aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common
diff options
context:
space:
mode:
authorSampsa <69092953+S4mpsa@users.noreply.github.com>2024-07-25 17:27:27 +0300
committerGitHub <noreply@github.com>2024-07-25 21:27:27 +0700
commitf975d67f62c455533922d3d64d02b3b20b4543ba (patch)
tree801e107923a4ff9ffacf7290849608ca72147416 /src/main/java/gregtech/common
parent88812f7fcd8e33d0c7e57501dda7e043e0e14f47 (diff)
downloadGT5-Unofficial-f975d67f62c455533922d3d64d02b3b20b4543ba.tar.gz
GT5-Unofficial-f975d67f62c455533922d3d64d02b3b20b4543ba.tar.bz2
GT5-Unofficial-f975d67f62c455533922d3d64d02b3b20b4543ba.zip
Add expedited recipe checks for autopulling Stocking Hatch and Bus (#2748)
* Add expedited recipe checks for autopulling Stocking Hatch and Bus * Change to proper Item and FluidStack comparison operators * Forgot one * And a negation * Spotless apply for branch stockingHatchNotifications for #2748 (#2765) spotlessApply Co-authored-by: GitHub GTNH Actions <> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech/common')
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java37
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Input_ME.java23
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/ISmartInputHatch.java13
3 files changed, 70 insertions, 3 deletions
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 c1a4bd8395..01c2489e59 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
@@ -77,8 +77,9 @@ import gregtech.common.gui.modularui.widget.AESlotWidget;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
-public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch_InputBus implements
- IConfigurationCircuitSupport, IRecipeProcessingAwareHatch, IAddGregtechLogo, IAddUIWidgets, IPowerChannelState {
+public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch_InputBus
+ implements IConfigurationCircuitSupport, IRecipeProcessingAwareHatch, IAddGregtechLogo, IAddUIWidgets,
+ IPowerChannelState, ISmartInputHatch {
private static final int SLOT_COUNT = 16;
private BaseActionSource requestSource = null;
@@ -92,6 +93,7 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch
private int autoPullRefreshTime = 100;
private static final int CONFIG_WINDOW_ID = 10;
private boolean additionalConnection = false;
+ private boolean justHadNewItems = false;
public GT_MetaTileEntity_Hatch_InputBus_ME(int aID, boolean autoPullAvailable, String aName, String aNameRegional) {
super(
@@ -392,6 +394,24 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch
}
@Override
+ public boolean justUpdated() {
+ if (autoPullItemList) {
+ boolean ret = justHadNewItems;
+ justHadNewItems = false;
+ return ret;
+ }
+ return false;
+ }
+
+ @Override
+ public void setInventorySlotContents(int aIndex, ItemStack aStack) {
+ if (aStack != null) {
+ justHadNewItems = true;
+ }
+ super.setInventorySlotContents(aIndex, aStack);
+ }
+
+ @Override
public ItemStack getStackInSlot(int aIndex) {
if (!processingRecipe) return super.getStackInSlot(aIndex);
if (aIndex < 0 || aIndex > mInventory.length) return null;
@@ -459,7 +479,11 @@ 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) {
+ justHadNewItems = !itemstack.isItemEqual(previous);
+ }
index++;
}
}
@@ -516,6 +540,9 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch
return checkRecipeResult;
}
+ /**
+ * Update the right side of the GUI, which shows the amounts of items set on the left side
+ */
public ItemStack updateInformationSlot(int aIndex, ItemStack aStack) {
if (aIndex >= 0 && aIndex < SLOT_COUNT) {
if (aStack == null) {
@@ -533,7 +560,13 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch
request.setStackSize(Integer.MAX_VALUE);
IAEItemStack result = sg.extractItems(request, Actionable.SIMULATE, getRequestSource());
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) {
+ justHadNewItems = !s.isItemEqual(previous);
+ }
return s;
} catch (final GridAccessException ignored) {}
}
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 b908dba3fb..8b15b10d35 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
@@ -81,7 +81,7 @@ import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_Input
- implements IPowerChannelState, IAddGregtechLogo, IAddUIWidgets, IRecipeProcessingAwareHatch {
+ implements IPowerChannelState, IAddGregtechLogo, IAddUIWidgets, IRecipeProcessingAwareHatch, ISmartInputHatch {
private static final int SLOT_COUNT = 16;
@@ -106,6 +106,7 @@ 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;
protected static final int CONFIG_WINDOW_ID = 10;
@@ -167,7 +168,11 @@ 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);
+ }
index++;
}
}
@@ -215,6 +220,16 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In
}
@Override
+ public boolean justUpdated() {
+ if (autoPullFluidList) {
+ boolean ret = justHadNewItems;
+ justHadNewItems = false;
+ return ret;
+ }
+ return false;
+ }
+
+ @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
// canTankBeEmptied()) but we do need to support draining from controller, which uses the UNKNOWN direction.
@@ -381,7 +396,13 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In
request.setStackSize(Integer.MAX_VALUE);
IAEFluidStack result = sg.extractItems(request, Actionable.SIMULATE, getRequestSource());
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);
+ }
} catch (final GridAccessException ignored) {}
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/ISmartInputHatch.java b/src/main/java/gregtech/common/tileentities/machines/ISmartInputHatch.java
new file mode 100644
index 0000000000..951dea4abf
--- /dev/null
+++ b/src/main/java/gregtech/common/tileentities/machines/ISmartInputHatch.java
@@ -0,0 +1,13 @@
+package gregtech.common.tileentities.machines;
+
+public interface ISmartInputHatch {
+
+ /*
+ * An interface to allow advanced interaction between hatches and a multiblock controller
+ * Adapted from the Crafting Input Buffer functionality
+ */
+
+ // Have the contents of the hatch changed since the last check?
+ boolean justUpdated();
+
+}