From 2cfbb427d38ea90f1ae2ad6787660c82e3f52d82 Mon Sep 17 00:00:00 2001 From: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Date: Thu, 24 Oct 2024 08:20:33 +1100 Subject: [PATCH 1/4] Fix Parallelization of Recipes with Non-Cached Inputs --- src/main/java/gregtech/api/recipes/RecipeBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/recipes/RecipeBuilder.java b/src/main/java/gregtech/api/recipes/RecipeBuilder.java index c267b5f5bb5..f808cb78365 100644 --- a/src/main/java/gregtech/api/recipes/RecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/RecipeBuilder.java @@ -818,7 +818,7 @@ protected static void multiplyInputsAndOutputs(List newRecipeInpu if (ri.isNonConsumable()) { newRecipeInputs.add(ri); } else { - newRecipeInputs.add(ri.withAmount(ri.getAmount() * numberOfOperations)); + newRecipeInputs.add(ri.copyWithAmount(ri.getAmount() * numberOfOperations)); } }); @@ -826,7 +826,7 @@ protected static void multiplyInputsAndOutputs(List newRecipeInpu if (fi.isNonConsumable()) { newFluidInputs.add(fi); } else { - newFluidInputs.add(fi.withAmount(fi.getAmount() * numberOfOperations)); + newFluidInputs.add(fi.copyWithAmount(fi.getAmount() * numberOfOperations)); } }); From 1034af446c107dd93472199660764a9a3c40d8df Mon Sep 17 00:00:00 2001 From: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Date: Thu, 24 Oct 2024 08:26:07 +1100 Subject: [PATCH 2/4] Fix Voiding in Certain Parallelizing Recipes --- src/main/java/gregtech/api/util/OverlayedItemHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/util/OverlayedItemHandler.java b/src/main/java/gregtech/api/util/OverlayedItemHandler.java index 83c63422930..dcd73ddb281 100644 --- a/src/main/java/gregtech/api/util/OverlayedItemHandler.java +++ b/src/main/java/gregtech/api/util/OverlayedItemHandler.java @@ -58,7 +58,8 @@ public int insertStackedItemStack(@NotNull ItemStack stack, int amountToInsert) ItemStack slotKey = this.slots[i].getItemStack(); if (slotKey.isEmpty() || ItemStackHashStrategy.comparingAllButCount().equals(slotKey, stack)) { // if the slot is not full - int canInsertUpTo = this.slots[i].getSlotLimit() - this.slots[i].getCount(); + int canInsertUpTo = Math.min(this.slots[i].getSlotLimit() - this.slots[i].getCount(), + stack.getMaxStackSize()); if (canInsertUpTo > 0) { int insertedAmount = Math.min(canInsertUpTo, amountToInsert); this.slots[i].setItemStack(stack.copy()); // this copy may not be need, needs further tests From 2a2ec242e5162432eb6bdd25fb446dd846adece7 Mon Sep 17 00:00:00 2001 From: alongstringofnumbers Date: Sun, 27 Oct 2024 16:46:56 -0700 Subject: [PATCH 3/4] Add a test for new fix --- .../logic/IParallelableRecipeLogicTest.java | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java b/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java index 8ab302939fa..56111295275 100644 --- a/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java +++ b/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java @@ -12,6 +12,7 @@ import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeBuilder; import gregtech.api.recipes.RecipeMap; +import gregtech.api.recipes.RecipeMapBuilder; import gregtech.api.recipes.builders.BlastRecipeBuilder; import gregtech.api.unification.material.Materials; import gregtech.api.util.GTUtility; @@ -24,6 +25,7 @@ import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockPart; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; @@ -38,8 +40,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.CoreMatchers.*; public class IParallelableRecipeLogicTest { @@ -713,6 +714,45 @@ public MetaTileEntity getMetaTileEntity() { MatcherAssert.assertThat(outputRecipe, nullValue()); } + @Test + public void findParallelRecipe_SmallMaxStackSize() { + MetaTileEntityElectricBlastFurnace EBF = initEBF(521); + + int parallelLimit = 4; + + // Create a recipe Map to be used for testing + RecipeMap map = new RecipeMapBuilder<>("electric_blast_furnace", new BlastRecipeBuilder()) + .itemInputs(3).itemOutputs(2).fluidInputs(1).fluidOutputs(1).build(); + + // Create a simple recipe to be used for testing + // Use an output item with small max stack size + Recipe recipe = map.recipeBuilder() + .inputs(new ItemStack(Blocks.COBBLESTONE)) + .outputs(new ItemStack(Items.ELYTRA)) + .blastFurnaceTemp(1000) + .EUt(30).duration(100) + .build().getResult(); + + IParallelableRecipeLogic logic = new ParallelableTestLogic(EBF, map, ParallelLogicType.MULTIPLY); + + // Populate the Input Bus + importItemBus.getImportItems().insertItem(0, new ItemStack(Blocks.COBBLESTONE, 16), false); + + // Saturate the export bus, except for one slot + exportItemBus.getExportItems().insertItem(0, new ItemStack(Blocks.BONE_BLOCK, 16), false); + exportItemBus.getExportItems().insertItem(1, new ItemStack(Blocks.BONE_BLOCK, 16), false); + exportItemBus.getExportItems().insertItem(2, new ItemStack(Blocks.BONE_BLOCK, 16), false); + // exportItemBus.getExportItems().insertItem(3, new ItemStack(Blocks.BONE_BLOCK, 16), false); + + RecipeBuilder parallelRecipe = logic.findMultipliedParallelRecipe(map, recipe, + importItemBus.getImportItems(), importFluidBus.getImportFluids(), + exportItemBus.getExportItems(), exportFluidBus.getExportFluids(), parallelLimit, Integer.MAX_VALUE, + EBF); + + MatcherAssert.assertThat(parallelRecipe, notNullValue()); + MatcherAssert.assertThat(parallelRecipe.getParallel(), is(1)); + } + @Test public void applyParallelBonus_Test() { MetaTileEntityElectricBlastFurnace EBF = initEBF(518); From 02a7e2c34bee235c381fb648f2a3057fff0e8b9f Mon Sep 17 00:00:00 2001 From: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:20:06 +1100 Subject: [PATCH 4/4] Review --- .../gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java b/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java index 56111295275..882d9287e6a 100644 --- a/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java +++ b/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java @@ -742,7 +742,6 @@ public void findParallelRecipe_SmallMaxStackSize() { exportItemBus.getExportItems().insertItem(0, new ItemStack(Blocks.BONE_BLOCK, 16), false); exportItemBus.getExportItems().insertItem(1, new ItemStack(Blocks.BONE_BLOCK, 16), false); exportItemBus.getExportItems().insertItem(2, new ItemStack(Blocks.BONE_BLOCK, 16), false); - // exportItemBus.getExportItems().insertItem(3, new ItemStack(Blocks.BONE_BLOCK, 16), false); RecipeBuilder parallelRecipe = logic.findMultipliedParallelRecipe(map, recipe, importItemBus.getImportItems(), importFluidBus.getImportFluids(),