From 3fce70a4064549ed3492ef8facd8cf6ae02339e2 Mon Sep 17 00:00:00 2001 From: firenoo <49818773+firenoo@users.noreply.github.com> Date: Sun, 30 Jul 2023 03:59:03 -0700 Subject: [PATCH] Add pattern doubling to ae2fc terminals (#148) * Brings pattern doubling to ae2fc pattern terms Literally copied and pasted the code over * Update dep --- dependencies.gradle | 2 +- .../base/FCContainerEncodeTerminal.java | 40 +++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 8f1ad7a2..7a667afa 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,7 +2,7 @@ dependencies { api('com.github.GTNewHorizons:NotEnoughItems:2.3.50-GTNH:dev') - api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-240-GTNH:dev') + api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-243-GTNH:dev') api('curse.maven:cofh-core-69162:2388751') api('com.github.GTNewHorizons:waila:1.6.0:dev') compileOnly('com.github.GTNewHorizons:Baubles:1.0.1.16:dev') diff --git a/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerEncodeTerminal.java b/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerEncodeTerminal.java index 86a6c21a..6fc897f9 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerEncodeTerminal.java +++ b/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerEncodeTerminal.java @@ -523,14 +523,40 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor return false; } + static boolean canDouble(SlotFake[] slots, int mult) { + for (Slot s : slots) { + if (s.getStack() != null) { + long result = (long) s.getStack().stackSize * mult; + if (result > Integer.MAX_VALUE) { + return false; + } + } + } + return true; + } + + static void doubleStacksInternal(SlotFake[] slots, int mult) { + List enabledSlots = Arrays.stream(slots).filter(SlotFake::isEnabled).collect(Collectors.toList()); + for (final Slot s : enabledSlots) { + ItemStack st = s.getStack(); + if (st != null) { + st.stackSize *= mult; + s.putStack(st); + } + } + } + public void doubleStacks(boolean isShift) { - if (canDoubleStacks(craftingSlots) && canDoubleStacks(outputSlots)) { - doubleStacksInternal(this.craftingSlots); - doubleStacksInternal(this.outputSlots); - if (isShift && (containsItem(outputSlots) || containsItem(craftingSlots))) { - while (canDoubleStacks(craftingSlots) && canDoubleStacks(outputSlots)) { - doubleStacksInternal(this.craftingSlots); - doubleStacksInternal(this.outputSlots); + if (!isCraftingMode()) { + if (isShift) { + if (canDouble(this.craftingSlots, 8) && canDouble(this.outputSlots, 8)) { + doubleStacksInternal(this.craftingSlots, 8); + doubleStacksInternal(this.outputSlots, 8); + } + } else { + if (canDouble(this.craftingSlots, 2) && canDouble(this.outputSlots, 2)) { + doubleStacksInternal(this.craftingSlots, 2); + doubleStacksInternal(this.outputSlots, 2); } } this.detectAndSendChanges();