aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java25
-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
4 files changed, 91 insertions, 7 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 58b82923f2..ff70633e7d 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
@@ -105,6 +105,7 @@ import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_Output_ME;
import gregtech.common.tileentities.machines.IDualInputHatch;
import gregtech.common.tileentities.machines.IDualInputInventory;
import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch;
+import gregtech.common.tileentities.machines.ISmartInputHatch;
import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_LargeTurbine;
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
@@ -148,6 +149,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
public ArrayList<GT_MetaTileEntity_Hatch_InputBus> mInputBusses = new ArrayList<>();
public ArrayList<GT_MetaTileEntity_Hatch_OutputBus> mOutputBusses = new ArrayList<>();
public ArrayList<IDualInputHatch> mDualInputHatches = new ArrayList<>();
+ public ArrayList<ISmartInputHatch> mSmartInputHatches = new ArrayList<>();
public ArrayList<GT_MetaTileEntity_Hatch_Dynamo> mDynamoHatches = new ArrayList<>();
public ArrayList<GT_MetaTileEntity_Hatch_Muffler> mMufflerHatches = new ArrayList<>();
public ArrayList<GT_MetaTileEntity_Hatch_Energy> mEnergyHatches = new ArrayList<>();
@@ -390,6 +392,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
mMufflerHatches.clear();
mMaintenanceHatches.clear();
mDualInputHatches.clear();
+ mSmartInputHatches.clear();
}
public boolean checkStructure(boolean aForceReset) {
@@ -514,6 +517,11 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
shouldCheck |= craftingInputMe.justUpdated();
}
if (shouldCheck) return true;
+ // Do the same for Smart Input Hatches
+ for (ISmartInputHatch smartInputHatch : mSmartInputHatches) {
+ shouldCheck |= smartInputHatch.justUpdated();
+ }
+ if (shouldCheck) return true;
// Perform more frequent recipe change after the machine just shuts down.
long timeElapsed = aTick - mLastWorkingTick;
@@ -582,10 +590,11 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
}
}
} else {
- if (shouldCheckRecipeThisTick(aTick) || aBaseMetaTileEntity.hasWorkJustBeenEnabled()
- || aBaseMetaTileEntity.hasInventoryBeenModified()) {
+ // Check if the machine is enabled in the first place!
+ if (aBaseMetaTileEntity.isAllowedToWork()) {
- if (aBaseMetaTileEntity.isAllowedToWork()) {
+ if (shouldCheckRecipeThisTick(aTick) || aBaseMetaTileEntity.hasWorkJustBeenEnabled()
+ || aBaseMetaTileEntity.hasInventoryBeenModified()) {
if (checkRecipe()) {
markDirty();
}
@@ -1593,6 +1602,9 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
hatch.updateCraftingIcon(this.getMachineCraftingIcon());
return mDualInputHatches.add(hatch);
}
+ if (aMetaTileEntity instanceof ISmartInputHatch hatch) {
+ mSmartInputHatches.add(hatch);
+ }
if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) {
setHatchRecipeMap((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity);
return mInputHatches.add((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity);
@@ -1699,7 +1711,9 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
hatch.updateCraftingIcon(this.getMachineCraftingIcon());
return mDualInputHatches.add(hatch);
}
-
+ if (aMetaTileEntity instanceof ISmartInputHatch hatch) {
+ mSmartInputHatches.add(hatch);
+ }
if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus hatch) {
hatch.updateTexture(aBaseCasingIndex);
hatch.updateCraftingIcon(this.getMachineCraftingIcon());
@@ -1725,6 +1739,9 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
if (aTileEntity == null) return false;
IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
if (aMetaTileEntity == null) return false;
+ if (aMetaTileEntity instanceof ISmartInputHatch hatch) {
+ mSmartInputHatches.add(hatch);
+ }
if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input hatch) {
hatch.updateTexture(aBaseCasingIndex);
hatch.updateCraftingIcon(this.getMachineCraftingIcon());
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();
+
+}