Skip to content

Commit

Permalink
make the if statements more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed Jul 22, 2021
1 parent dfd6617 commit c847713
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,11 @@ protected void trySearchNewRecipe() {
else {
currentRecipe = findRecipe(maxVoltage, importInventory, importFluids);
}
// If a recipe was found, then inputs were valid.
// If a recipe was found, then inputs were valid. Cache found recipe.
if (currentRecipe != null) {
this.invalidInputsForRecipes = false;
this.previousRecipe = currentRecipe;
// Add-ons may Override findRecipe method but not trySearchNewRecipe, in that case
// they may return a null recipe. Since we only check for items and fluid here, having
// findRecipe return a null recipe with isOutputsFull being true, means we have a valid
// recipe in the input waiting for space in the output.
} else this.invalidInputsForRecipes = !this.isOutputsFull;
}
this.invalidInputsForRecipes = (currentRecipe == null);

// proceed if we have a usable recipe.
if (currentRecipe != null && setupAndConsumeRecipeInputs(currentRecipe))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ protected Recipe findRecipe(long maxVoltage,
/* Iterate over the input items looking for more things to add until we run either out of input items
* or we have exceeded the number of items permissible from the smelting bonus
*/
this.invalidInputsForRecipes = true;
boolean matchedRecipe = false;
boolean canFitOutputs = true;

for(int index = 0; index < inputs.getSlots() && currentItemsEngaged < maxItemsLimit; index++) {

// Skip this slot if it is empty.
Expand All @@ -157,7 +159,7 @@ protected Recipe findRecipe(long maxVoltage,
CountableIngredient inputIngredient;
if(matchingRecipe != null) {
inputIngredient = matchingRecipe.getInputs().get(0);
this.invalidInputsForRecipes = false;
matchedRecipe = true;
}
else
continue;
Expand Down Expand Up @@ -185,7 +187,7 @@ protected Recipe findRecipe(long maxVoltage,
computeOutputItemStacks(temp, matchingRecipe.getOutputs().get(0), recipeMultiplier);

// determine if there is enough room in the output to fit all of this
boolean canFitOutputs = InventoryUtils.simulateItemStackMerge(temp, this.getOutputInventory());
canFitOutputs = InventoryUtils.simulateItemStackMerge(temp, this.getOutputInventory());

// if there isn't, we can't process this recipe.
if(!canFitOutputs)
Expand All @@ -203,13 +205,10 @@ protected Recipe findRecipe(long maxVoltage,
}
}

// If there were no accepted ingredients, then there is no recipe to process.
// the output may be filled up
if (recipeInputs.isEmpty() && !invalidInputsForRecipes) {
//Set here to prevent recipe deadlock on world load with full output bus
this.isOutputsFull = true;
return null;
} else if (recipeInputs.isEmpty()) {
this.invalidInputsForRecipes = !matchedRecipe;
this.isOutputsFull = !canFitOutputs;

if (recipeInputs.isEmpty()) {
return null;
}

Expand Down

0 comments on commit c847713

Please sign in to comment.