Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Voiding and Incorrect Input Consumption in Parallel Recipes #2649

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -818,15 +818,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,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<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);
// exportItemBus.getExportItems().insertItem(3, new ItemStack(Blocks.BONE_BLOCK, 16), false);
IntegerLimit marked this conversation as resolved.
Show resolved Hide resolved

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
Loading