Fixes Invalid recipe lag by caching validity of recipe. Thanks to aria1th.
reduces 5mspt -> 0.01mspt
This commit is contained in:
parent
df8706381b
commit
1a4895e525
1 changed files with 15 additions and 4 deletions
|
@ -50,7 +50,8 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
|
||||||
int inputSlot = 0;
|
int inputSlot = 0;
|
||||||
int outputSlot = 1;
|
int outputSlot = 1;
|
||||||
public float experience;
|
public float experience;
|
||||||
|
private boolean previousValid = false;
|
||||||
|
private ItemStack previousStack = ItemStack.EMPTY;
|
||||||
private Recipe<?> lastRecipe = null;
|
private Recipe<?> lastRecipe = null;
|
||||||
|
|
||||||
public IronFurnaceBlockEntity(BlockPos pos, BlockState state) {
|
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
|
// Fast fail if there is no input, no point checking the recipes if the machine is empty
|
||||||
return ItemStack.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
|
// 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)) {
|
if (lastRecipe != null && RecipeUtils.matchesSingleInput(lastRecipe, stack)) {
|
||||||
|
@ -123,11 +127,18 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
|
||||||
ItemStack inputStack = inventory.getStack(inputSlot);
|
ItemStack inputStack = inventory.getStack(inputSlot);
|
||||||
if (inputStack.isEmpty())
|
if (inputStack.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
if (previousStack != inputStack) {
|
||||||
|
previousStack = inputStack;
|
||||||
|
previousValid = true;
|
||||||
|
}
|
||||||
ItemStack outputStack = getResultFor(inputStack);
|
ItemStack outputStack = getResultFor(inputStack);
|
||||||
if (outputStack.isEmpty())
|
if (outputStack.isEmpty()) {
|
||||||
|
previousValid = false;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
previousValid = true;
|
||||||
|
}
|
||||||
ItemStack outputSlotStack = inventory.getStack(outputSlot);
|
ItemStack outputSlotStack = inventory.getStack(outputSlot);
|
||||||
if (outputSlotStack.isEmpty())
|
if (outputSlotStack.isEmpty())
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue