diff --git a/src/main/java/gregtech/api/recipes/RecipeBuilder.java b/src/main/java/gregtech/api/recipes/RecipeBuilder.java index d12ec1afb90..d7d8884daa7 100644 --- a/src/main/java/gregtech/api/recipes/RecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/RecipeBuilder.java @@ -828,7 +828,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)); } }); @@ -836,7 +836,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)); } }); 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 diff --git a/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java b/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java index 8ab302939fa..882d9287e6a 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,44 @@ 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); + + 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);