From ecd019b999a9261fb85ba1e4d6a3f98802fbd833 Mon Sep 17 00:00:00 2001 From: miozune Date: Fri, 29 Jul 2022 23:43:34 +0900 Subject: [PATCH 1/5] Port GuiCraftAmount features from AE2 --- dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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") From b1f4b996be8684612b883d3a7d58a23b601f8793 Mon Sep 17 00:00:00 2001 From: miozune Date: Fri, 29 Jul 2022 23:45:06 +0900 Subject: [PATCH 2/5] forgot these... --- .../client/gui/GuiCraftAmount.java | 114 +++++++----------- 1 file changed, 45 insertions(+), 69 deletions(-) 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..4a1bb49 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,18 @@ 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; + + if (resultD <= 0 || Double.isNaN(resultD)) { + resultI = 0; + } else { + resultI = (int) ArithHelper.round(resultD, 0); + } + + this.next.enabled = resultI > 0; } catch (final NumberFormatException e) { this.next.enabled = false; } @@ -127,40 +135,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 +150,17 @@ 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; + + if (resultD <= 0 || Double.isNaN(resultD)) { + resultI = 1; + } else { + resultI = (int) ArithHelper.round(resultD, 0); + } + + NetworkHandler.instance.sendToServer(new PacketCraftRequest(resultI, isShiftKeyDown())); } } catch (final NumberFormatException e) { // nope.. @@ -196,33 +180,25 @@ 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; + + if (resultD <= 0 || Double.isNaN(resultD)) { + resultI = 0; + } else { + resultI = (int) ArithHelper.round(resultD, 0); } - if (fixed) { - this.amountToCraft.setText(out); + if (resultI == 1 && i > 1) { + resultI = 0; } - if (out.isEmpty()) { - out = "0"; + resultI += i; + if (resultI < 1) { + resultI = 1; } - 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 From 0a78cf9e0fca6cbae6c2321d9c064d1e5ffe6218 Mon Sep 17 00:00:00 2001 From: miozune Date: Sat, 30 Jul 2022 20:22:49 +0900 Subject: [PATCH 3/5] extract common code --- .../client/gui/GuiCraftAmount.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) 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 4a1bb49..a27c50b 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java @@ -115,11 +115,7 @@ public class GuiCraftAmount extends WCTBaseGui { double resultD = Calculator.conversion(out); int resultI; - if (resultD <= 0 || Double.isNaN(resultD)) { - resultI = 0; - } else { - resultI = (int) ArithHelper.round(resultD, 0); - } + resultI = roundDouble(resultD); this.next.enabled = resultI > 0; } catch (final NumberFormatException e) { @@ -154,11 +150,7 @@ public class GuiCraftAmount extends WCTBaseGui { double resultD = Calculator.conversion(this.amountToCraft.getText()); int resultI; - if (resultD <= 0 || Double.isNaN(resultD)) { - resultI = 1; - } else { - resultI = (int) ArithHelper.round(resultD, 0); - } + resultI = roundDouble(resultD); NetworkHandler.instance.sendToServer(new PacketCraftRequest(resultI, isShiftKeyDown())); } @@ -183,11 +175,7 @@ public class GuiCraftAmount extends WCTBaseGui { double resultD = Calculator.conversion(out); int resultI; - if (resultD <= 0 || Double.isNaN(resultD)) { - resultI = 0; - } else { - resultI = (int) ArithHelper.round(resultD, 0); - } + resultI = roundDouble(resultD); if (resultI == 1 && i > 1) { resultI = 0; @@ -208,4 +196,13 @@ 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); + } + } } From 0ea8f5fb41083cff314dabd37e08b9bcdba4e833 Mon Sep 17 00:00:00 2001 From: miozune Date: Sat, 30 Jul 2022 20:26:00 +0900 Subject: [PATCH 4/5] spotlessApply --- .../wirelesscraftingterminal/client/gui/GuiCraftAmount.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 a27c50b..1bbc9f2 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java @@ -200,8 +200,7 @@ public class GuiCraftAmount extends WCTBaseGui { private int roundDouble(double num) { if (num <= 0 || Double.isNaN(num)) { return 0; - } - else { + } else { return (int) ArithHelper.round(num, 0); } } From 9f39b6bd16aebf49ebdb66cc6b8ed83dd33684f2 Mon Sep 17 00:00:00 2001 From: miozune Date: Sat, 30 Jul 2022 23:26:24 +0900 Subject: [PATCH 5/5] assign --- .../client/gui/GuiCraftAmount.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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 1bbc9f2..ef5064c 100644 --- a/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java +++ b/src/main/java/net/p455w0rd/wirelesscraftingterminal/client/gui/GuiCraftAmount.java @@ -113,9 +113,8 @@ public class GuiCraftAmount extends WCTBaseGui { String out = this.amountToCraft.getText(); double resultD = Calculator.conversion(out); - int resultI; - resultI = roundDouble(resultD); + int resultI = roundDouble(resultD); this.next.enabled = resultI > 0; } catch (final NumberFormatException e) { @@ -148,9 +147,8 @@ public class GuiCraftAmount extends WCTBaseGui { if (btn == this.next && btn.enabled) { double resultD = Calculator.conversion(this.amountToCraft.getText()); - int resultI; - resultI = roundDouble(resultD); + int resultI = roundDouble(resultD); NetworkHandler.instance.sendToServer(new PacketCraftRequest(resultI, isShiftKeyDown())); } @@ -173,9 +171,8 @@ public class GuiCraftAmount extends WCTBaseGui { String out = this.amountToCraft.getText(); double resultD = Calculator.conversion(out); - int resultI; - resultI = roundDouble(resultD); + int resultI = roundDouble(resultD); if (resultI == 1 && i > 1) { resultI = 0;