Skip to content

Commit 1faffbc

Browse files
[CR] Duplicate ARL + RecipeMap logic instead of creating overloads
1 parent ad45cec commit 1faffbc

File tree

3 files changed

+26
-48
lines changed

3 files changed

+26
-48
lines changed

src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import java.util.ArrayList;
3636
import java.util.List;
37-
import java.util.function.Predicate;
3837

3938
import static gregtech.api.GTValues.ULV;
4039
import static gregtech.api.recipes.logic.OverclockingLogic.*;
@@ -513,26 +512,12 @@ protected static int getMinTankCapacity(@NotNull IMultipleTankHandler tanks) {
513512
*/
514513
@Nullable
515514
protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs) {
516-
return this.findRecipe(maxVoltage, inputs, fluidInputs, null);
517-
}
518-
519-
/**
520-
* Find a recipe using inputs
521-
*
522-
* @param maxVoltage the maximum voltage the recipe can have
523-
* @param inputs the item inputs used to search for the recipe
524-
* @param fluidInputs the fluid inputs used to search for the recipe
525-
* @param extraPredicate an optional extra predicate to apply when searching
526-
* @return the recipe if found, otherwise null
527-
*/
528-
@Nullable
529-
protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs, Predicate<Recipe> extraPredicate) {
530515
RecipeMap<?> map = getRecipeMap();
531516
if (map == null || !isRecipeMapValid(map)) {
532517
return null;
533518
}
534519

535-
return map.findRecipe(maxVoltage, inputs, fluidInputs, extraPredicate);
520+
return map.findRecipe(maxVoltage, inputs, fluidInputs);
536521
}
537522

538523
/**

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

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,7 @@ protected ValidationResult<Recipe> postValidateRecipe(@NotNull ValidationResult<
507507

508508
@Nullable
509509
public Recipe findRecipe(long voltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs) {
510-
return this.findRecipe(voltage, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs), null);
511-
}
512-
513-
@Nullable
514-
public Recipe findRecipe(long voltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs, Predicate<Recipe> extraPredicate) {
515-
return this.findRecipe(voltage, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs), extraPredicate);
516-
}
517-
518-
@Nullable
519-
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, Predicate<Recipe> extraPredicate) {
520-
return findRecipe(voltage, inputs, fluidInputs, false, extraPredicate);
510+
return this.findRecipe(voltage, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs));
521511
}
522512

523513
/**
@@ -530,7 +520,7 @@ public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack>
530520
*/
531521
@Nullable
532522
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs) {
533-
return findRecipe(voltage, inputs, fluidInputs, false, null);
523+
return findRecipe(voltage, inputs, fluidInputs, false);
534524
}
535525

536526
/**
@@ -545,22 +535,6 @@ public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack>
545535
@Nullable
546536
public Recipe findRecipe(long voltage, final List<ItemStack> inputs, final List<FluidStack> fluidInputs,
547537
boolean exactVoltage) {
548-
return findRecipe(voltage, inputs, fluidInputs, exactVoltage, null);
549-
}
550-
551-
/**
552-
* Finds a Recipe matching the Fluid and/or ItemStack Inputs.
553-
*
554-
* @param voltage Voltage of the Machine or Long.MAX_VALUE if it has no Voltage
555-
* @param inputs the Item Inputs
556-
* @param fluidInputs the Fluid Inputs
557-
* @param exactVoltage should require exact voltage matching on recipe. used by craftweaker
558-
* @param extraPredicate optional extra filter predicate
559-
* @return the Recipe it has found or null for no matching Recipe
560-
*/
561-
@Nullable
562-
public Recipe findRecipe(long voltage, final List<ItemStack> inputs, final List<FluidStack> fluidInputs,
563-
boolean exactVoltage, Predicate<Recipe> extraPredicate) {
564538
final List<ItemStack> items = inputs.stream().filter(s -> !s.isEmpty()).collect(Collectors.toList());
565539
final List<FluidStack> fluids = fluidInputs.stream().filter(f -> f != null && f.amount != 0)
566540
.collect(Collectors.toList());
@@ -574,7 +548,7 @@ public Recipe findRecipe(long voltage, final List<ItemStack> inputs, final List<
574548
// there is not enough voltage to consider the recipe valid
575549
return false;
576550
}
577-
return recipe.matches(false, inputs, fluidInputs) && (extraPredicate == null || extraPredicate.test(recipe));
551+
return recipe.matches(false, inputs, fluidInputs);
578552
});
579553
}
580554

src/main/java/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
import gregtech.api.recipes.Recipe;
1111
import gregtech.api.recipes.RecipeBuilder;
1212

13+
import gregtech.api.recipes.RecipeMap;
14+
15+
import gregtech.api.util.GTUtility;
16+
17+
import net.minecraft.item.ItemStack;
1318
import net.minecraft.util.math.MathHelper;
1419
import net.minecraftforge.fluids.FluidStack;
1520
import net.minecraftforge.fluids.IFluidTank;
@@ -19,6 +24,7 @@
1924
import org.jetbrains.annotations.Nullable;
2025

2126
import java.util.List;
27+
import java.util.stream.Collectors;
2228

2329
public class LargeTurbineWorkableHandler extends MultiblockFuelRecipeLogic {
2430

@@ -82,7 +88,7 @@ private int getParallel(Recipe recipe, double totalHolderEfficiencyCoefficient,
8288
(Math.abs(recipe.getEUt()) * totalHolderEfficiencyCoefficient));
8389
}
8490

85-
private boolean canDoRecipeConsideringParallel(Recipe recipe) {
91+
private boolean canDoRecipeWithParallel(Recipe recipe) {
8692
IRotorHolder rotorHolder = ((MetaTileEntityLargeTurbine) metaTileEntity).getRotorHolder();
8793
if (rotorHolder == null || !rotorHolder.hasRotor())
8894
return false;
@@ -101,13 +107,26 @@ private boolean canDoRecipeConsideringParallel(Recipe recipe) {
101107

102108
@Override
103109
protected boolean checkPreviousRecipe() {
104-
return super.checkPreviousRecipe() && canDoRecipeConsideringParallel(this.previousRecipe);
110+
return super.checkPreviousRecipe() && canDoRecipeWithParallel(this.previousRecipe);
105111
}
106112

107113
@Override
108114
protected @Nullable Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs,
109115
IMultipleTankHandler fluidInputs) {
110-
return super.findRecipe(maxVoltage, inputs, fluidInputs, this::canDoRecipeConsideringParallel);
116+
RecipeMap<?> map = getRecipeMap();
117+
if (map == null || !isRecipeMapValid(map)) {
118+
return null;
119+
}
120+
121+
final List<ItemStack> items = GTUtility.itemHandlerToList(inputs).stream().filter(s -> !s.isEmpty()).collect(
122+
Collectors.toList());
123+
final List<FluidStack> fluids = GTUtility.fluidHandlerToList(fluidInputs).stream().filter(f -> f != null && f.amount != 0)
124+
.collect(Collectors.toList());
125+
126+
return map.find(items, fluids, recipe -> {
127+
if (recipe.getEUt() > maxVoltage) return false;
128+
return recipe.matches(false, inputs, fluidInputs) && this.canDoRecipeWithParallel(recipe);
129+
});
111130
}
112131

113132
@Override

0 commit comments

Comments
 (0)