Skip to content

Commit

Permalink
Remove findRecipe methods (#3084)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: boubou19 <miisterunknown@gmail.com>
  • Loading branch information
3 people committed Sep 14, 2024
1 parent 69d1113 commit 5c452f3
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ public boolean checkRecipe(ItemStack itemStack) {

if (this.mOutputItems == null) this.mOutputItems = new ItemStack[2];

GTRecipe tRecipe = RecipeMaps.maceratorRecipes
.findRecipe(this.getBaseMetaTileEntity(), false, false, V[1], null, itemStack);
GTRecipe tRecipe = RecipeMaps.maceratorRecipes.findRecipeQuery()
.items(itemStack)
.voltage(V[1])
.find();
if (tRecipe == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,9 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) {
}

if (this.lastRecipe == null || this.lastFail) {
this.lastRecipe = BartWorksRecipeMaps.radioHatchRecipes.findRecipe(
this.getBaseMetaTileEntity(),
false,
Integer.MAX_VALUE - 7,
null,
this.mInventory[0]);
this.lastRecipe = BartWorksRecipeMaps.radioHatchRecipes.findRecipeQuery()
.items(this.mInventory[0])
.find();
if (this.lastRecipe == null) {
this.lastFail = true;
this.lastUsedItem = this.mInventory[0] == null ? null : this.mInventory[0].copy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ protected boolean filtersFluid() {
}
}

GTRecipe tRecipe = GoodGeneratorRecipeMaps.naquadahReactorFuels
.findRecipe(this.getBaseMetaTileEntity(), true, 1 << 30, tFluids.toArray(new FluidStack[0]));
GTRecipe tRecipe = GoodGeneratorRecipeMaps.naquadahReactorFuels.findRecipeQuery()
.fluids(tFluids.toArray(new FluidStack[0]))
.find();
if (tRecipe != null) {
Pair<FluidStack, Integer> excitedInfo = getExcited(tFluids.toArray(new FluidStack[0]), false);
int pall = excitedInfo == null ? 1 : excitedInfo.getValue();
Expand Down
1 change: 0 additions & 1 deletion src/main/java/gregtech/GTMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ public class GTMod implements IGTMod {
public static GTProxy gregtechproxy;
public static final boolean DEBUG = Boolean.getBoolean("gt.debug");

public static int MAX_IC2 = 2147483647;
public static GTAchievements achievements;
@Deprecated
public static final String aTextGeneral = "general";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ public int getFuelValue(ItemStack aStack) {

public long getFuelValue(ItemStack aStack, boolean aLong) {
if (GTUtility.isStackInvalid(aStack) || getRecipeMap() == null) return 0;
GTRecipe tFuel = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack);
GTRecipe tFuel = getRecipeMap().findRecipeQuery()
.items(aStack)
.find();
if (tFuel == null) return 0;

long liters = 10L; // 1000mb/100
Expand All @@ -314,7 +316,9 @@ public long getFuelValue(ItemStack aStack, boolean aLong) {

public ItemStack getEmptyContainer(ItemStack aStack) {
if (GTUtility.isStackInvalid(aStack) || getRecipeMap() == null) return null;
GTRecipe tFuel = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack);
GTRecipe tFuel = getRecipeMap().findRecipeQuery()
.items(aStack)
.find();
if (tFuel != null) return GTUtility.copyOrNull(tFuel.getOutput(0));
return GTUtility.getContainerItem(aStack, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ && getBaseMetaTileEntity().getCoverIDAtSide(getBaseMetaTileEntity().getFrontFaci

@Override
public int checkRecipe() {
GTRecipe tRecipe = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, TierEU.LV, null, getAllInputs());
GTRecipe tRecipe = getRecipeMap().findRecipeQuery()
.items(getAllInputs())
.voltage(TierEU.LV)
.find();
if ((tRecipe != null) && (canOutput(tRecipe.mOutputs))
&& (tRecipe.isRecipeInputEqual(true, null, getAllInputs()))) {
this.mOutputItems[0] = tRecipe.getOutput(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;

import com.gtnewhorizons.modularui.api.drawable.FallbackableUITexture;
Expand Down Expand Up @@ -576,16 +575,15 @@ protected boolean allowPutStackValidated(IGregTechTileEntity aBaseMetaTileEntity
if (this.getFillableStack() == null) return this.getRecipeMap()
.containsInput(aStack);
else return this.getRecipeMap()
.findRecipe(
this.getBaseMetaTileEntity(),
this.mLastRecipe,
true,
true,
V[this.mTier],
new FluidStack[] { this.getFillableStack() },
this.getSpecialSlot(),
appendSelectedCircuit(aStack))
!= null;
.findRecipeQuery()
.items(appendSelectedCircuit(aStack))
.fluids(this.getFillableStack())
.specialSlot(this.getSpecialSlot())
.voltage(V[this.mTier])
.cachedRecipe(this.mLastRecipe)
.dontCheckStackSizes(true)
.notUnificated(true)
.find() != null;
}
case 2 -> {
return ((this.getInputAt(0) != null && this.getInputAt(1) != null)
Expand All @@ -594,17 +592,17 @@ protected boolean allowPutStackValidated(IGregTechTileEntity aBaseMetaTileEntity
: (this.getRecipeMap()
.containsInput(aStack)
&& this.getRecipeMap()
.findRecipe(
this.getBaseMetaTileEntity(),
this.mLastRecipe,
true,
true,
V[this.mTier],
new FluidStack[] { this.getFillableStack() },
this.getSpecialSlot(),
.findRecipeQuery()
.items(
aIndex == this.getInputSlot() ? appendSelectedCircuit(aStack, this.getInputAt(1))
: appendSelectedCircuit(this.getInputAt(0), aStack))
!= null)));
.fluids(this.getFillableStack())
.specialSlot(this.getSpecialSlot())
.voltage(V[this.mTier])
.cachedRecipe(this.mLastRecipe)
.dontCheckStackSizes(true)
.notUnificated(true)
.find() != null)));
}
default -> {
int tID = this.getBaseMetaTileEntity()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/recipe/FindRecipeQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public FindRecipeQuery filter(Predicate<GTRecipe> filter) {

/**
* @param voltage Recipes that exceed this voltage won't match. It will be automatically multiplied by amperage
* of the recipemap.
* of the recipemap. By default, voltage is set to max Integer, meaning no voltage check.
*/
public FindRecipeQuery voltage(long voltage) {
this.voltage = voltage;
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/gregtech/api/recipe/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.jetbrains.annotations.Unmodifiable;

import gregtech.api.interfaces.IRecipeMap;
import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords;
import gregtech.api.util.FieldsAreNonnullByDefault;
import gregtech.api.util.GTRecipe;
import gregtech.api.util.GTRecipeBuilder;
Expand Down Expand Up @@ -207,50 +206,13 @@ public boolean containsInput(@Nullable Fluid aFluid) {
return aFluid != null && backend.containsInput(aFluid);
}

// region find recipe

/**
* @return Entrypoint for fluent API for finding recipe.
*/
public FindRecipeQuery findRecipeQuery() {
return new FindRecipeQuery(this);
}

@Nullable
public GTRecipe findRecipe(@Nullable IHasWorldObjectAndCoords aTileEntity, boolean aNotUnificated, long aVoltage,
@Nullable FluidStack[] aFluids, @Nullable ItemStack... aInputs) {
return findRecipe(aTileEntity, null, aNotUnificated, aVoltage, aFluids, null, aInputs);
}

@Nullable
public GTRecipe findRecipe(@Nullable IHasWorldObjectAndCoords aTileEntity, boolean aNotUnificated,
boolean aDontCheckStackSizes, long aVoltage, @Nullable FluidStack[] aFluids, @Nullable ItemStack... aInputs) {
return findRecipe(aTileEntity, null, aNotUnificated, aDontCheckStackSizes, aVoltage, aFluids, null, aInputs);
}

@Nullable
public GTRecipe findRecipe(@Nullable IHasWorldObjectAndCoords aTileEntity, @Nullable GTRecipe aRecipe,
boolean aNotUnificated, long aVoltage, @Nullable FluidStack[] aFluids, @Nullable ItemStack aSpecialSlot,
@Nullable ItemStack... aInputs) {
return findRecipe(aTileEntity, aRecipe, aNotUnificated, false, aVoltage, aFluids, aSpecialSlot, aInputs);
}

@Nullable
public GTRecipe findRecipe(@Nullable IHasWorldObjectAndCoords aTileEntity, @Nullable GTRecipe aRecipe,
boolean aNotUnificated, boolean aDontCheckStackSizes, long aVoltage, @Nullable FluidStack[] aFluids,
@Nullable ItemStack aSpecialSlot, @Nullable ItemStack... aInputs) {
return findRecipeQuery().items(aInputs != null ? aInputs : new ItemStack[0])
.fluids(aFluids != null ? aFluids : new FluidStack[0])
.specialSlot(aSpecialSlot)
.voltage(aVoltage)
.cachedRecipe(aRecipe)
.notUnificated(aNotUnificated)
.dontCheckStackSizes(aDontCheckStackSizes)
.find();
}

// endregion

@Override
public String toString() {
return "RecipeMap{" + "unlocalizedName='"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ private static GTRecipe tryFindRecipe(@Nonnull RecipeMap<?> recipeMap, NBTTagCom
.map(FluidStack::loadFluidStackFromNBT)
.toArray(FluidStack[]::new);
int eut = tag.getInteger("eut");
GTRecipe found = recipeMap.findRecipe(null, false, GTValues.V[GTUtility.getTier(eut)], fInputs, inputs);
GTRecipe found = recipeMap.findRecipeQuery()
.items(inputs)
.fluids(fInputs)
.voltage(GTValues.V[GTUtility.getTier(eut)])
.find();
int[] chances = tag.getIntArray("chances");
if (chances.length == 0) chances = null;
if (found == null || !GTUtility.equals(inputs, found.mInputs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,11 @@ protected boolean allowPutStackValidated(IGregTechTileEntity aBaseMetaTileEntity
if ((ItemList.Schematic_1by1.isStackEqual(tInput1)) || (ItemList.Schematic_2by2.isStackEqual(tInput1))
|| (ItemList.Schematic_3by3.isStackEqual(tInput1))) {
if (hasValidCache(aStack, aTypeCache, false)) return true;
if (RecipeMaps.packagerRecipes.findRecipe(
getBaseMetaTileEntity(),
true,
GTValues.V[mTier],
null,
GTUtility.copyAmount(64, aStack),
tInput1) != null) {
if (RecipeMaps.packagerRecipes.findRecipeQuery()
.items(GTUtility.copyAmount(64, aStack), tInput1)
.voltage(GTValues.V[mTier])
.notUnificated(true)
.find() != null) {
return true;
}
if (ItemList.Schematic_1by1.isStackEqual(getInputAt(1)) && GTModHandler.getRecipeOutput(aStack) != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import com.gtnewhorizon.structurelib.structure.StructureDefinition;

import gregtech.api.GregTechAPI;
import gregtech.api.enums.GTValues;
import gregtech.api.enums.Materials;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.ITexture;
Expand Down Expand Up @@ -463,8 +462,9 @@ private void doMac(HashSet<Integer>... aTables) {
for (ItemStack aStack : sMidProduct) {
int tID = GTUtility.stackToInt(aStack);
if (checkTypes(tID, aTables)) {
GTRecipe tRecipe = RecipeMaps.maceratorRecipes
.findRecipe(getBaseMetaTileEntity(), false, GTValues.V[15], null, aStack);
GTRecipe tRecipe = RecipeMaps.maceratorRecipes.findRecipeQuery()
.items(aStack)
.find();
if (tRecipe != null) {
tProduct.addAll(getOutputStack(tRecipe, aStack.stackSize));
} else {
Expand All @@ -485,12 +485,10 @@ private void doWash(HashSet<Integer>... aTables) {
for (ItemStack aStack : sMidProduct) {
int tID = GTUtility.stackToInt(aStack);
if (checkTypes(tID, aTables)) {
GTRecipe tRecipe = RecipeMaps.oreWasherRecipes.findRecipe(
getBaseMetaTileEntity(),
false,
GTValues.V[15],
new FluidStack[] { GTModHandler.getDistilledWater(Integer.MAX_VALUE) },
aStack);
GTRecipe tRecipe = RecipeMaps.oreWasherRecipes.findRecipeQuery()
.items(aStack)
.fluids(GTModHandler.getDistilledWater(Integer.MAX_VALUE))
.find();
if (tRecipe != null) {
tProduct.addAll(getOutputStack(tRecipe, aStack.stackSize));
} else {
Expand All @@ -511,8 +509,9 @@ private void doThermal(HashSet<Integer>... aTables) {
for (ItemStack aStack : sMidProduct) {
int tID = GTUtility.stackToInt(aStack);
if (checkTypes(tID, aTables)) {
GTRecipe tRecipe = RecipeMaps.thermalCentrifugeRecipes
.findRecipe(getBaseMetaTileEntity(), false, GTValues.V[15], null, aStack);
GTRecipe tRecipe = RecipeMaps.thermalCentrifugeRecipes.findRecipeQuery()
.items(aStack)
.find();
if (tRecipe != null) {
tProduct.addAll(getOutputStack(tRecipe, aStack.stackSize));
} else {
Expand All @@ -533,8 +532,9 @@ private void doCentrifuge(HashSet<Integer>... aTables) {
for (ItemStack aStack : sMidProduct) {
int tID = GTUtility.stackToInt(aStack);
if (checkTypes(tID, aTables)) {
GTRecipe tRecipe = RecipeMaps.centrifugeRecipes
.findRecipe(getBaseMetaTileEntity(), false, GTValues.V[15], null, aStack);
GTRecipe tRecipe = RecipeMaps.centrifugeRecipes.findRecipeQuery()
.items(aStack)
.find();
if (tRecipe != null) {
tProduct.addAll(getOutputStack(tRecipe, aStack.stackSize));
} else {
Expand All @@ -555,8 +555,9 @@ private void doSift(HashSet<Integer>... aTables) {
for (ItemStack aStack : sMidProduct) {
int tID = GTUtility.stackToInt(aStack);
if (checkTypes(tID, aTables)) {
GTRecipe tRecipe = RecipeMaps.sifterRecipes
.findRecipe(getBaseMetaTileEntity(), false, GTValues.V[15], null, aStack);
GTRecipe tRecipe = RecipeMaps.sifterRecipes.findRecipeQuery()
.items(aStack)
.find();
if (tRecipe != null) {
tProduct.addAll(getOutputStack(tRecipe, aStack.stackSize));
} else {
Expand All @@ -577,12 +578,10 @@ private void doChemWash(HashSet<Integer>... aTables) {
for (ItemStack aStack : sMidProduct) {
int tID = GTUtility.stackToInt(aStack);
if (checkTypes(tID, aTables)) {
GTRecipe tRecipe = RecipeMaps.chemicalBathRecipes.findRecipe(
getBaseMetaTileEntity(),
false,
GTValues.V[15],
getStoredFluids().toArray(new FluidStack[0]),
aStack);
GTRecipe tRecipe = RecipeMaps.chemicalBathRecipes.findRecipeQuery()
.items(aStack)
.fluids(getStoredFluids().toArray(new FluidStack[0]))
.find();
if (tRecipe != null && tRecipe.getRepresentativeFluidInput(0) != null) {
FluidStack tInputFluid = tRecipe.getRepresentativeFluidInput(0)
.copy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,10 @@ private ItemStack[] getOutputByDrops(Collection<ItemStack> oreBlockDrops) {
outputItems.add(multiplyStackSize(currentItem));
return;
}
GTRecipe tRecipe = RecipeMaps.maceratorRecipes
.findRecipe(getBaseMetaTileEntity(), false, voltage, null, currentItem);
GTRecipe tRecipe = RecipeMaps.maceratorRecipes.findRecipeQuery()
.items(currentItem)
.voltage(voltage)
.find();
if (tRecipe == null) {
outputItems.add(currentItem);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ private boolean checkRecipe() {
}
ItemStack[] inputs = new ItemStack[INPUT_SLOTS];
System.arraycopy(mInventory, 0, inputs, 0, INPUT_SLOTS);
GTRecipe recipe = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, 0, null, inputs);
GTRecipe recipe = getRecipeMap().findRecipeQuery()
.items(inputs)
.find();
if (recipe == null) {
this.mOutputItems = null;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ public RecipeMap<?> getRecipeMap() {

@Override
public int checkRecipe() {
GTRecipe tRecipe = getRecipeMap()
.findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, TierEU.LV, null, null, getAllInputs());
GTRecipe tRecipe = getRecipeMap().findRecipeQuery()
.items(getAllInputs())
.voltage(TierEU.LV)
.cachedRecipe(mLastRecipe)
.find();
if (tRecipe == null) return DID_NOT_FIND_RECIPE;
if (tRecipe.mCanBeBuffered) mLastRecipe = tRecipe;
if (!canOutput(tRecipe)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ public RecipeMap<?> getRecipeMap() {

@Override
public int checkRecipe() {
GTRecipe tRecipe = getRecipeMap()
.findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, TierEU.LV, null, null, getAllInputs());
GTRecipe tRecipe = getRecipeMap().findRecipeQuery()
.items(getAllInputs())
.voltage(TierEU.LV)
.cachedRecipe(mLastRecipe)
.find();
if (tRecipe == null) return DID_NOT_FIND_RECIPE;
if (tRecipe.mCanBeBuffered) mLastRecipe = tRecipe;
if (!canOutput(tRecipe)) {
Expand Down
Loading

0 comments on commit 5c452f3

Please sign in to comment.