diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 7d06de0f303..6c0126d0cd9 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -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()); } /** @@ -685,17 +685,18 @@ protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe, return false; } - List items = gatherItems(importInventory, importFluids); - List 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 gatherItems(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { List items = new ArrayList<>(); diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index b56e2e66577..21e2ee2815e 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -260,6 +260,14 @@ protected void trySearchNewRecipeDistinct() { return map.findRecipe(maxVoltage, items, fluids); } + @Override + protected boolean recipeMatch(Recipe recipe, IItemHandlerModifiable inputItems, IMultipleTankHandler inputFluids) { + List items = gatherItems(inputItems, inputFluids); + List fluids = gatherFluids(inputItems, inputFluids); + + return recipe.matches(true, items, fluids); + } + @Override public void invalidateInputs() { MultiblockWithDisplayBase controller = (MultiblockWithDisplayBase) metaTileEntity; diff --git a/src/main/java/gregtech/api/recipes/Recipe.java b/src/main/java/gregtech/api/recipes/Recipe.java index d52be1bac09..4201be698fe 100644 --- a/src/main/java/gregtech/api/recipes/Recipe.java +++ b/src/main/java/gregtech/api/recipes/Recipe.java @@ -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 inputs, List fluidInputs) { - Pair fluids = null; - Pair items = null; - - if (fluidInputs.size() > 0) { - fluids = matchesFluid(fluidInputs); - if (!fluids.getKey()) { - return false; - } + Pair fluids = matchesFluid(fluidInputs); + if (!fluids.getKey()) { + return false; } - if (inputs.size() > 0) { - items = matchesItems(inputs); - if (!items.getKey()) { - return false; - } + Pair 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]); } }