diff options
Diffstat (limited to 'src/main/java/gregtech/api')
7 files changed, 83 insertions, 74 deletions
diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java index ffeec40561..1a47e41e8c 100644 --- a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java +++ b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java @@ -368,18 +368,18 @@ public class GT_UITextures { .fullImage(GregTech.ID, "gui/overlay_button/use_processing_state.png"); public static final UITexture OVERLAY_BUTTON_USE_INVERTED_PROCESSING_STATE = UITexture .fullImage(GregTech.ID, "gui/overlay_button/use_inverted_processing_state.png"); - public static final UITexture OVERLAY_CHUNK_LOADING = UITexture + public static final UITexture OVERLAY_BUTTON_CHUNK_LOADING = UITexture .fullImage(GregTech.ID, "gui/overlay_button/chunkloading"); - public static final UITexture OVERLAY_CHUNK_LOADING_OFF = UITexture + public static final UITexture OVERLAY_BUTTON_CHUNK_LOADING_OFF = UITexture .fullImage(GregTech.ID, "gui/overlay_button/chunkloading_off"); - public static final UITexture OVERLAY_WORK_AREA = UITexture.fullImage(GregTech.ID, "gui/overlay_button/work_area"); - public static final UITexture OVERLAY_REPLACE_COBBLE_ON = UITexture + public static final UITexture OVERLAY_BUTTON_WORK_AREA = UITexture + .fullImage(GregTech.ID, "gui/overlay_button/work_area"); + public static final UITexture OVERLAY_BUTTON_REPLACE_COBBLE_ON = UITexture .fullImage(GregTech.ID, "gui/overlay_button/replace_cobble_on"); - public static final UITexture OVERLAY_REPLACE_COBBLE_OFF = UITexture + public static final UITexture OVERLAY_BUTTON_REPLACE_COBBLE_OFF = UITexture .fullImage(GregTech.ID, "gui/overlay_button/replace_cobble_off"); - public static final UITexture OVERLAY_RETRACT_PIPE = UITexture + public static final UITexture OVERLAY_BUTTON_RETRACT_PIPE = UITexture .fullImage(GregTech.ID, "gui/overlay_button/retract_pipes"); - public static final UITexture OVERLAY_BUTTON_HOURGLASS = UITexture .fullImage(GregTech.ID, "gui/overlay_button/hourglass"); diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index 1ac42a2ea1..6267e7b3da 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -1203,21 +1203,11 @@ public abstract class MetaTileEntity implements IMetaTileEntity, ICleanroomRecei .name())); if (this instanceof IPowerChannelState state) { - // adapted from PowerStateWailaDataProvider final NBTTagCompound tag = accessor.getNBTData(); final boolean isActive = tag.getBoolean("isActive"); final boolean isPowered = tag.getBoolean("isPowered"); final boolean isBooting = tag.getBoolean("isBooting"); - - if (isBooting) { - currenttip.add(WailaText.Booting.getLocal()); - } else if (isActive && isPowered) { - currenttip.add(WailaText.DeviceOnline.getLocal()); - } else if (isPowered) { - currenttip.add(WailaText.DeviceMissingChannel.getLocal()); - } else { - currenttip.add(WailaText.DeviceOffline.getLocal()); - } + currenttip.add(WailaText.getPowerState(isActive, isPowered, isBooting)); } } @@ -1225,7 +1215,6 @@ public abstract class MetaTileEntity implements IMetaTileEntity, ICleanroomRecei public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y, int z) { if (this instanceof IPowerChannelState state) { - // adapted from PowerStateWailaDataProvider final boolean isActive = state.isActive(); final boolean isPowered = state.isPowered(); final boolean isBooting = state.isBooting(); 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()) { diff --git a/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java b/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java index ab1db6ecd2..eeb01077de 100644 --- a/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java +++ b/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java @@ -39,4 +39,11 @@ public interface CheckRecipeResult { * Decode synced value. */ void decode(PacketBuffer buffer); + + /** + * @return If this message should stay on GUI when the machine is shut down. + */ + default boolean persistsOnShutdown() { + return false; + } } diff --git a/src/main/java/gregtech/api/recipe/check/CheckRecipeResultRegistry.java b/src/main/java/gregtech/api/recipe/check/CheckRecipeResultRegistry.java index ad0d56708e..f162c892ee 100644 --- a/src/main/java/gregtech/api/recipe/check/CheckRecipeResultRegistry.java +++ b/src/main/java/gregtech/api/recipe/check/CheckRecipeResultRegistry.java @@ -59,7 +59,7 @@ public final class CheckRecipeResultRegistry { /** * Code crashed. */ - public static final CheckRecipeResult CRASH = SimpleCheckRecipeResult.ofFailure("crash"); + public static final CheckRecipeResult CRASH = SimpleCheckRecipeResult.ofFailurePersistOnShutdown("crash"); /** * Cannot find valid fuel for generator. */ @@ -121,7 +121,7 @@ public final class CheckRecipeResultRegistry { } static { - register(new SimpleCheckRecipeResult(false, "")); + register(new SimpleCheckRecipeResult(false, "", false)); register(new ResultInsufficientPower(0)); register(new ResultInsufficientHeat(0)); register(new ResultInsufficientMachineTier(0)); diff --git a/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java b/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java index 767a168125..ed4c95f880 100644 --- a/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java +++ b/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java @@ -14,10 +14,12 @@ public class SimpleCheckRecipeResult implements CheckRecipeResult { private boolean success; private String key; + private boolean persistsOnShutdown; - SimpleCheckRecipeResult(boolean success, String key) { + SimpleCheckRecipeResult(boolean success, String key, boolean persistsOnShutdown) { this.success = success; this.key = key; + this.persistsOnShutdown = persistsOnShutdown; } @Override @@ -37,19 +39,26 @@ public class SimpleCheckRecipeResult implements CheckRecipeResult { @Override public CheckRecipeResult newInstance() { - return new SimpleCheckRecipeResult(false, ""); + return new SimpleCheckRecipeResult(false, "", false); } @Override public void encode(PacketBuffer buffer) { buffer.writeBoolean(success); NetworkUtils.writeStringSafe(buffer, key); + buffer.writeBoolean(persistsOnShutdown); } @Override public void decode(PacketBuffer buffer) { success = buffer.readBoolean(); key = NetworkUtils.readStringSafe(buffer); + persistsOnShutdown = buffer.readBoolean(); + } + + @Override + public boolean persistsOnShutdown() { + return persistsOnShutdown; } @Override @@ -57,7 +66,8 @@ public class SimpleCheckRecipeResult implements CheckRecipeResult { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SimpleCheckRecipeResult that = (SimpleCheckRecipeResult) o; - return success == that.success && Objects.equals(key, that.key); + return success == that.success && Objects.equals(key, that.key) + && persistsOnShutdown == that.persistsOnShutdown; } /** @@ -65,14 +75,22 @@ public class SimpleCheckRecipeResult implements CheckRecipeResult { * This is already registered to registry. */ public static CheckRecipeResult ofSuccess(String key) { - return new SimpleCheckRecipeResult(true, key); + return new SimpleCheckRecipeResult(true, key, false); } /** - * Creates new result object with failed state. Add your localized description with `GT5U.gui.text.{key}`. + * Creates new result with failed state. Add your localized description with `GT5U.gui.text.{key}`. * This is already registered to registry. */ public static CheckRecipeResult ofFailure(String key) { - return new SimpleCheckRecipeResult(false, key); + return new SimpleCheckRecipeResult(false, key, false); + } + + /** + * Creates new result object with failed state that does not get reset on shutdown. Add your localized description + * with `GT5U.gui.text.{key}`. This is already registered to registry. + */ + public static CheckRecipeResult ofFailurePersistOnShutdown(String key) { + return new SimpleCheckRecipeResult(false, key, true); } } |