Skip to content

Commit 0911bbf

Browse files
authored
Fix Voiding and Incorrect Input Consumption in Parallel Recipes (#2649)
1 parent c0c5b60 commit 0911bbf

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

src/main/java/gregtech/api/recipes/RecipeBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,15 +828,15 @@ protected static void multiplyInputsAndOutputs(List<GTRecipeInput> newRecipeInpu
828828
if (ri.isNonConsumable()) {
829829
newRecipeInputs.add(ri);
830830
} else {
831-
newRecipeInputs.add(ri.withAmount(ri.getAmount() * numberOfOperations));
831+
newRecipeInputs.add(ri.copyWithAmount(ri.getAmount() * numberOfOperations));
832832
}
833833
});
834834

835835
recipe.getFluidInputs().forEach(fi -> {
836836
if (fi.isNonConsumable()) {
837837
newFluidInputs.add(fi);
838838
} else {
839-
newFluidInputs.add(fi.withAmount(fi.getAmount() * numberOfOperations));
839+
newFluidInputs.add(fi.copyWithAmount(fi.getAmount() * numberOfOperations));
840840
}
841841
});
842842

src/main/java/gregtech/api/util/OverlayedItemHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public int insertStackedItemStack(@NotNull ItemStack stack, int amountToInsert)
5858
ItemStack slotKey = this.slots[i].getItemStack();
5959
if (slotKey.isEmpty() || ItemStackHashStrategy.comparingAllButCount().equals(slotKey, stack)) {
6060
// if the slot is not full
61-
int canInsertUpTo = this.slots[i].getSlotLimit() - this.slots[i].getCount();
61+
int canInsertUpTo = Math.min(this.slots[i].getSlotLimit() - this.slots[i].getCount(),
62+
stack.getMaxStackSize());
6263
if (canInsertUpTo > 0) {
6364
int insertedAmount = Math.min(canInsertUpTo, amountToInsert);
6465
this.slots[i].setItemStack(stack.copy()); // this copy may not be need, needs further tests

src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import gregtech.api.recipes.Recipe;
1313
import gregtech.api.recipes.RecipeBuilder;
1414
import gregtech.api.recipes.RecipeMap;
15+
import gregtech.api.recipes.RecipeMapBuilder;
1516
import gregtech.api.recipes.builders.BlastRecipeBuilder;
1617
import gregtech.api.unification.material.Materials;
1718
import gregtech.api.util.GTUtility;
@@ -24,6 +25,7 @@
2425
import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockPart;
2526

2627
import net.minecraft.init.Blocks;
28+
import net.minecraft.init.Items;
2729
import net.minecraft.item.ItemStack;
2830
import net.minecraft.util.ResourceLocation;
2931
import net.minecraft.world.World;
@@ -38,8 +40,7 @@
3840
import java.lang.reflect.InvocationTargetException;
3941
import java.lang.reflect.Method;
4042

41-
import static org.hamcrest.CoreMatchers.is;
42-
import static org.hamcrest.CoreMatchers.nullValue;
43+
import static org.hamcrest.CoreMatchers.*;
4344

4445
public class IParallelableRecipeLogicTest {
4546

@@ -713,6 +714,44 @@ public MetaTileEntity getMetaTileEntity() {
713714
MatcherAssert.assertThat(outputRecipe, nullValue());
714715
}
715716

717+
@Test
718+
public void findParallelRecipe_SmallMaxStackSize() {
719+
MetaTileEntityElectricBlastFurnace EBF = initEBF(521);
720+
721+
int parallelLimit = 4;
722+
723+
// Create a recipe Map to be used for testing
724+
RecipeMap<BlastRecipeBuilder> map = new RecipeMapBuilder<>("electric_blast_furnace", new BlastRecipeBuilder())
725+
.itemInputs(3).itemOutputs(2).fluidInputs(1).fluidOutputs(1).build();
726+
727+
// Create a simple recipe to be used for testing
728+
// Use an output item with small max stack size
729+
Recipe recipe = map.recipeBuilder()
730+
.inputs(new ItemStack(Blocks.COBBLESTONE))
731+
.outputs(new ItemStack(Items.ELYTRA))
732+
.blastFurnaceTemp(1000)
733+
.EUt(30).duration(100)
734+
.build().getResult();
735+
736+
IParallelableRecipeLogic logic = new ParallelableTestLogic(EBF, map, ParallelLogicType.MULTIPLY);
737+
738+
// Populate the Input Bus
739+
importItemBus.getImportItems().insertItem(0, new ItemStack(Blocks.COBBLESTONE, 16), false);
740+
741+
// Saturate the export bus, except for one slot
742+
exportItemBus.getExportItems().insertItem(0, new ItemStack(Blocks.BONE_BLOCK, 16), false);
743+
exportItemBus.getExportItems().insertItem(1, new ItemStack(Blocks.BONE_BLOCK, 16), false);
744+
exportItemBus.getExportItems().insertItem(2, new ItemStack(Blocks.BONE_BLOCK, 16), false);
745+
746+
RecipeBuilder<?> parallelRecipe = logic.findMultipliedParallelRecipe(map, recipe,
747+
importItemBus.getImportItems(), importFluidBus.getImportFluids(),
748+
exportItemBus.getExportItems(), exportFluidBus.getExportFluids(), parallelLimit, Integer.MAX_VALUE,
749+
EBF);
750+
751+
MatcherAssert.assertThat(parallelRecipe, notNullValue());
752+
MatcherAssert.assertThat(parallelRecipe.getParallel(), is(1));
753+
}
754+
716755
@Test
717756
public void applyParallelBonus_Test() {
718757
MetaTileEntityElectricBlastFurnace EBF = initEBF(518);

0 commit comments

Comments
 (0)