Fixes Invalid recipe lag by caching validity of recipe. Thanks to aria1th.

reduces 5mspt -> 0.01mspt
This commit is contained in:
AngelBottomless 2022-02-20 18:26:07 +09:00 committed by GitHub
parent df8706381b
commit 1a4895e525
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -50,7 +50,8 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
int inputSlot = 0;
int outputSlot = 1;
public float experience;
private boolean previousValid = false;
private ItemStack previousStack = ItemStack.EMPTY;
private Recipe<?> lastRecipe = null;
public IronFurnaceBlockEntity(BlockPos pos, BlockState state) {
@ -75,6 +76,9 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
// Fast fail if there is no input, no point checking the recipes if the machine is empty
return ItemStack.EMPTY;
}
if (previousStack.isItemEqualIgnoreDamage(stack) && !previousValid){
return ItemStack.EMPTY;
}
// Check the previous recipe to see if it still applies to the current inv, saves rechecking the whole recipe list
if (lastRecipe != null && RecipeUtils.matchesSingleInput(lastRecipe, stack)) {
@ -123,11 +127,18 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
ItemStack inputStack = inventory.getStack(inputSlot);
if (inputStack.isEmpty())
return false;
if (previousStack != inputStack) {
previousStack = inputStack;
previousValid = true;
}
ItemStack outputStack = getResultFor(inputStack);
if (outputStack.isEmpty())
if (outputStack.isEmpty()) {
previousValid = false;
return false;
}
else {
previousValid = true;
}
ItemStack outputSlotStack = inventory.getStack(outputSlot);
if (outputSlotStack.isEmpty())
return true;