Skip to content

Commit

Permalink
Fix Stocking Bus bug (GTNewHorizons#2326)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
miozune authored Oct 13, 2023
1 parent b43e65f commit 4c8b94d
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 120 deletions.
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
.gradle
.settings
/.idea/
.shelf
/.vscode/
/run/
/build/
/eclipse/
.vscode
.classpath
.project
/bin/
Expand All @@ -27,12 +26,14 @@ whitelist.json
*.iml
*.ipr
*.iws
src/main/resources/mixins.*.json
src/main/resources/mixins.*([!.]).json
*.bat
/src/main/generated/
/src/test/generated/
.DS_Store
classes
*.DS_Store
!gradlew.bat
.factorypath
addon.local.gradle
addon.local.gradle.kts
addon.late.local.gradle
addon.late.local.gradle.kts
/.vs
layout.json
2 changes: 1 addition & 1 deletion src/main/java/gregtech/GT_Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@
dependencies = " required-after:IC2;" + " required-after:structurelib;"
+ " required-after:gtnhlib@[0.0.8,);"
+ " required-after:modularui@[1.1.12,);"
+ " required-after:appliedenergistics2@[rv3-beta-258,);"
+ " after:dreamcraft;"
+ " after:Forestry;"
+ " after:PFAAGeologica;"
+ " after:Thaumcraft;"
+ " after:Railcraft;"
+ " required-after:appliedenergistics2;"
+ " after:ThermalExpansion;"
+ " after:TwilightForest;"
+ " after:harvestcraft;"
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
13 changes: 1 addition & 12 deletions src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1203,29 +1203,18 @@ public void getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDat
.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));
}
}

@Override
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
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;
Expand Down Expand Up @@ -262,8 +264,27 @@ protected boolean limitedAllowPutStack(int aIndex, ItemStack aStack) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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;
Expand Down Expand Up @@ -89,7 +88,6 @@
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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -179,7 +176,7 @@ public static boolean isValidMetaTileEntity(MetaTileEntity aMetaTileEntity) {
}

/**
* @deprecated Use {@link GT_Utility#filterValidMTEs)}
* @deprecated Use {@link GT_Utility#filterValidMTEs}
*/
@Deprecated
public static <T extends MetaTileEntity> List<T> filterValidMetaTileEntities(Collection<T> metaTileEntities) {
Expand Down Expand Up @@ -445,8 +442,6 @@ public void onTickFail(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
if (aBaseMetaTileEntity.isServerSide()) {
aBaseMetaTileEntity.disableWorking();
checkRecipeResult = CheckRecipeResultRegistry.CRASH;
// Don't let `onSetActive` to overwrite
isScheduledForResetCheckRecipeResult = false;
}
}

Expand Down Expand Up @@ -499,7 +494,8 @@ protected final boolean checkRecipe() {
}
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) {
Expand Down Expand Up @@ -896,13 +892,13 @@ public int getPollutionPerSecond(ItemStack aStack) {

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() {
Expand Down Expand Up @@ -1369,26 +1365,19 @@ public ArrayList<ItemStack> getStoredInputs() {
}

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;
}

Expand All @@ -1413,21 +1402,18 @@ public void updateSlots() {
}

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) {
Expand Down Expand Up @@ -1823,20 +1809,6 @@ public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompou
}
}

@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();
Expand Down Expand Up @@ -2301,8 +2273,10 @@ protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inve
.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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static boolean isRegistered(String id) {
/**
* Code crashed.
*/
public static final CheckRecipeResult CRASH = SimpleCheckRecipeResult.ofFailure("crash");
public static final CheckRecipeResult CRASH = SimpleCheckRecipeResult.ofFailurePersistOnShutdown("crash");
/**
* Cannot find valid fuel for generator.
*/
Expand Down Expand Up @@ -121,7 +121,7 @@ public static CheckRecipeResult insufficientStartupPower(int required) {
}

static {
register(new SimpleCheckRecipeResult(false, ""));
register(new SimpleCheckRecipeResult(false, "", false));
register(new ResultInsufficientPower(0));
register(new ResultInsufficientHeat(0));
register(new ResultInsufficientMachineTier(0));
Expand Down
Loading

0 comments on commit 4c8b94d

Please sign in to comment.