Skip to content

Commit

Permalink
move more logic to MultiblockRecipeLogic
Browse files Browse the repository at this point in the history
fix small issue with recipe matching lists
  • Loading branch information
ghzdude committed Jul 11, 2024
1 parent 97ca32c commit 3700d34
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ protected void trySearchNewRecipe() {
protected boolean checkPreviousRecipe() {
if (this.previousRecipe == null) return false;
if (this.previousRecipe.getEUt() > this.getMaxVoltage()) return false;
return this.previousRecipe.matches(false, getInputInventory(), getInputTank());
return recipeMatch(this.previousRecipe, getInputInventory(), getInputTank());
}

/**
Expand Down Expand Up @@ -685,17 +685,18 @@ protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe,
return false;
}

List<ItemStack> items = gatherItems(importInventory, importFluids);
List<FluidStack> fluids = gatherFluids(importInventory, importFluids);

this.isOutputsFull = false;
if (recipe.matches(true, items, fluids)) {
if (recipeMatch(recipe, importInventory, importFluids)) {
this.metaTileEntity.addNotifiedInput(importInventory);
return true;
}
return false;
}

protected boolean recipeMatch(Recipe recipe, IItemHandlerModifiable inputItems, IMultipleTankHandler inputFluids) {
return recipe.matches(true, inputItems, inputFluids);
}

protected List<ItemStack> gatherItems(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) {
List<ItemStack> items = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ protected void trySearchNewRecipeDistinct() {
return map.findRecipe(maxVoltage, items, fluids);
}

@Override
protected boolean recipeMatch(Recipe recipe, IItemHandlerModifiable inputItems, IMultipleTankHandler inputFluids) {
List<ItemStack> items = gatherItems(inputItems, inputFluids);
List<FluidStack> fluids = gatherFluids(inputItems, inputFluids);

return recipe.matches(true, items, fluids);
}

@Override
public void invalidateInputs() {
MultiblockWithDisplayBase controller = (MultiblockWithDisplayBase) metaTileEntity;
Expand Down
57 changes: 24 additions & 33 deletions src/main/java/gregtech/api/recipes/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,46 +250,37 @@ public final boolean matches(boolean consumeIfSuccessful, IItemHandlerModifiable
* @return true if the recipe matches the given inputs false otherwise.
*/
public boolean matches(boolean consumeIfSuccessful, List<ItemStack> inputs, List<FluidStack> fluidInputs) {
Pair<Boolean, int[]> fluids = null;
Pair<Boolean, int[]> items = null;

if (fluidInputs.size() > 0) {
fluids = matchesFluid(fluidInputs);
if (!fluids.getKey()) {
return false;
}
Pair<Boolean, int[]> fluids = matchesFluid(fluidInputs);
if (!fluids.getKey()) {
return false;
}

if (inputs.size() > 0) {
items = matchesItems(inputs);
if (!items.getKey()) {
return false;
}
Pair<Boolean, int[]> items = matchesItems(inputs);
if (!items.getKey()) {
return false;
}

if (consumeIfSuccessful) {
if (fluids != null) {
int[] fluidAmountInTank = fluids.getValue();
int[] fluidAmountInTank = fluids.getValue();

for (int i = 0; i < fluidAmountInTank.length; i++) {
FluidStack fluidStack = fluidInputs.get(i);
int fluidAmount = fluidAmountInTank[i];
if (fluidStack == null || fluidStack.amount == fluidAmount)
continue;
fluidStack.amount = fluidAmount;
if (fluidStack.amount == 0)
fluidInputs.set(i, null);
}
for (int i = 0; i < fluidAmountInTank.length; i++) {
FluidStack fluidStack = fluidInputs.get(i);
int fluidAmount = fluidAmountInTank[i];
if (fluidStack == null || fluidStack.amount == fluidAmount)
continue;
fluidStack.amount = fluidAmount;
if (fluidStack.amount == 0)
fluidInputs.set(i, null);
}
if (items != null) {
int[] itemAmountInSlot = items.getValue();
for (int i = 0; i < itemAmountInSlot.length; i++) {
ItemStack itemInSlot = inputs.get(i);
int itemAmount = itemAmountInSlot[i];
if (itemInSlot.isEmpty() || itemInSlot.getCount() == itemAmount)
continue;
itemInSlot.setCount(itemAmountInSlot[i]);
}

int[] itemAmountInSlot = items.getValue();

for (int i = 0; i < itemAmountInSlot.length; i++) {
ItemStack itemInSlot = inputs.get(i);
int itemAmount = itemAmountInSlot[i];
if (itemInSlot.isEmpty() || itemInSlot.getCount() == itemAmount)
continue;
itemInSlot.setCount(itemAmountInSlot[i]);
}
}

Expand Down

0 comments on commit 3700d34

Please sign in to comment.