diff options
author | Sampsa <69092953+S4mpsa@users.noreply.github.com> | 2024-07-29 23:50:33 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-29 23:50:33 +0300 |
commit | bbe59c0de8cc6a65369671789123319354148347 (patch) | |
tree | 3d1c984857f6345d356c0072d2b0d15f39986a45 | |
parent | 078a7800baa7ad01f268f53363ced60034811948 (diff) | |
download | GT5-Unofficial-bbe59c0de8cc6a65369671789123319354148347.tar.gz GT5-Unofficial-bbe59c0de8cc6a65369671789123319354148347.tar.bz2 GT5-Unofficial-bbe59c0de8cc6a65369671789123319354148347.zip |
Optimize recipe check forcing and add a button to enable/disable (#2785)
Disable expecited recipe check by default and add a button to enable behavior + optimize
5 files changed, 96 insertions, 29 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index f0f8c9f806..31052f8b8e 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -1605,7 +1605,10 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity return mDualInputHatches.add(hatch); } if (aMetaTileEntity instanceof ISmartInputHatch hatch) { - mSmartInputHatches.add(hatch); + // Only add them to be iterated if enabled for performance reasons + if (hatch.doFastRecipeCheck()) { + mSmartInputHatches.add(hatch); + } } if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { setHatchRecipeMap((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity); diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java index 40bda377a3..11c219aee9 100644 --- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java +++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java @@ -35,6 +35,7 @@ import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; import com.gtnewhorizons.modularui.common.widget.DrawableWidget; import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; import com.gtnewhorizons.modularui.common.widget.SlotGroup; @@ -94,6 +95,7 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch private static final int CONFIG_WINDOW_ID = 10; private boolean additionalConnection = false; private boolean justHadNewItems = false; + private boolean expediteRecipeCheck = false; public GT_MetaTileEntity_Hatch_InputBus_ME(int aID, boolean autoPullAvailable, String aName, String aNameRegional) { super( @@ -215,6 +217,7 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch aNBT.setBoolean("autoStock", autoPullItemList); aNBT.setInteger("minAutoPullStackSize", minAutoPullStackSize); aNBT.setBoolean("additionalConnection", additionalConnection); + aNBT.setBoolean("expediteRecipeCheck", expediteRecipeCheck); aNBT.setInteger("refreshTime", autoPullRefreshTime); getProxy().writeToNBT(aNBT); } @@ -235,6 +238,10 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch updateAllInformationSlots(); } + public boolean doFastRecipeCheck() { + return expediteRecipeCheck; + } + @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); @@ -253,6 +260,7 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch autoPullItemList = aNBT.getBoolean("autoStock"); minAutoPullStackSize = aNBT.getInteger("minAutoPullStackSize"); additionalConnection = aNBT.getBoolean("additionalConnection"); + expediteRecipeCheck = aNBT.getBoolean("expediteRecipeCheck"); if (aNBT.hasKey("refreshTime")) { autoPullRefreshTime = aNBT.getInteger("refreshTime"); } @@ -395,7 +403,7 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch @Override public boolean justUpdated() { - if (autoPullItemList) { + if (expediteRecipeCheck) { boolean ret = justHadNewItems; justHadNewItems = false; return ret; @@ -403,9 +411,13 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch return false; } + public void setRecipeCheck(boolean value) { + expediteRecipeCheck = value; + } + @Override public void setInventorySlotContents(int aIndex, ItemStack aStack) { - if (aStack != null) { + if (expediteRecipeCheck && aStack != null) { justHadNewItems = true; } super.setInventorySlotContents(aIndex, aStack); @@ -479,11 +491,13 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch IAEItemStack currItem = iterator.next(); if (currItem.getStackSize() >= minAutoPullStackSize) { ItemStack itemstack = GT_Utility.copyAmount(1, currItem.getItemStack()); - ItemStack previous = this.mInventory[index]; - this.mInventory[index] = itemstack; - if (itemstack != null && previous != null) { - justHadNewItems = !itemstack.isItemEqual(previous); + if (expediteRecipeCheck) { + ItemStack previous = this.mInventory[index]; + if (itemstack != null) { + justHadNewItems = !ItemStack.areItemStacksEqual(itemstack, previous); + } } + this.mInventory[index] = itemstack; index++; } } @@ -562,11 +576,13 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch ItemStack s = (result != null) ? result.getItemStack() : null; // We want to track changes in any ItemStack to notify any connected controllers to make a recipe // check early - ItemStack previous = getStackInSlot(aIndex + SLOT_COUNT); - setInventorySlotContents(aIndex + SLOT_COUNT, s); - if (s != null && previous != null) { - justHadNewItems = !s.isItemEqual(previous); + if (expediteRecipeCheck) { + ItemStack previous = getStackInSlot(aIndex + SLOT_COUNT); + if (s != null) { + justHadNewItems = !ItemStack.areItemStacksEqual(s, previous); + } } + setInventorySlotContents(aIndex + SLOT_COUNT, s); return s; } catch (final GridAccessException ignored) {} } @@ -733,7 +749,7 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch protected ModularWindow createStackSizeConfigurationWindow(final EntityPlayer player) { final int WIDTH = 78; - final int HEIGHT = 80; + final int HEIGHT = 115; final int PARENT_WIDTH = getGUIWidth(); final int PARENT_HEIGHT = getGUIHeight(); ModularWindow.Builder builder = ModularWindow.builder(WIDTH, HEIGHT); @@ -773,6 +789,19 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch .setSize(70, 18) .setPos(3, 58) .setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD)); + builder.widget( + TextWidget.localised("GT5U.machines.stocking_bus.force_check") + .setPos(3, 88) + .setSize(50, 14)) + .widget( + new CycleButtonWidget().setToggle(() -> expediteRecipeCheck, val -> setRecipeCheck(val)) + .setTextureGetter( + state -> expediteRecipeCheck ? GT_UITextures.OVERLAY_BUTTON_CHECKMARK + : GT_UITextures.OVERLAY_BUTTON_CROSS) + .setBackground(GT_UITextures.BUTTON_STANDARD) + .setPos(53, 87) + .setSize(16, 16) + .addTooltip(StatCollector.translateToLocal("GT5U.machines.stocking_bus.hatch_warning"))); return builder.build(); } @@ -830,8 +859,9 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch strings.add( "Auto-Pull from ME mode will automatically stock the first 16 items in the ME system, updated every 5 seconds."); strings.add("Toggle by right-clicking with screwdriver, or use the GUI."); - strings - .add("Use the GUI to limit the minimum stack size for Auto-Pulling and adjust the slot refresh timer."); + strings.add( + "Use the GUI to limit the minimum stack size for Auto-Pulling, adjust the slot refresh timer and enable fast recipe checks."); + strings.add("WARNING: Fast recipe checks can be laggy. Use with caution."); } strings.add("Change ME connection behavior by right-clicking with wire cutter."); diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Input_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Input_ME.java index 8b15b10d35..b4266caa47 100644 --- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Input_ME.java +++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Input_ME.java @@ -40,6 +40,7 @@ import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import com.gtnewhorizons.modularui.api.widget.Interactable; import com.gtnewhorizons.modularui.common.fluid.FluidStackTank; import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; import com.gtnewhorizons.modularui.common.widget.DrawableWidget; import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; import com.gtnewhorizons.modularui.common.widget.FluidSlotWidget; @@ -106,7 +107,8 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In protected int minAutoPullAmount = 1; private int autoPullRefreshTime = 100; protected boolean processingRecipe = false; - private boolean justHadNewItems = false; + private boolean justHadNewFluids = false; + private boolean expediteRecipeCheck = false; protected static final int CONFIG_WINDOW_ID = 10; @@ -168,11 +170,13 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In IAEFluidStack currItem = iterator.next(); if (currItem.getStackSize() >= minAutoPullAmount) { FluidStack fluidStack = GT_Utility.copyAmount(1, currItem.getFluidStack()); - FluidStack previous = storedFluids[index]; - storedFluids[index] = fluidStack; - if (fluidStack != null) { - justHadNewItems = !fluidStack.isFluidEqual(previous); + if (expediteRecipeCheck) { + FluidStack previous = storedFluids[index]; + if (fluidStack != null && previous != null) { + justHadNewFluids = !fluidStack.isFluidEqual(previous); + } } + storedFluids[index] = fluidStack; index++; } } @@ -221,14 +225,18 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In @Override public boolean justUpdated() { - if (autoPullFluidList) { - boolean ret = justHadNewItems; - justHadNewItems = false; + if (expediteRecipeCheck) { + boolean ret = justHadNewFluids; + justHadNewFluids = false; return ret; } return false; } + public void setRecipeCheck(boolean value) { + expediteRecipeCheck = value; + } + @Override public FluidStack drain(ForgeDirection side, FluidStack aFluid, boolean doDrain) { // this is an ME input hatch. allowing draining via logistics would be very wrong (and against @@ -366,6 +374,10 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In updateAllInformationSlots(); } + public boolean doFastRecipeCheck() { + return expediteRecipeCheck; + } + private void updateAllInformationSlots() { for (int index = 0; index < SLOT_COUNT; index++) { updateInformationSlot(index); @@ -398,11 +410,13 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In FluidStack resultFluid = (result != null) ? result.getFluidStack() : null; // We want to track if any FluidStack is modified to notify any connected controllers to make a recipe check // early - FluidStack previous = storedInformationFluids[index]; - storedInformationFluids[index] = resultFluid; - if (resultFluid != null) { - justHadNewItems = !resultFluid.isFluidEqual(previous); + if (expediteRecipeCheck) { + FluidStack previous = storedInformationFluids[index]; + if (resultFluid != null) { + justHadNewFluids = !resultFluid.isFluidEqual(previous); + } } + storedInformationFluids[index] = resultFluid; } catch (final GridAccessException ignored) {} } @@ -505,6 +519,7 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In aNBT.setBoolean("autoPull", autoPullFluidList); aNBT.setInteger("minAmount", minAutoPullAmount); aNBT.setBoolean("additionalConnection", additionalConnection); + aNBT.setBoolean("expediteRecipeCheck", expediteRecipeCheck); aNBT.setInteger("refreshTime", autoPullRefreshTime); getProxy().writeToNBT(aNBT); } @@ -530,6 +545,7 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In minAutoPullAmount = aNBT.getInteger("minAmount"); autoPullFluidList = aNBT.getBoolean("autoPull"); additionalConnection = aNBT.getBoolean("additionalConnection"); + expediteRecipeCheck = aNBT.getBoolean("expediteRecipeCheck"); if (aNBT.hasKey("refreshTime")) { autoPullRefreshTime = aNBT.getInteger("refreshTime"); } @@ -795,7 +811,7 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In protected ModularWindow createStackSizeConfigurationWindow(final EntityPlayer player) { final int WIDTH = 78; - final int HEIGHT = 80; + final int HEIGHT = 115; final int PARENT_WIDTH = getGUIWidth(); final int PARENT_HEIGHT = getGUIHeight(); ModularWindow.Builder builder = ModularWindow.builder(WIDTH, HEIGHT); @@ -835,6 +851,19 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In .setSize(70, 18) .setPos(3, 58) .setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD)); + builder.widget( + TextWidget.localised("GT5U.machines.stocking_bus.force_check") + .setPos(3, 88) + .setSize(50, 14)) + .widget( + new CycleButtonWidget().setToggle(() -> expediteRecipeCheck, val -> setRecipeCheck(val)) + .setTextureGetter( + state -> expediteRecipeCheck ? GT_UITextures.OVERLAY_BUTTON_CHECKMARK + : GT_UITextures.OVERLAY_BUTTON_CROSS) + .setBackground(GT_UITextures.BUTTON_STANDARD) + .setPos(53, 87) + .setSize(16, 16) + .addTooltip(StatCollector.translateToLocal("GT5U.machines.stocking_bus.hatch_warning"))); return builder.build(); } @@ -892,8 +921,9 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In strings.add( "Auto-Pull from ME mode will automatically stock the first 16 fluid in the ME system, updated every 5 seconds."); strings.add("Toggle by right-clicking with screwdriver, or use the GUI."); - strings - .add("Use the GUI to limit the minimum stack size for Auto-Pulling and adjust the slot refresh timer."); + strings.add( + "Use the GUI to limit the minimum stack size for Auto-Pulling, adjust the slot refresh timer and enable fast recipe checks."); + strings.add("WARNING: Fast recipe checks can be laggy. Use with caution."); } strings.add("Change ME connection behavior by right-clicking with wire cutter."); diff --git a/src/main/java/gregtech/common/tileentities/machines/ISmartInputHatch.java b/src/main/java/gregtech/common/tileentities/machines/ISmartInputHatch.java index 951dea4abf..dc5cac45f8 100644 --- a/src/main/java/gregtech/common/tileentities/machines/ISmartInputHatch.java +++ b/src/main/java/gregtech/common/tileentities/machines/ISmartInputHatch.java @@ -10,4 +10,6 @@ public interface ISmartInputHatch { // Have the contents of the hatch changed since the last check? boolean justUpdated(); + public boolean doFastRecipeCheck(); + } diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index e6b7acac5a..1607a2cfb1 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -417,6 +417,8 @@ GT5U.machines.stocking_bus.auto_pull.tooltip.1=Click to toggle automatic item pu GT5U.machines.stocking_bus.auto_pull.tooltip.2=Right-Click to edit additional parameters. GT5U.machines.stocking_bus.min_stack_size=Min Stack Size GT5U.machines.stocking_bus.refresh_time=Slot Refresh Time (Ticks) +GT5U.machines.stocking_bus.force_check=Recipe Check on change +GT5U.machines.stocking_bus.hatch_warning=Requires a fresh structure check to apply (Reboot/Replace controller) GT5U.machines.stocking_bus.auto_pull_toggle.enabled=Automatic Item Pull Enabled GT5U.machines.stocking_bus.auto_pull_toggle.disabled=Automatic Item Pull Disabled GT5U.machines.stocking_hatch.auto_pull.tooltip.1=Click to toggle automatic fluid pulling from ME. |