mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
code cleanup, removed jon arbuckle mode, battery priority buttons
This commit is contained in:
parent
752a863559
commit
7454e65d10
@ -321,7 +321,7 @@ public class FluidTank {
|
||||
list.add(fluid + "/" + maxFluid + "mB");
|
||||
|
||||
type.addInfo(list);
|
||||
gui.drawFluidInfo(list.toArray(new String[0]), mouseX, mouseY);
|
||||
gui.drawInfo(list.toArray(new String[0]), mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,9 @@ import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.inventory.container.ContainerMachineBattery;
|
||||
@ -15,6 +18,7 @@ import com.hbm.packet.AuxButtonPacket;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.tileentity.machine.storage.TileEntityMachineBattery;
|
||||
import com.hbm.util.BobMathUtil;
|
||||
import com.hbm.util.I18nUtil;
|
||||
|
||||
public class GUIMachineBattery extends GuiInfoContainer {
|
||||
|
||||
@ -38,63 +42,44 @@ public class GUIMachineBattery extends GuiInfoContainer {
|
||||
long delta = battery.log[19] - battery.log[0];
|
||||
String deltaText = BobMathUtil.getShortNumber(Math.abs(delta)) + "HE/s";
|
||||
|
||||
if(delta > 0)
|
||||
deltaText = EnumChatFormatting.GREEN + "+" + deltaText;
|
||||
else if(delta < 0)
|
||||
deltaText = EnumChatFormatting.RED + "-" + deltaText;
|
||||
else
|
||||
deltaText = EnumChatFormatting.YELLOW + "+" + deltaText;
|
||||
if(delta > 0) deltaText = EnumChatFormatting.GREEN + "+" + deltaText;
|
||||
else if(delta < 0) deltaText = EnumChatFormatting.RED + "-" + deltaText;
|
||||
else deltaText = EnumChatFormatting.YELLOW + "+" + deltaText;
|
||||
|
||||
String[] info = { BobMathUtil.getShortNumber(battery.power) + "/" + BobMathUtil.getShortNumber(battery.getMaxPower()) + "HE", deltaText };
|
||||
|
||||
this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 62, guiTop + 69 - 52, 52, 52, mouseX, mouseY, info);
|
||||
|
||||
String[] text = new String[] { "Click the buttons on the right", "to change battery behavior for", "when redstone is or isn't applied." };
|
||||
this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 16, guiTop + 36, 16, 16, guiLeft - 8, guiTop + 36 + 16, text);
|
||||
|
||||
if(battery.childLock) {
|
||||
String[] childLock = new String[] {
|
||||
EnumChatFormatting.RED + "Child Safety Lock for Buffer Mode",
|
||||
EnumChatFormatting.ITALIC + "What is Buffer Mode?",
|
||||
"Buffer Mode simply combines the input and output modes",
|
||||
"of the battery. " + EnumChatFormatting.RED + "NO, DON'T STOP READING YET.",
|
||||
"It absolutely does no more than that. It's not an omniscient",
|
||||
"load-balancer that somehow knows where you want to direct most of",
|
||||
"your energy to. Batteries - obviously - still receive energy when in",
|
||||
"Buffer Mode, which means that combining multiple batteries in Buffer",
|
||||
"Mode will cause them to constantly send energy back and forth,",
|
||||
"with only a small share going out to whatever it is you want powered.",
|
||||
"This can be solved easily by either only using Buffer Mode when",
|
||||
"actually necessary or by switching to another mode if required.",
|
||||
"Diodes may also help curb the \"ping-ponging\" of energy.",
|
||||
"",
|
||||
EnumChatFormatting.ITALIC + "What is Buffer Mode not?",
|
||||
"Something to use for every single battery because \"I want to have",
|
||||
"batteries send and receive anyway\". Rule of thumb: Use your brain,",
|
||||
"use diodes, actually think about how load distribution should work in",
|
||||
"your power grid."
|
||||
};
|
||||
this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 152, guiTop + 35, 16, 16, guiLeft - 80, guiTop, childLock);
|
||||
String lang = null;
|
||||
switch(battery.priority) {
|
||||
case LOW: lang = "low"; break;
|
||||
case NORMAL: lang = "normal"; break;
|
||||
case HIGH: lang = "high"; break;
|
||||
}
|
||||
|
||||
List<String> priority = new ArrayList();
|
||||
priority.add(I18nUtil.resolveKey("battery.priority." + lang));
|
||||
priority.add(I18nUtil.resolveKey("battery.priority.recommended"));
|
||||
String[] desc = I18nUtil.resolveKeyArray("battery.priority." + lang + ".desc");
|
||||
for(String s : desc) priority.add(s);
|
||||
|
||||
this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 152, guiTop + 35, 16, 16, guiLeft - 80, guiTop, priority);
|
||||
}
|
||||
|
||||
protected void mouseClicked(int x, int y, int i) {
|
||||
super.mouseClicked(x, y, i);
|
||||
|
||||
if(guiLeft + 133 <= x && guiLeft + 133 + 18 > x && guiTop + 16 < y && guiTop + 16 + 18 >= y) {
|
||||
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
PacketDispatcher.wrapper.sendToServer(new AuxButtonPacket(battery.xCoord, battery.yCoord, battery.zCoord, 0, 0));
|
||||
}
|
||||
|
||||
if(guiLeft + 133 <= x && guiLeft + 133 + 18 > x && guiTop + 52 < y && guiTop + 52 + 18 >= y) {
|
||||
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
PacketDispatcher.wrapper.sendToServer(new AuxButtonPacket(battery.xCoord, battery.yCoord, battery.zCoord, 0, 1));
|
||||
}
|
||||
|
||||
if(guiLeft + 152 <= x && guiLeft + 152 + 16 > x && guiTop + 35 < y && guiTop + 35 + 16 >= y) {
|
||||
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
PacketDispatcher.wrapper.sendToServer(new AuxButtonPacket(battery.xCoord, battery.yCoord, battery.zCoord, 0, 2));
|
||||
}
|
||||
@ -126,9 +111,6 @@ public class GUIMachineBattery extends GuiInfoContainer {
|
||||
int j = battery.redHigh;
|
||||
drawTexturedModalRect(guiLeft + 133, guiTop + 52, 176, 52 + j * 18, 18, 18);
|
||||
|
||||
if(!battery.childLock)
|
||||
drawTexturedModalRect(guiLeft + 152, guiTop + 35, 176, 124, 16, 16);
|
||||
|
||||
this.drawInfoPanel(guiLeft - 16, guiTop + 36, 16, 16, 2);
|
||||
drawTexturedModalRect(guiLeft + 152, guiTop + 35, 194, 52 + battery.priority.ordinal() * 16, 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,18 +1,12 @@
|
||||
package com.hbm.inventory.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.inventory.container.ContainerReactorControl;
|
||||
import com.hbm.inventory.gui.GuiInfoContainer.NumberDisplay;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.module.NumberDisplay;
|
||||
import com.hbm.packet.NBTControlPacket;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.tileentity.machine.TileEntityReactorControl;
|
||||
@ -38,9 +32,9 @@ public class GUIReactorControl extends GuiInfoContainer {
|
||||
public GUIReactorControl(InventoryPlayer invPlayer, TileEntityReactorControl tedf) {
|
||||
super(new ContainerReactorControl(invPlayer, tedf));
|
||||
control = tedf;
|
||||
displays[0] = new NumberDisplay(6, 20, 0x08FF00).setDigitLength(3);
|
||||
displays[1] = new NumberDisplay(66, 20, 0x08FF00).setDigitLength(4);
|
||||
displays[2] = new NumberDisplay(126, 20, 0x08FF00).setDigitLength(3);
|
||||
displays[0] = new NumberDisplay(this, 6, 20, 0x08FF00).setDigitLength(3);
|
||||
displays[1] = new NumberDisplay(this, 66, 20, 0x08FF00).setDigitLength(4);
|
||||
displays[2] = new NumberDisplay(this, 126, 20, 0x08FF00).setDigitLength(3);
|
||||
|
||||
fields = new GuiTextField[4];
|
||||
|
||||
|
||||
@ -4,9 +4,9 @@ import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.inventory.FluidTank;
|
||||
import com.hbm.inventory.container.ContainerReactorResearch;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.module.NumberDisplay;
|
||||
import com.hbm.packet.NBTControlPacket;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.tileentity.machine.TileEntityReactorResearch;
|
||||
@ -16,7 +16,6 @@ import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
@ -34,9 +33,9 @@ public class GUIReactorResearch extends GuiInfoContainer {
|
||||
reactor = te;
|
||||
this.xSize = 176;
|
||||
this.ySize = 222;
|
||||
displays[0] = new NumberDisplay(14, 25, 0x08FF00).setDigitLength(4);
|
||||
displays[1] = new NumberDisplay(12, 63, 0x08FF00).setDigitLength(3);
|
||||
displays[2] = new NumberDisplay(5, 101, 0x08FF00).setDigitLength(3);
|
||||
displays[0] = new NumberDisplay(this, 14, 25, 0x08FF00).setDigitLength(4);
|
||||
displays[1] = new NumberDisplay(this, 12, 63, 0x08FF00).setDigitLength(3);
|
||||
displays[2] = new NumberDisplay(this, 5, 101, 0x08FF00).setDigitLength(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,24 +1,21 @@
|
||||
package com.hbm.inventory.gui;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.util.BobMathUtil;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public abstract class GuiInfoContainer extends GuiContainer {
|
||||
@ -29,67 +26,46 @@ public abstract class GuiInfoContainer extends GuiContainer {
|
||||
super(p_i1072_1_);
|
||||
}
|
||||
|
||||
public void drawFluidInfo(String[] text, int x, int y) {
|
||||
public void drawElectricityInfo(GuiInfoContainer gui, int mouseX, int mouseY, int x, int y, int width, int height, long power, long maxPower) {
|
||||
if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY)
|
||||
gui.drawInfo(new String[] { BobMathUtil.getShortNumber(power) + "/" + BobMathUtil.getShortNumber(maxPower) + "HE" }, mouseX, mouseY);
|
||||
}
|
||||
|
||||
public void drawCustomInfoStat(int mouseX, int mouseY, int x, int y, int width, int height, int tPosX, int tPosY, String[] text) { drawCustomInfoStat(mouseX, mouseY, x, y, width, height, tPosX, tPosY, Arrays.asList(text)); }
|
||||
|
||||
public void drawCustomInfoStat(int mouseX, int mouseY, int x, int y, int width, int height, int tPosX, int tPosY, List text) {
|
||||
|
||||
if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY)
|
||||
this.func_146283_a(text, tPosX, tPosY);
|
||||
}
|
||||
|
||||
public void drawInfo(String[] text, int x, int y) {
|
||||
this.func_146283_a(Arrays.asList(text), x, y);
|
||||
}
|
||||
|
||||
public void drawElectricityInfo(GuiInfoContainer gui, int mouseX, int mouseY, int x, int y, int width, int height, long power, long maxPower) {
|
||||
if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY)
|
||||
gui.drawFluidInfo(new String[] { BobMathUtil.getShortNumber(power) + "/" + BobMathUtil.getShortNumber(maxPower) + "HE" }, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void drawCustomInfo(GuiInfoContainer gui, int mouseX, int mouseY, int x, int y, int width, int height, String[] text) {
|
||||
if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY)
|
||||
this.func_146283_a(Arrays.asList(text), mouseX, mouseY);
|
||||
}
|
||||
|
||||
public void drawCustomInfoStat(int mouseX, int mouseY, int x, int y, int width, int height, int tPosX, int tPosY, String[] text) {
|
||||
|
||||
if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY)
|
||||
this.func_146283_a(Arrays.asList(text), tPosX, tPosY);
|
||||
}
|
||||
|
||||
public void drawInfoPanel(int x, int y, int width, int height, int type) {
|
||||
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(guiUtil);
|
||||
|
||||
switch(type) {
|
||||
case 0:
|
||||
//Small blue I
|
||||
drawTexturedModalRect(x, y, 0, 0, 8, 8); break;
|
||||
case 1:
|
||||
//Small green I
|
||||
drawTexturedModalRect(x, y, 0, 8, 8, 8); break;
|
||||
case 2:
|
||||
//Large blue I
|
||||
drawTexturedModalRect(x, y, 8, 0, 16, 16); break;
|
||||
case 3:
|
||||
//Large green I
|
||||
drawTexturedModalRect(x, y, 24, 0, 16, 16); break;
|
||||
case 4:
|
||||
//Small red !
|
||||
drawTexturedModalRect(x, y, 0, 16, 8, 8); break;
|
||||
case 5:
|
||||
//Small yellow !
|
||||
drawTexturedModalRect(x, y, 0, 24, 8, 8); break;
|
||||
case 6:
|
||||
//Large red !
|
||||
drawTexturedModalRect(x, y, 8, 16, 16, 16); break;
|
||||
case 7:
|
||||
//Large yellow !
|
||||
drawTexturedModalRect(x, y, 24, 16, 16, 16); break;
|
||||
case 8:
|
||||
//Small blue *
|
||||
drawTexturedModalRect(x, y, 0, 32, 8, 8); break;
|
||||
case 9:
|
||||
//Small grey *
|
||||
drawTexturedModalRect(x, y, 0, 40, 8, 8); break;
|
||||
case 10:
|
||||
//Large blue *
|
||||
drawTexturedModalRect(x, y, 8, 32, 16, 16); break;
|
||||
case 11:
|
||||
//Large grey *
|
||||
drawTexturedModalRect(x, y, 24, 32, 16, 16); break;
|
||||
case 0: drawTexturedModalRect(x, y, 0, 0, 8, 8); break; //Small blue I
|
||||
case 1: drawTexturedModalRect(x, y, 0, 8, 8, 8); break; //Small green I
|
||||
case 2: drawTexturedModalRect(x, y, 8, 0, 16, 16); break; //Large blue I
|
||||
case 3: drawTexturedModalRect(x, y, 24, 0, 16, 16); break; //Large green I
|
||||
case 4: drawTexturedModalRect(x, y, 0, 16, 8, 8); break; //Small red !
|
||||
case 5: drawTexturedModalRect(x, y, 0, 24, 8, 8); break; //Small yellow !
|
||||
case 6: drawTexturedModalRect(x, y, 8, 16, 16, 16); break; //Large red !
|
||||
case 7: drawTexturedModalRect(x, y, 24, 16, 16, 16); break; //Large yellow !
|
||||
case 8: drawTexturedModalRect(x, y, 0, 32, 8, 8); break; //Small blue *
|
||||
case 9: drawTexturedModalRect(x, y, 0, 40, 8, 8); break; //Small grey *
|
||||
case 10: drawTexturedModalRect(x, y, 8, 32, 16, 16); break; //Large blue *
|
||||
case 11: drawTexturedModalRect(x, y, 24, 32, 16, 16); break; //Large grey *
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,415 +73,90 @@ public abstract class GuiInfoContainer extends GuiContainer {
|
||||
return this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seven segment style displays for GUIs, tried to be as adaptable as possible. Still has some bugs that need to be ironed out but it works for the most part.
|
||||
* @author UFFR
|
||||
*
|
||||
*/
|
||||
@Beta
|
||||
public class NumberDisplay
|
||||
{
|
||||
/** The display's X coordinate **/
|
||||
private int displayX;
|
||||
/** The display's Y coordinate **/
|
||||
private int displayY;
|
||||
/** The display's color, in hexadecimal **/
|
||||
private int color;
|
||||
/** The amount of padding between digits, default 3 **/
|
||||
@Nonnegative
|
||||
private byte padding = 3;
|
||||
/** Does it blink or not, default false, not yet used **/
|
||||
private boolean blink = false;
|
||||
/** Max number the display can handle **/
|
||||
private float maxNum;
|
||||
/** Min number the display can handle **/
|
||||
private float minNum;
|
||||
private boolean customBounds = false;
|
||||
// Should it be a decimal number?
|
||||
private boolean isFloat = false;
|
||||
// How many trailing zeros?
|
||||
private byte floatPad = 1;
|
||||
/** Does it pad out with zeros **/
|
||||
private boolean pads = false;
|
||||
/** Max number of digits the display has, default 3 **/
|
||||
@Nonnegative
|
||||
private byte digitLength = 3;
|
||||
private Number numIn = 0;
|
||||
private char[] toDisp = {'0', '0', '0'};
|
||||
@Nonnegative
|
||||
private short dispOffset = 0;
|
||||
/** Length and thickness of segments. **/
|
||||
private int verticalLength = 5;
|
||||
private int horizontalLength = 4;
|
||||
private int thickness = 1;
|
||||
/**
|
||||
* Construct a new number display
|
||||
* @param dX X coordinate of the display
|
||||
* @param dY Y coordinate of the display
|
||||
* @param c Enum Color to use, invalid enums will default to yellow
|
||||
*/
|
||||
public NumberDisplay(int x, int y, EnumChatFormatting c)
|
||||
{
|
||||
this(x, y);
|
||||
setColor(enumToColor(c));
|
||||
}
|
||||
/**
|
||||
* Construct a new number display
|
||||
* @param x X coordinate of the display
|
||||
* @param y Y coordinate of the display
|
||||
* @param color Color to use, valid hexadecimal value required
|
||||
*/
|
||||
public NumberDisplay(int x, int y, int color)
|
||||
{
|
||||
this(x, y);
|
||||
setColor(color);
|
||||
}
|
||||
/**
|
||||
* Construct a new number display, color is yellow
|
||||
* @param x X coordinate of the display
|
||||
* @param y Y coordinate of the display
|
||||
*/
|
||||
public NumberDisplay(int x, int y)
|
||||
{
|
||||
displayX = x;
|
||||
displayY = y;
|
||||
setColor(0xFFFF55);
|
||||
}
|
||||
/**
|
||||
* Returns a hexadecimal from EnumChatFormatting
|
||||
* @param c Color to use
|
||||
* @return
|
||||
*/
|
||||
private int enumToColor(EnumChatFormatting c) {
|
||||
if(c.isColor()) {
|
||||
switch(c) {
|
||||
case AQUA:
|
||||
return 0x55FFFF;
|
||||
case BLACK:
|
||||
return 0x000000;
|
||||
case BLUE:
|
||||
return 0x5555FF;
|
||||
case DARK_AQUA:
|
||||
return 0x00AAAA;
|
||||
case DARK_BLUE:
|
||||
return 0x0000AA;
|
||||
case DARK_GRAY:
|
||||
return 0x555555;
|
||||
case DARK_GREEN:
|
||||
return 0x00AA00;
|
||||
case DARK_PURPLE:
|
||||
return 0xAA00AA;
|
||||
case DARK_RED:
|
||||
return 0xAA0000;
|
||||
case GOLD:
|
||||
return 0xFFAA00;
|
||||
case GRAY:
|
||||
return 0xAAAAAA;
|
||||
case GREEN:
|
||||
return 0x55FF55;
|
||||
case LIGHT_PURPLE:
|
||||
return 0xFF55FF;
|
||||
case RED:
|
||||
return 0xFF5555;
|
||||
case WHITE:
|
||||
return 0xFFFFFF;
|
||||
case YELLOW:
|
||||
return 0xFFFF55;
|
||||
default:
|
||||
/* Getters for external use of the GUI's rect rendering, such as NumberDisplay */
|
||||
public int getGuiTop() {
|
||||
return this.guiTop;
|
||||
}
|
||||
|
||||
public int getGuiLeft() {
|
||||
return this.guiLeft;
|
||||
}
|
||||
|
||||
public float getZLevel() {
|
||||
return this.zLevel;
|
||||
}
|
||||
|
||||
//TODO: do the funny
|
||||
protected void drawHoveringText2(List lines, int x, int y, FontRenderer font) {
|
||||
|
||||
if(!lines.isEmpty()) {
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
int longestline = 0;
|
||||
Iterator iterator = lines.iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
String line = (String) iterator.next();
|
||||
int lineWidth = font.getStringWidth(line);
|
||||
|
||||
if(lineWidth > longestline) {
|
||||
longestline = lineWidth;
|
||||
}
|
||||
}
|
||||
|
||||
return 0xFFFF55;
|
||||
}
|
||||
/**
|
||||
* Sets color
|
||||
* @param color - The color in hexadecimal
|
||||
**/
|
||||
public void setColor(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
/**
|
||||
* Draw custom number
|
||||
* @param num - The char array that has the number
|
||||
*/
|
||||
public void drawNumber(char[] num)
|
||||
{
|
||||
if (blink && !BobMathUtil.getBlink())
|
||||
return;
|
||||
|
||||
short gap = (short) (digitLength - num.length);
|
||||
for (int i = 0; i < num.length; i++)
|
||||
{
|
||||
if (num[i] == '.')
|
||||
gap--;
|
||||
dispOffset = (short) ((padding + horizontalLength + 2 * thickness) * (i + gap));
|
||||
drawChar(num[i]);
|
||||
}
|
||||
if (pads)
|
||||
padOut(gap);
|
||||
}
|
||||
/** Draw the previously provided number **/
|
||||
public void drawNumber()
|
||||
{
|
||||
if (isFloat)
|
||||
formatForFloat();
|
||||
drawNumber(toDisp);
|
||||
}
|
||||
public void drawNumber(Number num)
|
||||
{
|
||||
setNumber(num);
|
||||
drawNumber();
|
||||
}
|
||||
private void padOut(short gap)
|
||||
{
|
||||
if (gap == 0)
|
||||
return;
|
||||
for (int i = 0; i < gap; i++)
|
||||
{
|
||||
dispOffset = (short) ((padding + horizontalLength + 2 * thickness) * i);
|
||||
drawChar('0');
|
||||
}
|
||||
}
|
||||
|
||||
/** Draw a single character (requires dispOffset to be set) **/
|
||||
public void drawChar(char num)
|
||||
{
|
||||
switch (num)
|
||||
{
|
||||
case '1':
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '2':
|
||||
drawHorizontal(0);
|
||||
drawVertical(1, 0);
|
||||
drawHorizontal(1);
|
||||
drawVertical(0, 1);
|
||||
drawHorizontal(2);
|
||||
break;
|
||||
case '3':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '4':
|
||||
drawVertical(0, 0);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
drawHorizontal(1);
|
||||
break;
|
||||
case '5':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '6':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(0, 1);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '7':
|
||||
drawHorizontal(0);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '8':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(0, 1);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '9':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '0':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(0, 1);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '-':
|
||||
drawHorizontal(1);
|
||||
break;
|
||||
case '.':
|
||||
drawPeriod();
|
||||
break;
|
||||
case 'E':
|
||||
default:
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(0, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void drawHorizontal(int pos)
|
||||
{
|
||||
byte offset = (byte) (pos * (verticalLength + thickness));
|
||||
renderSegment(guiLeft + displayX + dispOffset + thickness, guiTop + displayY + offset, horizontalLength, thickness);
|
||||
}
|
||||
|
||||
private void drawPeriod()
|
||||
{
|
||||
renderSegment(guiLeft + displayX + dispOffset + padding - (int) Math.ceil(padding / 2) + (horizontalLength + thickness),
|
||||
guiTop + displayY + 2 * (verticalLength + thickness), thickness, thickness);
|
||||
}
|
||||
|
||||
private void drawVertical(int posX, int posY)
|
||||
{
|
||||
byte offsetX = (byte) (posX * (horizontalLength + thickness));
|
||||
byte offsetY = (byte) (posY * (verticalLength + thickness));
|
||||
renderSegment(guiLeft + displayX + offsetX + dispOffset, guiTop + displayY + offsetY + thickness, thickness, verticalLength);
|
||||
}
|
||||
/**
|
||||
* drawTexturedModalRect() for cool kids
|
||||
* @param renX X coordinate to render the part
|
||||
* @param renY Y coordinate to render the part
|
||||
* @param width Relevant for horizontals
|
||||
* @param height Relevant for verticals
|
||||
*/
|
||||
private void renderSegment(int renX, int renY, int width, int height)
|
||||
{
|
||||
final Tessellator tess = Tessellator.instance;
|
||||
final float z = GuiInfoContainer.this.zLevel;
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
tess.startDrawingQuads();
|
||||
tess.setColorOpaque_I(color);
|
||||
tess.addVertex(renX, renY + height, z);
|
||||
tess.addVertex(renX + width, renY + height, z);
|
||||
tess.addVertex(renX + width, renY + 0, z);
|
||||
tess.addVertex(renX, renY, z);
|
||||
tess.draw();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
public void setNumber(Number num)
|
||||
{
|
||||
numIn = num;
|
||||
if (customBounds)
|
||||
numIn = MathHelper.clamp_double(num.doubleValue(), minNum, maxNum);
|
||||
if (isFloat)
|
||||
formatForFloat();
|
||||
else
|
||||
{
|
||||
toDisp = new Long(Math.round(numIn.doubleValue())).toString().toCharArray();
|
||||
toDisp = truncOrExpand();
|
||||
int minX = x + 12;
|
||||
int minY = y - 12;
|
||||
int height = 8;
|
||||
|
||||
if(lines.size() > 1) {
|
||||
height += 2 + (lines.size() - 1) * 10;
|
||||
}
|
||||
}
|
||||
/** Get the set number **/
|
||||
public Number getNumber()
|
||||
{
|
||||
return numIn;
|
||||
}
|
||||
/** Get the char array for display **/
|
||||
public char[] getDispNumber()
|
||||
{
|
||||
return toDisp.clone();
|
||||
}
|
||||
/** Make the display blink **/
|
||||
public NumberDisplay setBlinks(boolean doesBlink)
|
||||
{
|
||||
blink = doesBlink;
|
||||
return this;
|
||||
}
|
||||
/** Padding between digits, default 3 **/
|
||||
public NumberDisplay setPadding(@Nonnegative int p)
|
||||
{
|
||||
padding = (byte) p;
|
||||
return this;
|
||||
}
|
||||
/** Max number of digits **/
|
||||
public NumberDisplay setDigitLength(@Nonnegative int l)
|
||||
{
|
||||
digitLength = (byte) l;
|
||||
toDisp = truncOrExpand();
|
||||
return this;
|
||||
}
|
||||
/** Set sizes and thickness of horizontal and vertical segments. **/
|
||||
public NumberDisplay setSegmentSize(int vertical, int horizontal, int thickness)
|
||||
{
|
||||
this.verticalLength = vertical;
|
||||
this.horizontalLength = horizontal;
|
||||
this.thickness = thickness;
|
||||
return this;
|
||||
}
|
||||
/** Set custom number bounds **/
|
||||
public NumberDisplay setMaxMin(float max, float min)
|
||||
{
|
||||
if (min > max)
|
||||
throw new IllegalArgumentException("Minimum value is larger than maximum value!");
|
||||
maxNum = max;
|
||||
minNum = min;
|
||||
customBounds = true;
|
||||
return this;
|
||||
}
|
||||
/** Pad out the left side of the number with zeros **/
|
||||
public NumberDisplay setPadNumber()
|
||||
{
|
||||
pads = true;
|
||||
return this;
|
||||
}
|
||||
/** Set the number to be a decimal, default zero trailing is 1 **/
|
||||
public NumberDisplay setFloat()
|
||||
{
|
||||
return setFloat(1);
|
||||
}
|
||||
/** Set the number to be a decimal with specified zero trailing **/
|
||||
public NumberDisplay setFloat(@Nonnegative int pad)
|
||||
{
|
||||
floatPad = (byte) pad;
|
||||
isFloat = true;
|
||||
|
||||
formatForFloat();
|
||||
|
||||
return this;
|
||||
}
|
||||
private void formatForFloat()
|
||||
{
|
||||
BigDecimal bd = new BigDecimal(numIn.toString());
|
||||
bd = bd.setScale(floatPad, RoundingMode.HALF_UP);
|
||||
|
||||
// char[] proc = new Double(bd.doubleValue()).toString().toCharArray();
|
||||
char[] proc = bd.toString().toCharArray();
|
||||
proc = Double.valueOf(BobMathUtil.roundDecimal(numIn.doubleValue(), floatPad)).toString().toCharArray();
|
||||
|
||||
if (proc.length == digitLength)
|
||||
toDisp = proc;
|
||||
else
|
||||
toDisp = truncOrExpand();
|
||||
}
|
||||
@Beta
|
||||
private char[] truncOrExpand()
|
||||
{
|
||||
if (isFloat)
|
||||
{
|
||||
char[] out = Arrays.copyOf(toDisp, digitLength);
|
||||
for (int i = 0; i < digitLength; i++)
|
||||
if (out[i] == '\u0000')
|
||||
out[i] = '0';
|
||||
return out.clone();
|
||||
|
||||
if(minX + longestline > this.width) {
|
||||
minX -= 28 + longestline;
|
||||
}
|
||||
return toDisp;
|
||||
|
||||
if(minY + height + 6 > this.height) {
|
||||
minY = this.height - height - 6;
|
||||
}
|
||||
|
||||
this.zLevel = 300.0F;
|
||||
itemRender.zLevel = 300.0F;
|
||||
//int j1 = -267386864;
|
||||
int colorBg = 0xF0100010;
|
||||
this.drawGradientRect(minX - 3, minY - 4, minX + longestline + 3, minY - 3, colorBg, colorBg);
|
||||
this.drawGradientRect(minX - 3, minY + height + 3, minX + longestline + 3, minY + height + 4, colorBg, colorBg);
|
||||
this.drawGradientRect(minX - 3, minY - 3, minX + longestline + 3, minY + height + 3, colorBg, colorBg);
|
||||
this.drawGradientRect(minX - 4, minY - 3, minX - 3, minY + height + 3, colorBg, colorBg);
|
||||
this.drawGradientRect(minX + longestline + 3, minY - 3, minX + longestline + 4, minY + height + 3, colorBg, colorBg);
|
||||
//int k1 = 1347420415;
|
||||
int color0 = 0x505000FF;
|
||||
//int l1 = (k1 & 16711422) >> 1 | k1 & -16777216;
|
||||
int color1 = (color0 & 0xFEFEFE) >> 1 | color0 & 0xFF000000;
|
||||
this.drawGradientRect(minX - 3, minY - 3 + 1, minX - 3 + 1, minY + height + 3 - 1, color0, color1);
|
||||
this.drawGradientRect(minX + longestline + 2, minY - 3 + 1, minX + longestline + 3, minY + height + 3 - 1, color0, color1);
|
||||
this.drawGradientRect(minX - 3, minY - 3, minX + longestline + 3, minY - 3 + 1, color0, color0);
|
||||
this.drawGradientRect(minX - 3, minY + height + 2, minX + longestline + 3, minY + height + 3, color1, color1);
|
||||
|
||||
for(int index = 0; index < lines.size(); ++index) {
|
||||
String line = (String) lines.get(index);
|
||||
font.drawStringWithShadow(line, minX, minY, -1);
|
||||
|
||||
if(index == 0) {
|
||||
minY += 2;
|
||||
}
|
||||
|
||||
minY += 10;
|
||||
}
|
||||
|
||||
this.zLevel = 0.0F;
|
||||
itemRender.zLevel = 0.0F;
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,26 +17,20 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.play.client.C07PacketPlayerDigging;
|
||||
import net.minecraft.network.play.server.S23PacketBlockChange;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
|
||||
public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRockTool {
|
||||
|
||||
@ -84,7 +78,14 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
|
||||
this.damage = damage;
|
||||
this.movement = movement;
|
||||
this.toolType = type;
|
||||
this.setHarvestLevel(type.toString().toLowerCase(), material.getHarvestLevel());
|
||||
|
||||
// hacky workaround, might be good to rethink this entire system
|
||||
if(type == EnumToolType.MINER) {
|
||||
this.setHarvestLevel("pickaxe", material.getHarvestLevel());
|
||||
this.setHarvestLevel("shovel", material.getHarvestLevel());
|
||||
} else {
|
||||
this.setHarvestLevel(type.toString().toLowerCase(), material.getHarvestLevel());
|
||||
}
|
||||
}
|
||||
|
||||
public ItemToolAbility addBreakAbility(ToolAbility breakAbility) {
|
||||
|
||||
437
src/main/java/com/hbm/module/NumberDisplay.java
Normal file
437
src/main/java/com/hbm/module/NumberDisplay.java
Normal file
@ -0,0 +1,437 @@
|
||||
package com.hbm.module;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.hbm.inventory.gui.GuiInfoContainer;
|
||||
import com.hbm.util.BobMathUtil;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Seven segment style displays for GUIs, tried to be as adaptable as possible. Still has some bugs that need to be ironed out but it works for the most part.
|
||||
* @author UFFR
|
||||
*
|
||||
*/
|
||||
public class NumberDisplay {
|
||||
|
||||
/*
|
||||
* Moved the entire class into its own file to keep GuiInfoContainer tidy.
|
||||
* This new class needs a reference to the GUI because of this so it can render things using the GUI's utils.
|
||||
*/
|
||||
protected GuiInfoContainer gui;
|
||||
|
||||
/** The display's X coordinate **/
|
||||
private int displayX;
|
||||
/** The display's Y coordinate **/
|
||||
private int displayY;
|
||||
/** The display's color, in hexadecimal **/
|
||||
private int color;
|
||||
/** The amount of padding between digits, default 3 **/
|
||||
@Nonnegative
|
||||
private byte padding = 3;
|
||||
/** Does it blink or not, default false, not yet used **/
|
||||
private boolean blink = false;
|
||||
/** Max number the display can handle **/
|
||||
private float maxNum;
|
||||
/** Min number the display can handle **/
|
||||
private float minNum;
|
||||
private boolean customBounds = false;
|
||||
// Should it be a decimal number?
|
||||
private boolean isFloat = false;
|
||||
// How many trailing zeros?
|
||||
private byte floatPad = 1;
|
||||
/** Does it pad out with zeros **/
|
||||
private boolean pads = false;
|
||||
/** Max number of digits the display has, default 3 **/
|
||||
@Nonnegative
|
||||
private byte digitLength = 3;
|
||||
private Number numIn = 0;
|
||||
private char[] toDisp = {'0', '0', '0'};
|
||||
@Nonnegative
|
||||
private short dispOffset = 0;
|
||||
/** Length and thickness of segments. **/
|
||||
private int verticalLength = 5;
|
||||
private int horizontalLength = 4;
|
||||
private int thickness = 1;
|
||||
/**
|
||||
* Construct a new number display
|
||||
* @param dX X coordinate of the display
|
||||
* @param dY Y coordinate of the display
|
||||
* @param c Enum Color to use, invalid enums will default to yellow
|
||||
*/
|
||||
public NumberDisplay(GuiInfoContainer gui, int x, int y, EnumChatFormatting c)
|
||||
{
|
||||
this(gui, x, y);
|
||||
setColor(enumToColor(c));
|
||||
}
|
||||
/**
|
||||
* Construct a new number display
|
||||
* @param x X coordinate of the display
|
||||
* @param y Y coordinate of the display
|
||||
* @param color Color to use, valid hexadecimal value required
|
||||
*/
|
||||
public NumberDisplay(GuiInfoContainer gui, int x, int y, int color)
|
||||
{
|
||||
this(gui, x, y);
|
||||
setColor(color);
|
||||
}
|
||||
/**
|
||||
* Construct a new number display, color is yellow
|
||||
* @param x X coordinate of the display
|
||||
* @param y Y coordinate of the display
|
||||
*/
|
||||
public NumberDisplay(GuiInfoContainer gui, int x, int y)
|
||||
{
|
||||
displayX = x;
|
||||
displayY = y;
|
||||
setColor(0xFFFF55);
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hexadecimal from EnumChatFormatting
|
||||
* @param c Color to use
|
||||
* @return
|
||||
*/
|
||||
private int enumToColor(EnumChatFormatting c) {
|
||||
if(c.isColor()) {
|
||||
switch(c) {
|
||||
case AQUA:
|
||||
return 0x55FFFF;
|
||||
case BLACK:
|
||||
return 0x000000;
|
||||
case BLUE:
|
||||
return 0x5555FF;
|
||||
case DARK_AQUA:
|
||||
return 0x00AAAA;
|
||||
case DARK_BLUE:
|
||||
return 0x0000AA;
|
||||
case DARK_GRAY:
|
||||
return 0x555555;
|
||||
case DARK_GREEN:
|
||||
return 0x00AA00;
|
||||
case DARK_PURPLE:
|
||||
return 0xAA00AA;
|
||||
case DARK_RED:
|
||||
return 0xAA0000;
|
||||
case GOLD:
|
||||
return 0xFFAA00;
|
||||
case GRAY:
|
||||
return 0xAAAAAA;
|
||||
case GREEN:
|
||||
return 0x55FF55;
|
||||
case LIGHT_PURPLE:
|
||||
return 0xFF55FF;
|
||||
case RED:
|
||||
return 0xFF5555;
|
||||
case WHITE:
|
||||
return 0xFFFFFF;
|
||||
case YELLOW:
|
||||
return 0xFFFF55;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
return 0xFFFF55;
|
||||
}
|
||||
/**
|
||||
* Sets color
|
||||
* @param color - The color in hexadecimal
|
||||
**/
|
||||
public void setColor(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
/**
|
||||
* Draw custom number
|
||||
* @param num - The char array that has the number
|
||||
*/
|
||||
public void drawNumber(char[] num)
|
||||
{
|
||||
if (blink && !BobMathUtil.getBlink())
|
||||
return;
|
||||
|
||||
short gap = (short) (digitLength - num.length);
|
||||
for (int i = 0; i < num.length; i++)
|
||||
{
|
||||
if (num[i] == '.')
|
||||
gap--;
|
||||
dispOffset = (short) ((padding + horizontalLength + 2 * thickness) * (i + gap));
|
||||
drawChar(num[i]);
|
||||
}
|
||||
if (pads)
|
||||
padOut(gap);
|
||||
}
|
||||
/** Draw the previously provided number **/
|
||||
public void drawNumber()
|
||||
{
|
||||
if (isFloat)
|
||||
formatForFloat();
|
||||
drawNumber(toDisp);
|
||||
}
|
||||
public void drawNumber(Number num)
|
||||
{
|
||||
setNumber(num);
|
||||
drawNumber();
|
||||
}
|
||||
private void padOut(short gap)
|
||||
{
|
||||
if (gap == 0)
|
||||
return;
|
||||
for (int i = 0; i < gap; i++)
|
||||
{
|
||||
dispOffset = (short) ((padding + horizontalLength + 2 * thickness) * i);
|
||||
drawChar('0');
|
||||
}
|
||||
}
|
||||
|
||||
/** Draw a single character (requires dispOffset to be set) **/
|
||||
public void drawChar(char num)
|
||||
{
|
||||
switch (num)
|
||||
{
|
||||
case '1':
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '2':
|
||||
drawHorizontal(0);
|
||||
drawVertical(1, 0);
|
||||
drawHorizontal(1);
|
||||
drawVertical(0, 1);
|
||||
drawHorizontal(2);
|
||||
break;
|
||||
case '3':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '4':
|
||||
drawVertical(0, 0);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
drawHorizontal(1);
|
||||
break;
|
||||
case '5':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '6':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(0, 1);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '7':
|
||||
drawHorizontal(0);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '8':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(0, 1);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '9':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '0':
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(0, 1);
|
||||
drawVertical(1, 0);
|
||||
drawVertical(1, 1);
|
||||
break;
|
||||
case '-':
|
||||
drawHorizontal(1);
|
||||
break;
|
||||
case '.':
|
||||
drawPeriod();
|
||||
break;
|
||||
case 'E':
|
||||
default:
|
||||
drawHorizontal(0);
|
||||
drawHorizontal(1);
|
||||
drawHorizontal(2);
|
||||
drawVertical(0, 0);
|
||||
drawVertical(0, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void drawHorizontal(int pos)
|
||||
{
|
||||
byte offset = (byte) (pos * (verticalLength + thickness));
|
||||
renderSegment(gui.getGuiLeft() + displayX + dispOffset + thickness, gui.getGuiTop() + displayY + offset, horizontalLength, thickness);
|
||||
}
|
||||
|
||||
private void drawPeriod()
|
||||
{
|
||||
renderSegment(gui.getGuiLeft() + displayX + dispOffset + padding - (int) Math.ceil(padding / 2) + (horizontalLength + thickness),
|
||||
gui.getGuiLeft() + displayY + 2 * (verticalLength + thickness), thickness, thickness);
|
||||
}
|
||||
|
||||
private void drawVertical(int posX, int posY)
|
||||
{
|
||||
byte offsetX = (byte) (posX * (horizontalLength + thickness));
|
||||
byte offsetY = (byte) (posY * (verticalLength + thickness));
|
||||
renderSegment(gui.getGuiLeft() + displayX + offsetX + dispOffset, gui.getGuiTop() + displayY + offsetY + thickness, thickness, verticalLength);
|
||||
}
|
||||
/**
|
||||
* drawTexturedModalRect() for cool kids
|
||||
* @param renX X coordinate to render the part
|
||||
* @param renY Y coordinate to render the part
|
||||
* @param width Relevant for horizontals
|
||||
* @param height Relevant for verticals
|
||||
*/
|
||||
private void renderSegment(int renX, int renY, int width, int height)
|
||||
{
|
||||
final Tessellator tess = Tessellator.instance;
|
||||
final float z = gui.getZLevel();
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
tess.startDrawingQuads();
|
||||
tess.setColorOpaque_I(color);
|
||||
tess.addVertex(renX, renY + height, z);
|
||||
tess.addVertex(renX + width, renY + height, z);
|
||||
tess.addVertex(renX + width, renY + 0, z);
|
||||
tess.addVertex(renX, renY, z);
|
||||
tess.draw();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
public void setNumber(Number num)
|
||||
{
|
||||
numIn = num;
|
||||
if (customBounds)
|
||||
numIn = MathHelper.clamp_double(num.doubleValue(), minNum, maxNum);
|
||||
if (isFloat)
|
||||
formatForFloat();
|
||||
else
|
||||
{
|
||||
toDisp = new Long(Math.round(numIn.doubleValue())).toString().toCharArray();
|
||||
toDisp = truncOrExpand();
|
||||
}
|
||||
}
|
||||
/** Get the set number **/
|
||||
public Number getNumber()
|
||||
{
|
||||
return numIn;
|
||||
}
|
||||
/** Get the char array for display **/
|
||||
public char[] getDispNumber()
|
||||
{
|
||||
return toDisp.clone();
|
||||
}
|
||||
/** Make the display blink **/
|
||||
public NumberDisplay setBlinks(boolean doesBlink)
|
||||
{
|
||||
blink = doesBlink;
|
||||
return this;
|
||||
}
|
||||
/** Padding between digits, default 3 **/
|
||||
public NumberDisplay setPadding(@Nonnegative int p)
|
||||
{
|
||||
padding = (byte) p;
|
||||
return this;
|
||||
}
|
||||
/** Max number of digits **/
|
||||
public NumberDisplay setDigitLength(@Nonnegative int l)
|
||||
{
|
||||
digitLength = (byte) l;
|
||||
toDisp = truncOrExpand();
|
||||
return this;
|
||||
}
|
||||
/** Set sizes and thickness of horizontal and vertical segments. **/
|
||||
public NumberDisplay setSegmentSize(int vertical, int horizontal, int thickness)
|
||||
{
|
||||
this.verticalLength = vertical;
|
||||
this.horizontalLength = horizontal;
|
||||
this.thickness = thickness;
|
||||
return this;
|
||||
}
|
||||
/** Set custom number bounds **/
|
||||
public NumberDisplay setMaxMin(float max, float min)
|
||||
{
|
||||
if (min > max)
|
||||
throw new IllegalArgumentException("Minimum value is larger than maximum value!");
|
||||
maxNum = max;
|
||||
minNum = min;
|
||||
customBounds = true;
|
||||
return this;
|
||||
}
|
||||
/** Pad out the left side of the number with zeros **/
|
||||
public NumberDisplay setPadNumber()
|
||||
{
|
||||
pads = true;
|
||||
return this;
|
||||
}
|
||||
/** Set the number to be a decimal, default zero trailing is 1 **/
|
||||
public NumberDisplay setFloat()
|
||||
{
|
||||
return setFloat(1);
|
||||
}
|
||||
/** Set the number to be a decimal with specified zero trailing **/
|
||||
public NumberDisplay setFloat(@Nonnegative int pad)
|
||||
{
|
||||
floatPad = (byte) pad;
|
||||
isFloat = true;
|
||||
|
||||
formatForFloat();
|
||||
|
||||
return this;
|
||||
}
|
||||
private void formatForFloat()
|
||||
{
|
||||
BigDecimal bd = new BigDecimal(numIn.toString());
|
||||
bd = bd.setScale(floatPad, RoundingMode.HALF_UP);
|
||||
|
||||
// char[] proc = new Double(bd.doubleValue()).toString().toCharArray();
|
||||
char[] proc = bd.toString().toCharArray();
|
||||
proc = Double.valueOf(BobMathUtil.roundDecimal(numIn.doubleValue(), floatPad)).toString().toCharArray();
|
||||
|
||||
if (proc.length == digitLength)
|
||||
toDisp = proc;
|
||||
else
|
||||
toDisp = truncOrExpand();
|
||||
}
|
||||
@Beta
|
||||
private char[] truncOrExpand()
|
||||
{
|
||||
if (isFloat)
|
||||
{
|
||||
char[] out = Arrays.copyOf(toDisp, digitLength);
|
||||
for (int i = 0; i < digitLength; i++)
|
||||
if (out[i] == '\u0000')
|
||||
out[i] = '0';
|
||||
return out.clone();
|
||||
}
|
||||
return toDisp;
|
||||
}
|
||||
}
|
||||
@ -20,6 +20,7 @@ import com.hbm.tileentity.machine.TileEntitySoyuzLauncher;
|
||||
import com.hbm.tileentity.machine.storage.TileEntityBarrel;
|
||||
import com.hbm.tileentity.machine.storage.TileEntityMachineBattery;
|
||||
|
||||
import api.hbm.energy.IEnergyConnector.ConnectionPriority;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@ -165,20 +166,20 @@ public class AuxButtonPacket implements IMessage {
|
||||
|
||||
if(m.id == 0) {
|
||||
bat.redLow = (short) ((bat.redLow + 1) % 4);
|
||||
if(bat.redLow == 1 && bat.childLock)
|
||||
bat.redLow++;
|
||||
bat.markDirty();
|
||||
}
|
||||
|
||||
if(m.id == 1) {
|
||||
bat.redHigh = (short) ((bat.redHigh + 1) % 4);
|
||||
if(bat.redHigh == 1 && bat.childLock)
|
||||
bat.redHigh++;
|
||||
bat.markDirty();
|
||||
}
|
||||
|
||||
if(m.id == 2) {
|
||||
bat.childLock = !bat.childLock;
|
||||
switch(bat.priority) {
|
||||
case LOW: bat.priority = ConnectionPriority.NORMAL; break;
|
||||
case NORMAL: bat.priority = ConnectionPriority.HIGH; break;
|
||||
case HIGH: bat.priority = ConnectionPriority.LOW; break;
|
||||
}
|
||||
bat.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
||||
public static final int mode_none = 3;
|
||||
public short redLow = 0;
|
||||
public short redHigh = 2;
|
||||
public boolean childLock = true;
|
||||
public ConnectionPriority priority = ConnectionPriority.LOW;
|
||||
|
||||
//public boolean conducts = false;
|
||||
public byte lastRedstone = 0;
|
||||
@ -92,8 +92,8 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
||||
this.power = nbt.getLong("power");
|
||||
this.redLow = nbt.getShort("redLow");
|
||||
this.redHigh = nbt.getShort("redHigh");
|
||||
this.childLock = nbt.getBoolean("childLock");
|
||||
this.lastRedstone = nbt.getByte("lastRedstone");
|
||||
this.priority = ConnectionPriority.values()[nbt.getByte("priority")];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -103,8 +103,8 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
||||
nbt.setLong("power", power);
|
||||
nbt.setShort("redLow", redLow);
|
||||
nbt.setShort("redHigh", redHigh);
|
||||
nbt.setBoolean("childLock", childLock);
|
||||
nbt.setByte("lastRedstone", lastRedstone);
|
||||
nbt.setByte("priority", (byte)this.priority.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -165,7 +165,7 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
||||
nbt.setLong("power", (power + prevPower) / 2);
|
||||
nbt.setShort("redLow", redLow);
|
||||
nbt.setShort("redHigh", redHigh);
|
||||
nbt.setBoolean("childLock", childLock);
|
||||
nbt.setByte("priority", (byte) this.priority.ordinal());
|
||||
this.networkPack(nbt, 20);
|
||||
}
|
||||
|
||||
@ -228,7 +228,7 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
||||
this.power = nbt.getLong("power");
|
||||
this.redLow = nbt.getShort("redLow");
|
||||
this.redHigh = nbt.getShort("redHigh");
|
||||
this.childLock = nbt.getBoolean("childLock");
|
||||
this.priority = ConnectionPriority.values()[nbt.getByte("priority")];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -306,7 +306,7 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
||||
|
||||
@Override
|
||||
public ConnectionPriority getPriority() {
|
||||
return ConnectionPriority.LOW;
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
// do some opencomputer stuff
|
||||
|
||||
@ -32,7 +32,6 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
|
||||
nbt.setLong("power", power);
|
||||
nbt.setShort("redLow", redLow);
|
||||
nbt.setShort("redHigh", redHigh);
|
||||
nbt.setBoolean("childLock", childLock);
|
||||
this.networkPack(nbt, 250);
|
||||
} else {
|
||||
this.prevRotation = this.rotation;
|
||||
|
||||
@ -164,6 +164,20 @@ armorMod.type.leggings=Leggings
|
||||
armorMod.type.servo=Servos
|
||||
armorMod.type.special=Special
|
||||
|
||||
battery.mode.buffer=Input/Output Mode
|
||||
battery.mode.input=Input Mode
|
||||
battery.mode.off=OffW
|
||||
battery.mode.output=Output Mode
|
||||
battery.priority.high=Charge Priority: High
|
||||
battery.priority.high.desc=Emergency buffers that$always need to be full
|
||||
battery.priority.low=Charge Priority: Low
|
||||
battery.priority.low.desc=Most use-cases where surplus$energy needs to be stored without$affecting machine performance
|
||||
battery.priority.normal=Charge Priority: Normal
|
||||
battery.priority.normal.desc=Smaller power grids where$priority doesn't matter
|
||||
battery.priority.recommended=Recommended for:
|
||||
battery.redstone.off=Redstone OFF
|
||||
battery.redstone.on=Redstone ON
|
||||
|
||||
bomb.detonated=Detonated successfully!
|
||||
bomb.incompatible=Device can not be triggered!
|
||||
bomb.launched=Launched successfully!
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 3.3 KiB |
Loading…
x
Reference in New Issue
Block a user