Skip to content

Commit

Permalink
remove unused parameter from RecipeMap#findRecipe() (#1650)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 authored Mar 26, 2023
1 parent 504efa7 commit 46fe29d
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMul
return null;
}

return map.findRecipe(maxVoltage, inputs, fluidInputs, getMinTankCapacity(getOutputTank()));
return map.findRecipe(maxVoltage, inputs, fluidInputs);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected void trySearchNewRecipe() {
if (fuelStack == null || ModHandler.isWater(fuelStack)) continue;

Recipe dieselRecipe = RecipeMaps.COMBUSTION_GENERATOR_FUELS.findRecipe(
GTValues.V[GTValues.MAX], dummyList, Collections.singletonList(fuelStack), Integer.MAX_VALUE);
GTValues.V[GTValues.MAX], dummyList, Collections.singletonList(fuelStack));
// run only if it can apply a certain amount of "parallel", this is to mitigate int division
if (dieselRecipe != null && fuelStack.amount >= dieselRecipe.getFluidInputs().get(0).getAmount() * FLUID_DRAIN_MULTIPLIER) {
fluidTank.drain(dieselRecipe.getFluidInputs().get(0).getAmount() * FLUID_DRAIN_MULTIPLIER, true);
Expand All @@ -86,7 +86,7 @@ protected void trySearchNewRecipe() {
}

Recipe denseFuelRecipe = RecipeMaps.SEMI_FLUID_GENERATOR_FUELS.findRecipe(
GTValues.V[GTValues.MAX], dummyList, Collections.singletonList(fuelStack), Integer.MAX_VALUE);
GTValues.V[GTValues.MAX], dummyList, Collections.singletonList(fuelStack));
// run only if it can apply a certain amount of "parallel", this is to mitigate int division
if (denseFuelRecipe != null && fuelStack.amount >= denseFuelRecipe.getFluidInputs().get(0).getAmount() * FLUID_DRAIN_MULTIPLIER) {
fluidTank.drain(denseFuelRecipe.getFluidInputs().get(0).getAmount() * FLUID_DRAIN_MULTIPLIER, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private static double getQuotient(double base) {
*/
protected static void applyTieredHammerNoRandomDrops(@Nonnull IBlockState blockState, List<ItemStack> drops, int fortuneLevel, @Nonnull RecipeMap<?> map, int tier) {
ItemStack itemStack = GTUtility.toItem(blockState);
Recipe recipe = map.findRecipe(Long.MAX_VALUE, Collections.singletonList(itemStack), Collections.emptyList(), 0);
Recipe recipe = map.findRecipe(Long.MAX_VALUE, Collections.singletonList(itemStack), Collections.emptyList());
if (recipe != null && !recipe.getOutputs().isEmpty()) {
drops.clear();
for (ItemStack outputStack : recipe.getResultItemOutputs(GTUtility.getTierByVoltage(recipe.getEUt()), tier, map)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/items/toolitem/ToolHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public static void applyHammerDropConversion(ItemStack tool, IBlockState state,
// Stack lists can be immutable going into Recipe#matches barring no rewrites
List<ItemStack> dropAsList = Collections.singletonList(silktouchDrop);
// Search for forge hammer recipes from all drops individually (only LV or under)
Recipe hammerRecipe = RecipeMaps.FORGE_HAMMER_RECIPES.findRecipe(GTValues.V[1], dropAsList, Collections.emptyList(), 0, false);
Recipe hammerRecipe = RecipeMaps.FORGE_HAMMER_RECIPES.findRecipe(GTValues.V[1], dropAsList, Collections.emptyList(), false);
if (hammerRecipe != null && hammerRecipe.matches(true, dropAsList, Collections.emptyList())) {
drops.clear();
OrePrefix prefix = OreDictUnifier.getPrefix(silktouchDrop);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/recipes/GTRecipeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static <R extends RecipeBuilder<R>> boolean removeRecipesByInputs(RecipeM
}
}

boolean wasRemoved = map.removeRecipe(map.findRecipe(Long.MAX_VALUE, itemIn, fluidIn, Integer.MAX_VALUE));
boolean wasRemoved = map.removeRecipe(map.findRecipe(Long.MAX_VALUE, itemIn, fluidIn));
if (ConfigHolder.misc.debug) {
if (wasRemoved)
GTLog.logger.info("Removed Recipe for inputs: Items: {} Fluids: {}", itemNames, fluidNames);
Expand Down
28 changes: 13 additions & 15 deletions src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,36 +394,34 @@ protected ValidationResult<Recipe> postValidateRecipe(@Nonnull ValidationResult<
}

@Nullable
public Recipe findRecipe(long voltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs, int outputFluidTankCapacity) {
return this.findRecipe(voltage, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs), outputFluidTankCapacity);
public Recipe findRecipe(long voltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs) {
return this.findRecipe(voltage, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs));
}

/**
* Finds a Recipe matching the Fluid and/or ItemStack Inputs.
*
* @param voltage Voltage of the Machine or Long.MAX_VALUE if it has no Voltage
* @param inputs the Item Inputs
* @param fluidInputs the Fluid Inputs
* @param outputFluidTankCapacity minimal capacity of output fluid tank, used for fluid canner recipes for example
* @param voltage Voltage of the Machine or Long.MAX_VALUE if it has no Voltage
* @param inputs the Item Inputs
* @param fluidInputs the Fluid Inputs
* @return the Recipe it has found or null for no matching Recipe
*/
@Nullable
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, int outputFluidTankCapacity) {
return findRecipe(voltage, inputs, fluidInputs, outputFluidTankCapacity, false);
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs) {
return findRecipe(voltage, inputs, fluidInputs, false);
}

/**
* Finds a Recipe matching the Fluid and/or ItemStack Inputs.
*
* @param voltage Voltage of the Machine or Long.MAX_VALUE if it has no Voltage
* @param inputs the Item Inputs
* @param fluidInputs the Fluid Inputs
* @param outputFluidTankCapacity minimal capacity of output fluid tank, used for fluid canner recipes for example
* @param exactVoltage should require exact voltage matching on recipe. used by craftweaker
* @param voltage Voltage of the Machine or Long.MAX_VALUE if it has no Voltage
* @param inputs the Item Inputs
* @param fluidInputs the Fluid Inputs
* @param exactVoltage should require exact voltage matching on recipe. used by craftweaker
* @return the Recipe it has found or null for no matching Recipe
*/
@Nullable
public Recipe findRecipe(long voltage, final List<ItemStack> inputs, final List<FluidStack> fluidInputs, int outputFluidTankCapacity, boolean exactVoltage) {
public Recipe findRecipe(long voltage, final List<ItemStack> inputs, final List<FluidStack> fluidInputs, boolean exactVoltage) {
final List<ItemStack> items = inputs.stream().filter(s -> !s.isEmpty()).collect(Collectors.toList());
final List<FluidStack> fluids = fluidInputs.stream().filter(f -> f != null && f.amount != 0).collect(Collectors.toList());

Expand Down Expand Up @@ -1150,7 +1148,7 @@ public SoundEvent getSound() {
public CTRecipe ctFindRecipe(long maxVoltage, IItemStack[] itemInputs, ILiquidStack[] fluidInputs, @Optional(valueLong = Integer.MAX_VALUE) int outputFluidTankCapacity) {
List<ItemStack> mcItemInputs = itemInputs == null ? Collections.emptyList() : Arrays.stream(itemInputs).map(CraftTweakerMC::getItemStack).collect(Collectors.toList());
List<FluidStack> mcFluidInputs = fluidInputs == null ? Collections.emptyList() : Arrays.stream(fluidInputs).map(CraftTweakerMC::getLiquidStack).collect(Collectors.toList());
Recipe backingRecipe = findRecipe(maxVoltage, mcItemInputs, mcFluidInputs, outputFluidTankCapacity, true);
Recipe backingRecipe = findRecipe(maxVoltage, mcItemInputs, mcFluidInputs, true);
return backingRecipe == null ? null : new CTRecipe(this, backingRecipe);
}

Expand Down
7 changes: 1 addition & 6 deletions src/main/java/gregtech/api/recipes/logic/ParallelLogic.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package gregtech.api.recipes.logic;

import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.recipes.FluidKey;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeBuilder;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.metatileentity.IVoidable;
import gregtech.api.recipes.FluidKey;
import gregtech.api.recipes.Recipe;
Expand Down Expand Up @@ -505,7 +500,7 @@ public static RecipeBuilder<?> appendItemRecipes(@Nonnull RecipeMap<?> recipeMap
// Determine if there is a valid recipe for this item. If not, skip it.
Recipe matchingRecipe = recipeMap.findRecipe(maxVoltage,
Collections.singletonList(currentInputItem),
Collections.emptyList(), 0);
Collections.emptyList());

GTRecipeInput inputIngredient;
if (matchingRecipe != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public RecipeMapFluidCanner(String unlocalizedName, int maxInputs, int maxOutput

@Override
@Nullable
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, int outputFluidTankCapacity, boolean exactVoltage) {
Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs, outputFluidTankCapacity, exactVoltage);
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, boolean exactVoltage) {
Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs, exactVoltage);
if (recipe != null) return recipe;

for (ItemStack input : inputs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public RecipeMapFormingPress(String unlocalizedName, int maxInputs, int maxOutpu

@Override
@Nullable
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, int outputFluidTankCapacity, boolean exactVoltage) {
Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs, outputFluidTankCapacity, exactVoltage);
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, boolean exactVoltage) {
Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs, exactVoltage);

// Item Mold renaming - min of 2 inputs required
if (recipe == null && inputs.size() > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public RecipeMapFurnace(String unlocalizedName, int maxInputs, int maxOutputs, i

@Override
@Nullable
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, int outputFluidTankCapacity, boolean exactVoltage) {
Recipe normalRecipe = super.findRecipe(voltage, inputs, fluidInputs, outputFluidTankCapacity, exactVoltage);
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, boolean exactVoltage) {
Recipe normalRecipe = super.findRecipe(voltage, inputs, fluidInputs, exactVoltage);
if (normalRecipe != null || inputs.size() == 0)
return normalRecipe;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Object matchItemStack(ItemStack itemStack) {
ItemStack infinitelyBigStack = itemStack.copy();
infinitelyBigStack.setCount(Integer.MAX_VALUE);

Recipe recipe = filteringMode.recipeMap.findRecipe(Long.MAX_VALUE, Collections.singletonList(infinitelyBigStack), Collections.emptyList(), Integer.MAX_VALUE);
Recipe recipe = filteringMode.recipeMap.findRecipe(Long.MAX_VALUE, Collections.singletonList(infinitelyBigStack), Collections.emptyList());
if (recipe == null) {
filteringMode.transferStackSizesCache.put(itemAndMetadata, 0);
cachedTransferRateValue = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public SimpleObjectStream<Recipe> streamRecipes() {
public Recipe find(long voltage, List<ItemStack> items, List<FluidStack> fluids) {
if (items == null || items.isEmpty()) items = Collections.emptyList();
if (fluids == null || fluids.isEmpty()) fluids = Collections.emptyList();
return this.recipeMap.findRecipe(voltage, items, fluids, Integer.MAX_VALUE, true);
return this.recipeMap.findRecipe(voltage, items, fluids, true);
}

public boolean removeByInput(long voltage, List<ItemStack> items, List<FluidStack> fluids) {
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/gregtech/api/recipes/RecipeMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public void setupRecipes() {
public void findRecipe() {
MatcherAssert.assertThat(map.getRecipeList().size(), is(3));

Recipe r = map.findRecipe(1, Collections.singletonList(new ItemStack(Blocks.COBBLESTONE)), Collections.singletonList(null), 0);
Recipe r = map.findRecipe(1, Collections.singletonList(new ItemStack(Blocks.COBBLESTONE)), Collections.singletonList(null));
MatcherAssert.assertThat(r, notNullValue());

// This test is failing for me locally -dan
Recipe r2 = map.findRecipe(1, Collections.singletonList(new ItemStack(Blocks.STONE)), Collections.singletonList(new FluidStack(FluidRegistry.WATER, 1)), 0);
Recipe r2 = map.findRecipe(1, Collections.singletonList(new ItemStack(Blocks.STONE)), Collections.singletonList(new FluidStack(FluidRegistry.WATER, 1)));
MatcherAssert.assertThat(r2, notNullValue());
}

Expand All @@ -101,8 +101,8 @@ public void findRecipeFluidOnly() {
Arrays.asList(
Epichlorohydrin.getFluid(144),
Naphtha.getFluid(3000),
NitrogenDioxide.getFluid(1000)),
64000);
NitrogenDioxide.getFluid(1000))
);
MatcherAssert.assertThat(r, notNullValue());
}

Expand All @@ -113,17 +113,17 @@ public void removeRecipe() {
Arrays.asList(
Epichlorohydrin.getFluid(144),
Naphtha.getFluid(3000),
NitrogenDioxide.getFluid(1000)),
64000);
NitrogenDioxide.getFluid(1000))
);
MatcherAssert.assertThat(r, notNullValue());
assert map.removeRecipe(r);
MatcherAssert.assertThat(map.findRecipe(30,
Collections.singletonList(ItemStack.EMPTY),
Arrays.asList(
Epichlorohydrin.getFluid(144),
Naphtha.getFluid(3000),
NitrogenDioxide.getFluid(1000)),
64000), nullValue());
NitrogenDioxide.getFluid(1000))
), nullValue());
MatcherAssert.assertThat(map.getRecipeList().size(), is(2));
}

Expand Down

0 comments on commit 46fe29d

Please sign in to comment.