Skip to content

Commit

Permalink
Fix most cases of Processing Arrays randomly jamming (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers authored Jan 29, 2023
1 parent 0f4eb2a commit f6ac884
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ public void invalidate() {
this.machineTier = 0;
this.numberOfMachines = 0;
this.numberOfOperations = 0;
this.lastItemInputsMatrix = null;
this.lastItemInputs = null;
this.lastFluidInputs = null;
}

//Finds the Recipe Map of the passed Machine Stack and checks if it is a valid Recipe Map
Expand Down Expand Up @@ -476,6 +479,11 @@ public void findMachineStack() {
//The Processing Array is limited to 1 Machine Interface per multiblock, and only has 1 slot
ItemStack currentMachine = controller.getAbilities(GACapabilities.PA_MACHINE_CONTAINER).get(0).getStackInSlot(0);

if (currentMachine.isEmpty()) {
invalidate();
return;
}

if (!ItemStack.areItemStacksEqual(this.machineItemStack, currentMachine)) {
RecipeMap<?> rmap = findRecipeMapAndCheckValid(currentMachine);

Expand Down Expand Up @@ -646,8 +654,10 @@ private void trySearchNewRecipeDistinct() {
multipliedRecipe = multiplyRecipe(importInventory.get(lastRecipeIndex), importFluids, currentRecipe, machineItemStack, recipeMap);
if(setupAndConsumeRecipeInputs(multipliedRecipe, lastRecipeIndex)) {
setupRecipe(multipliedRecipe);
return;
}
//if the recipe matches return true we HAVE enough of the input to proceed, but are not proceeding due to either lack of energy or output space.
//return earlier to avoid refreshing the input cache too early and missing the inventory change when this recipe is actually invalid.
return;
}

//If the previous recipe is null, check for a new recipe
Expand All @@ -668,9 +678,13 @@ private void trySearchNewRecipeDistinct() {
multipliedRecipe = multiplyRecipe(bus, importFluids, currentRecipe, machineItemStack, recipeMap);
}

if(multipliedRecipe != null && setupAndConsumeRecipeInputs(multipliedRecipe, i)) {
if(multipliedRecipe != null) {
if(setupAndConsumeRecipeInputs(multipliedRecipe, i)) {
setupRecipe(multipliedRecipe);
}
//if the recipe matches return true we HAVE enough of the input to proceed, but are not proceeding due to either lack of energy or output space.
//return earlier to avoid refreshing the input cache too early and missing the inventory change when this recipe is actually invalid.
lastRecipeIndex = i;
setupRecipe(multipliedRecipe);
break;
}
}
Expand Down

0 comments on commit f6ac884

Please sign in to comment.