diff --git a/dependencies.gradle b/dependencies.gradle index ee99ad4..67ff99c 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,7 +1,7 @@ // Add your dependencies here dependencies { - compile("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-87-GTNH:dev") + compile("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-91-GTNH:dev") compile("com.github.GTNewHorizons:Baubles:1.0.1.14:dev") compile("curse.maven:cofh-core-69162:2388751") compile("com.github.GTNewHorizons:NotEnoughItems:2.2.12-GTNH:dev") diff --git a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java index 91951a8..ef5064c 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java @@ -4,11 +4,13 @@ import appeng.api.AEApi; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IParts; import appeng.api.storage.ITerminalHost; -import appeng.client.gui.widgets.GuiNumberBox; import appeng.core.AEConfig; import appeng.core.localization.GuiText; import appeng.helpers.Reflected; +import appeng.util.calculators.ArithHelper; +import appeng.util.calculators.Calculator; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiTextField; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiTabButton; @@ -22,7 +24,7 @@ import net.p455w0rd.wirelesscraftingterminal.items.ItemWirelessCraftingTerminal; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; public class GuiCraftAmount extends WCTBaseGui { - private GuiNumberBox amountToCraft; + private GuiTextField amountToCraft; private GuiTabButton originalGuiBtn; private GuiButton next; @@ -84,19 +86,15 @@ public class GuiCraftAmount extends WCTBaseGui { this.guiLeft + 154, this.guiTop - 4, myIcon, myIcon.getDisplayName(), itemRender)); } - this.amountToCraft = new GuiNumberBox( - this.fontRendererObj, - this.guiLeft + 62, - this.guiTop + 57, - 59, - this.fontRendererObj.FONT_HEIGHT, - Integer.class); + this.amountToCraft = new GuiTextField( + this.fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, this.fontRendererObj.FONT_HEIGHT); this.amountToCraft.setEnableBackgroundDrawing(false); this.amountToCraft.setMaxStringLength(16); this.amountToCraft.setTextColor(0xFFFFFF); this.amountToCraft.setVisible(true); this.amountToCraft.setFocused(true); this.amountToCraft.setText("1"); + this.amountToCraft.setSelectionPos(0); } @Override @@ -112,8 +110,13 @@ public class GuiCraftAmount extends WCTBaseGui { this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize); try { - Long.parseLong(this.amountToCraft.getText()); - this.next.enabled = this.amountToCraft.getText().length() > 0; + String out = this.amountToCraft.getText(); + + double resultD = Calculator.conversion(out); + + int resultI = roundDouble(resultD); + + this.next.enabled = resultI > 0; } catch (final NumberFormatException e) { this.next.enabled = false; } @@ -127,40 +130,8 @@ public class GuiCraftAmount extends WCTBaseGui { if (key == 28) { this.actionPerformed(this.next); } - if ((key == 211 - || key == 205 - || key == 203 - || key == 14 - || character == '-' - || Character.isDigit(character)) - && this.amountToCraft.textboxKeyTyped(character, key)) { - try { - String out = this.amountToCraft.getText(); - - boolean fixed = false; - while (out.startsWith("0") && out.length() > 1) { - out = out.substring(1); - fixed = true; - } - - if (fixed) { - this.amountToCraft.setText(out); - } - - if (out.isEmpty()) { - out = "0"; - } - - final long result = Long.parseLong(out); - if (result < 0) { - this.amountToCraft.setText("1"); - } - } catch (final NumberFormatException e) { - // :P - } - } else { - super.keyTyped(character, key); - } + this.amountToCraft.textboxKeyTyped(character, key); + super.keyTyped(character, key); } } @@ -174,9 +145,12 @@ public class GuiCraftAmount extends WCTBaseGui { NetworkHandler.instance.sendToServer(new PacketSwitchGuis(this.originalGui)); } - if (btn == this.next) { - NetworkHandler.instance.sendToServer( - new PacketCraftRequest(Integer.parseInt(this.amountToCraft.getText()), isShiftKeyDown())); + if (btn == this.next && btn.enabled) { + double resultD = Calculator.conversion(this.amountToCraft.getText()); + + int resultI = roundDouble(resultD); + + NetworkHandler.instance.sendToServer(new PacketCraftRequest(resultI, isShiftKeyDown())); } } catch (final NumberFormatException e) { // nope.. @@ -196,33 +170,20 @@ public class GuiCraftAmount extends WCTBaseGui { try { String out = this.amountToCraft.getText(); - boolean fixed = false; - while (out.startsWith("0") && out.length() > 1) { - out = out.substring(1); - fixed = true; + double resultD = Calculator.conversion(out); + + int resultI = roundDouble(resultD); + + if (resultI == 1 && i > 1) { + resultI = 0; } - if (fixed) { - this.amountToCraft.setText(out); + resultI += i; + if (resultI < 1) { + resultI = 1; } - if (out.isEmpty()) { - out = "0"; - } - - long result = Integer.parseInt(out); - - if (result == 1 && i > 1) { - result = 0; - } - - result += i; - if (result < 1) { - result = 1; - } - - out = Long.toString(result); - Integer.parseInt(out); + out = Integer.toString(resultI); this.amountToCraft.setText(out); } catch (final NumberFormatException e) { // :P @@ -232,4 +193,12 @@ public class GuiCraftAmount extends WCTBaseGui { protected String getBackground() { return "guis/craftAmt.png"; } + + private int roundDouble(double num) { + if (num <= 0 || Double.isNaN(num)) { + return 0; + } else { + return (int) ArithHelper.round(num, 0); + } + } }