Skip to content

Commit

Permalink
Fix Voiding and Incorrect Input Consumption in Parallel Recipes (Greg…
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit authored Nov 24, 2024
1 parent c0c5b60 commit 0911bbf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/recipes/RecipeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -828,15 +828,15 @@ protected static void multiplyInputsAndOutputs(List<GTRecipeInput> newRecipeInpu
if (ri.isNonConsumable()) {
newRecipeInputs.add(ri);
} else {
newRecipeInputs.add(ri.withAmount(ri.getAmount() * numberOfOperations));
newRecipeInputs.add(ri.copyWithAmount(ri.getAmount() * numberOfOperations));
}
});

recipe.getFluidInputs().forEach(fi -> {
if (fi.isNonConsumable()) {
newFluidInputs.add(fi);
} else {
newFluidInputs.add(fi.withAmount(fi.getAmount() * numberOfOperations));
newFluidInputs.add(fi.copyWithAmount(fi.getAmount() * numberOfOperations));
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gregtech/api/util/OverlayedItemHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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<BlastRecipeBuilder> 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);
Expand Down

0 comments on commit 0911bbf

Please sign in to comment.