aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/metatileentity/implementations
diff options
context:
space:
mode:
authormiozune <miozune@gmail.com>2023-10-13 17:59:39 +0900
committerGitHub <noreply@github.com>2023-10-13 10:59:39 +0200
commit4c8b94dd91fa5e16534d48415d5a4f75ea0bbb6f (patch)
treeb9222d444b42514e265640aab7c3488816ddccd8 /src/main/java/gregtech/api/metatileentity/implementations
parentb43e65f3784a7978656a4e2a72a2734b37d7b735 (diff)
downloadGT5-Unofficial-4c8b94dd91fa5e16534d48415d5a4f75ea0bbb6f.tar.gz
GT5-Unofficial-4c8b94dd91fa5e16534d48415d5a4f75ea0bbb6f.tar.bz2
GT5-Unofficial-4c8b94dd91fa5e16534d48415d5a4f75ea0bbb6f.zip
Fix Stocking Bus bug (#2326)
* Shut down machine with message if stocking bus fail to extract items * Better way to handle message persistent on shutdown * Minor cleanup * Allow more localizations * Add network status display * Fix auto-pull mode accepting shift insert * Remove workaround for issue with multiple ME buses in a multiblock * Some tweak for appearance * Correct inconsistent variable naming in GT_UITextures * Update .gitignore * Fix typo * Remove isScheduledForResetCheckRecipeResult by using persistsOnShutdown * Apply "cannot set slot" tooltip for empty slots too
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity/implementations')
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java21
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java68
2 files changed, 42 insertions, 47 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java
index 0102b698dd..e7cddffc12 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java
@@ -30,6 +30,8 @@ import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.modularui.IAddUIWidgets;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
+import gregtech.api.recipe.check.CheckRecipeResult;
+import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_ClientPreference;
import gregtech.api.util.GT_OreDictUnificator;
@@ -262,8 +264,27 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch
return mInventory[aIndex] == null;
}
+ /**
+ * Called when multiblock controller starts processing.
+ * {@link #endRecipeProcessing(GT_MetaTileEntity_MultiBlockBase)} is called on the same tick.
+ */
public void startRecipeProcessing() {}
+ /**
+ * Called when multiblock controller ends processing. {@link #startRecipeProcessing()} is called on the same tick.
+ *
+ * @param controller Caller of this method.
+ * @return Result of the process of this method. {@code !wasSuccessful()} means the returned result should
+ * overwrite the result calculated on multiblock whatever the reason is.
+ */
+ public CheckRecipeResult endRecipeProcessing(GT_MetaTileEntity_MultiBlockBase controller) {
+ endRecipeProcessing();
+ return CheckRecipeResultRegistry.SUCCESSFUL;
+ }
+
+ /**
+ * Simple version of {@link #endRecipeProcessing(GT_MetaTileEntity_MultiBlockBase)}. Maybe use it instead.
+ */
public void endRecipeProcessing() {}
@Override
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 2412e0e8ff..d9d5f4c731 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
@@ -12,7 +12,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
@@ -89,7 +88,6 @@ import gregtech.client.GT_SoundLoop;
import gregtech.common.GT_Pollution;
import gregtech.common.gui.modularui.widget.CheckRecipeResultSyncer;
import gregtech.common.items.GT_MetaGenerated_Tool_01;
-import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_InputBus_ME;
import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_OutputBus_ME;
import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_Output_ME;
import gregtech.common.tileentities.machines.IDualInputHatch;
@@ -120,7 +118,6 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
protected VoidingMode voidingMode = getDefaultVoidingMode();
protected boolean batchMode = getDefaultBatchMode();
private @Nonnull CheckRecipeResult checkRecipeResult = CheckRecipeResultRegistry.NONE;
- private boolean isScheduledForResetCheckRecipeResult;
protected static final String INPUT_SEPARATION_NBT_KEY = "inputSeparation";
protected static final String VOID_EXCESS_NBT_KEY = "voidExcess";
@@ -179,7 +176,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
}
/**
- * @deprecated Use {@link GT_Utility#filterValidMTEs)}
+ * @deprecated Use {@link GT_Utility#filterValidMTEs}
*/
@Deprecated
public static <T extends MetaTileEntity> List<T> filterValidMetaTileEntities(Collection<T> metaTileEntities) {
@@ -445,8 +442,6 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
if (aBaseMetaTileEntity.isServerSide()) {
aBaseMetaTileEntity.disableWorking();
checkRecipeResult = CheckRecipeResultRegistry.CRASH;
- // Don't let `onSetActive` to overwrite
- isScheduledForResetCheckRecipeResult = false;
}
}
@@ -499,7 +494,8 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
}
this.checkRecipeResult = result;
endRecipeProcessing();
- return result.wasSuccessful();
+ // Don't use `result` here because `endRecipeProcessing()` might mutate `this.checkRecipeResult`
+ return this.checkRecipeResult.wasSuccessful();
}
private boolean shouldCheckRecipeThisTick(long aTick) {
@@ -896,13 +892,13 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
public void stopMachine() {
mOutputItems = null;
+ mOutputFluids = null;
mEUt = 0;
mEfficiency = 0;
mProgresstime = 0;
mMaxProgresstime = 0;
mEfficiencyIncrease = 0;
getBaseMetaTileEntity().disableWorking();
- checkRecipeResult = CheckRecipeResultRegistry.NONE;
}
public void criticalStopMachine() {
@@ -1369,26 +1365,19 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
}
ArrayList<ItemStack> rList = new ArrayList<>();
- HashMap<String, ItemStack> rInputBusMeList = new HashMap<>();
for (GT_MetaTileEntity_Hatch_InputBus tHatch : filterValidMTEs(mInputBusses)) {
tHatch.mRecipeMap = getRecipeMap();
IGregTechTileEntity tileEntity = tHatch.getBaseMetaTileEntity();
- if (tHatch instanceof GT_MetaTileEntity_Hatch_InputBus_ME) {
- for (int i = tileEntity.getSizeInventory() - 1; i >= 0; i--) {
- ItemStack itemStack = tileEntity.getStackInSlot(i);
- if (itemStack != null) rInputBusMeList.put(itemStack.toString(), itemStack);
- }
- } else {
- for (int i = tileEntity.getSizeInventory() - 1; i >= 0; i--) {
- ItemStack itemStack = tileEntity.getStackInSlot(i);
- if (itemStack != null) rList.add(itemStack);
+ for (int i = tileEntity.getSizeInventory() - 1; i >= 0; i--) {
+ ItemStack itemStack = tileEntity.getStackInSlot(i);
+ if (itemStack != null) {
+ rList.add(itemStack);
}
}
}
if (getStackInSlot(1) != null && getStackInSlot(1).getUnlocalizedName()
.startsWith("gt.integrated_circuit")) rList.add(getStackInSlot(1));
- if (!rInputBusMeList.isEmpty()) rList.addAll(rInputBusMeList.values());
return rList;
}
@@ -1413,21 +1402,18 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
}
protected void startRecipeProcessing() {
- for (GT_MetaTileEntity_Hatch_InputBus tHatch : filterValidMTEs(mInputBusses)) tHatch.startRecipeProcessing();
+ for (GT_MetaTileEntity_Hatch_InputBus hatch : filterValidMTEs(mInputBusses)) {
+ hatch.startRecipeProcessing();
+ }
}
protected void endRecipeProcessing() {
- for (GT_MetaTileEntity_Hatch_InputBus tHatch : filterValidMTEs(mInputBusses)) tHatch.endRecipeProcessing();
- }
-
- protected static <T extends GT_MetaTileEntity_Hatch> T identifyHatch(IGregTechTileEntity aTileEntity,
- int aBaseCasingIndex, Class<T> clazz) {
- if (aTileEntity == null) return null;
- IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
- if (!clazz.isInstance(aMetaTileEntity)) return null;
- T hatch = clazz.cast(aMetaTileEntity);
- hatch.updateTexture(aBaseCasingIndex);
- return hatch;
+ for (GT_MetaTileEntity_Hatch_InputBus hatch : filterValidMTEs(mInputBusses)) {
+ CheckRecipeResult result = hatch.endRecipeProcessing(this);
+ if (!result.wasSuccessful()) {
+ this.checkRecipeResult = result;
+ }
+ }
}
public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) {
@@ -1823,20 +1809,6 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
}
}
- @Override
- public void onSetActive(boolean active) {
- if (isScheduledForResetCheckRecipeResult && !active) {
- checkRecipeResult = CheckRecipeResultRegistry.NONE;
- isScheduledForResetCheckRecipeResult = false;
- }
- }
-
- @Override
- public void onDisableWorking() {
- // This prevents deleting result instantly when turning off machine
- isScheduledForResetCheckRecipeResult = true;
- }
-
protected void setMufflers(boolean state) {
for (GT_MetaTileEntity_Hatch_Muffler aMuffler : mMufflerHatches) {
final IGregTechTileEntity iGTTileEntity = aMuffler.getBaseMetaTileEntity();
@@ -2301,8 +2273,10 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
.setSynced(false)
.setTextAlignment(Alignment.CenterLeft)
.setEnabled(
- widget -> GT_Utility.isStringValid(checkRecipeResult.getDisplayString())
- && shouldDisplayCheckRecipeResult()))
+ widget -> shouldDisplayCheckRecipeResult()
+ && GT_Utility.isStringValid(checkRecipeResult.getDisplayString())
+ && (isAllowedToWork() || getBaseMetaTileEntity().isActive()
+ || checkRecipeResult.persistsOnShutdown())))
.widget(new CheckRecipeResultSyncer(() -> checkRecipeResult, (result) -> checkRecipeResult = result));
if (showRecipeTextInGUI()) {