Skip to content

Commit a98c0b2

Browse files
reworked idle logic
avoid iterating the input slots again.
1 parent a4b0822 commit a98c0b2

2 files changed

Lines changed: 11 additions & 22 deletions

File tree

src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public abstract class AbstractRecipeLogic extends MTETrait implements IWorkable
5151
protected boolean workingEnabled = true;
5252
protected boolean hasNotEnoughEnergy;
5353
protected boolean wasActiveAndNeedsUpdate;
54+
protected boolean isInputsEmpty;
5455

5556
public AbstractRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap) {
5657
super(tileEntity);
@@ -111,10 +112,11 @@ public void update() {
111112
if (progressTime == 0) {
112113
trySearchNewRecipe();
113114
if (currentRecipe == null) {
114-
metaTileEntity.setSituation(NO_MATCHING_RECIPE);
115-
}
116-
if (metaTileEntity.isInputEmpty()) {
117-
metaTileEntity.setSituation(IDLE);
115+
if (isInputsEmpty) {
116+
metaTileEntity.setSituation(IDLE);
117+
} else {
118+
metaTileEntity.setSituation(NO_MATCHING_RECIPE);
119+
}
118120
}
119121
}
120122
} else {
@@ -195,6 +197,7 @@ protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMul
195197

196198
protected boolean checkRecipeInputsDirty(IItemHandler inputs, IMultipleTankHandler fluidInputs) {
197199
boolean shouldRecheckRecipe = false;
200+
this.isInputsEmpty = true;
198201
if (lastItemInputs == null || lastItemInputs.length != inputs.getSlots()) {
199202
this.lastItemInputs = new ItemStack[inputs.getSlots()];
200203
Arrays.fill(lastItemInputs, ItemStack.EMPTY);
@@ -211,6 +214,8 @@ protected boolean checkRecipeInputsDirty(IItemHandler inputs, IMultipleTankHandl
211214
} else if (currentStack.getCount() != lastStack.getCount()) {
212215
lastStack.setCount(currentStack.getCount());
213216
shouldRecheckRecipe = true;
217+
} else if (!currentStack.isEmpty()) {
218+
this.isInputsEmpty = false;
214219
}
215220
}
216221
for (int i = 0; i < lastFluidInputs.length; i++) {
@@ -224,6 +229,8 @@ protected boolean checkRecipeInputsDirty(IItemHandler inputs, IMultipleTankHandl
224229
currentStack.amount != lastStack.amount) {
225230
lastStack.amount = currentStack.amount;
226231
shouldRecheckRecipe = true;
232+
} else if (currentStack != null) {
233+
this.isInputsEmpty = false;
227234
}
228235
}
229236
return shouldRecheckRecipe;

src/main/java/gregtech/api/metatileentity/MetaTileEntity.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -992,24 +992,6 @@ public static boolean addFluidsToFluidHandler(IFluidHandler handler, boolean sim
992992
return filledAll;
993993
}
994994

995-
public boolean isInputEmpty() {
996-
if (importItems.getSlots() > 0) {
997-
for (int i = 0; i < importItems.getSlots(); i++) {
998-
if (!importItems.getStackInSlot(i).isEmpty()) {
999-
return false;
1000-
}
1001-
}
1002-
}
1003-
if (importFluids.getTanks() > 0) {
1004-
for (int i = 0; i < importFluids.getTanks(); i++) {
1005-
if (importFluids.getTankAt(i).getFluid() != null) {
1006-
return false;
1007-
}
1008-
}
1009-
}
1010-
return true;
1011-
}
1012-
1013995
public final int getOutputRedstoneSignal(@Nullable EnumFacing side) {
1014996
if (side == null) {
1015997
return getHighestOutputRedstoneSignal();

0 commit comments

Comments
 (0)