Skip to content

Commit

Permalink
Add ways to modify ingredients shown on NEI (#3805)
Browse files Browse the repository at this point in the history
Co-authored-by: Maya <10861407+serenibyss@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
3 people authored Jan 14, 2025
1 parent 8786ba5 commit c5b7781
Show file tree
Hide file tree
Showing 18 changed files with 257 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import static gregtech.api.util.GTRecipeBuilder.TICKS;
import static gregtech.api.util.GTRecipeConstants.COIL_HEAT;
import static gregtech.api.util.GTRecipeConstants.NKE_RANGE;
import static gregtech.api.util.GTRecipeConstants.QFT_CATALYST;
import static gregtech.api.util.GTRecipeConstants.QFT_FOCUS_TIER;
import static gregtech.api.util.GTRecipeConstants.UniversalChemical;
import static gregtech.common.items.MetaGeneratedItem01.registerCauldronCleaningFor;
Expand Down Expand Up @@ -94,8 +95,7 @@ public static void RecipeLoad() {
.itemInputs(
naquadahEarth.get(OrePrefixes.dust, 32),
Materials.Sodium.getDust(64),
Materials.Carbon.getDust(1),
GTUtility.copyAmount(0, GenericChem.mSimpleNaquadahCatalyst))
Materials.Carbon.getDust(1))
.itemOutputs(
inertNaquadah.get(OrePrefixes.dust, 1),
Materials.Titanium.getDust(64),
Expand All @@ -107,28 +107,26 @@ public static void RecipeLoad() {
Materials.Oxygen.getGas(100L))
.duration(10 * SECONDS)
.eut(GTValues.VP[10])
.metadata(QFT_CATALYST, GTUtility.copyAmount(0, GenericChem.mSimpleNaquadahCatalyst))
.metadata(QFT_FOCUS_TIER, 2)
.addTo(quantumForceTransformerRecipes);
// Enriched Naquadah (UIV)
GTValues.RA.stdBuilder()
.itemInputs(
enrichedNaquadahEarth.get(OrePrefixes.dust, 32),
Materials.Zinc.getDust(64),
Materials.Carbon.getDust(1),
GTUtility.copyAmount(0, GenericChem.mSimpleNaquadahCatalyst))
Materials.Carbon.getDust(1))
.itemOutputs(inertEnrichedNaquadah.get(OrePrefixes.dust, 1), Materials.Trinium.getDust(64))
.fluidInputs(Materials.SulfuricAcid.getFluid(16000), Materials.Oxygen.getGas(100L))
.fluidOutputs(wasteLiquid.getFluidOrGas(32000))
.duration(10 * SECONDS)
.eut(GTValues.VP[11])
.metadata(QFT_CATALYST, GTUtility.copyAmount(0, GenericChem.mSimpleNaquadahCatalyst))
.metadata(QFT_FOCUS_TIER, 2)
.addTo(quantumForceTransformerRecipes);
// Naquadria (UMV)
GTValues.RA.stdBuilder()
.itemInputs(
naquadriaEarth.get(OrePrefixes.dust, 32),
Materials.Magnesium.getDust(64),
GTUtility.copyAmount(0, GenericChem.mAdvancedNaquadahCatalyst))
.itemInputs(naquadriaEarth.get(OrePrefixes.dust, 32), Materials.Magnesium.getDust(64))
.itemOutputs(
inertNaquadria.get(OrePrefixes.dust, 1),
Materials.Barium.getDust(64),
Expand All @@ -140,6 +138,7 @@ public static void RecipeLoad() {
Materials.Oxygen.getGas(100L))
.duration(5 * SECONDS)
.eut(GTValues.VP[12])
.metadata(QFT_CATALYST, GTUtility.copyAmount(0, GenericChem.mAdvancedNaquadahCatalyst))
.metadata(QFT_FOCUS_TIER, 3)
.addTo(quantumForceTransformerRecipes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,8 +969,8 @@ protected CheckRecipeResult doCheckRecipe() {
}

/**
* Override to perform additional checkRecipe logic. It gets called after CRIBs and before ordinal hatches.
*
* Override to perform additional checkRecipe logic. It gets called after CRIBs and before ordinary hatches.
*
* @param lastResult Last result of checkRecipe. It might contain interesting info about failure, so don't blindly
* overwrite it. Refer to {@link #doCheckRecipe} for how to handle it.
* @return Result of the checkRecipe.
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/gregtech/api/recipe/NEIRecipeProperties.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package gregtech.api.recipe;

import java.util.Comparator;
import java.util.function.Function;
import java.util.function.UnaryOperator;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import com.gtnewhorizons.modularui.api.math.Pos2d;
import com.gtnewhorizons.modularui.api.math.Size;

Expand Down Expand Up @@ -67,6 +71,23 @@ static NEIRecipePropertiesBuilder builder() {
*/
public final boolean renderRealStackSizes;

/**
* Specifies what item inputs get displayed on NEI.
*/
public final Function<GTRecipe, ItemStack[]> itemInputsGetter;
/**
* Specifies what fluid inputs get displayed on NEI.
*/
public final Function<GTRecipe, FluidStack[]> fluidInputsGetter;
/**
* Specifies what item outputs get displayed on NEI.
*/
public final Function<GTRecipe, ItemStack[]> itemOutputsGetter;
/**
* Specifies what fluid outputs get displayed on NEI.
*/
public final Function<GTRecipe, FluidStack[]> fluidOutputsGetter;

/**
* Comparator for NEI recipe sort. {@link GTRecipe#compareTo(GTRecipe)} by default.
*/
Expand All @@ -75,6 +96,8 @@ static NEIRecipePropertiesBuilder builder() {
NEIRecipeProperties(boolean registerNEI, @Nullable UnaryOperator<HandlerInfo.Builder> handlerInfoCreator,
Size recipeBackgroundSize, Pos2d recipeBackgroundOffset, INEISpecialInfoFormatter neiSpecialInfoFormatter,
boolean unificateOutput, boolean useCustomFilter, boolean renderRealStackSizes,
Function<GTRecipe, ItemStack[]> itemInputsGetter, Function<GTRecipe, FluidStack[]> fluidInputsGetter,
Function<GTRecipe, ItemStack[]> itemOutputsGetter, Function<GTRecipe, FluidStack[]> fluidOutputsGetter,
Comparator<GTRecipe> comparator) {
this.registerNEI = registerNEI;
this.handlerInfoCreator = handlerInfoCreator;
Expand All @@ -84,6 +107,10 @@ static NEIRecipePropertiesBuilder builder() {
this.unificateOutput = unificateOutput;
this.useCustomFilter = useCustomFilter;
this.renderRealStackSizes = renderRealStackSizes;
this.itemInputsGetter = itemInputsGetter;
this.fluidInputsGetter = fluidInputsGetter;
this.itemOutputsGetter = itemOutputsGetter;
this.fluidOutputsGetter = fluidOutputsGetter;
this.comparator = comparator;
}
}
33 changes: 33 additions & 0 deletions src/main/java/gregtech/api/recipe/NEIRecipePropertiesBuilder.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package gregtech.api.recipe;

import java.util.Comparator;
import java.util.function.Function;
import java.util.function.UnaryOperator;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import com.gtnewhorizons.modularui.api.math.Pos2d;
import com.gtnewhorizons.modularui.api.math.Size;

Expand Down Expand Up @@ -36,6 +40,11 @@ public final class NEIRecipePropertiesBuilder {
private boolean useCustomFilter;
private boolean renderRealStackSizes = true;

private Function<GTRecipe, ItemStack[]> itemInputsGetter = recipe -> recipe.mInputs;
private Function<GTRecipe, FluidStack[]> fluidInputsGetter = recipe -> recipe.mFluidInputs;
private Function<GTRecipe, ItemStack[]> itemOutputsGetter = recipe -> recipe.mOutputs;
private Function<GTRecipe, FluidStack[]> fluidOutputsGetter = recipe -> recipe.mFluidOutputs;

private Comparator<GTRecipe> comparator = GTRecipe::compareTo;

NEIRecipePropertiesBuilder() {}
Expand All @@ -50,6 +59,10 @@ public NEIRecipeProperties build() {
unificateOutput,
useCustomFilter,
renderRealStackSizes,
itemInputsGetter,
fluidInputsGetter,
itemOutputsGetter,
fluidOutputsGetter,
comparator);
}

Expand Down Expand Up @@ -93,6 +106,26 @@ public NEIRecipePropertiesBuilder disableRenderRealStackSizes() {
return this;
}

public NEIRecipePropertiesBuilder itemInputsGetter(Function<GTRecipe, ItemStack[]> itemInputsGetter) {
this.itemInputsGetter = itemInputsGetter;
return this;
}

public NEIRecipePropertiesBuilder fluidInputsGetter(Function<GTRecipe, FluidStack[]> fluidInputsGetter) {
this.fluidInputsGetter = fluidInputsGetter;
return this;
}

public NEIRecipePropertiesBuilder itemOutputsGetter(Function<GTRecipe, ItemStack[]> itemOutputsGetter) {
this.itemOutputsGetter = itemOutputsGetter;
return this;
}

public NEIRecipePropertiesBuilder fluidOutputsGetter(Function<GTRecipe, FluidStack[]> fluidOutputsGetter) {
this.fluidOutputsGetter = fluidOutputsGetter;
return this;
}

public NEIRecipePropertiesBuilder recipeComparator(Comparator<GTRecipe> comparator) {
this.comparator = comparator;
return this;
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/gregtech/api/recipe/RecipeMapBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import com.gtnewhorizons.modularui.api.drawable.FallbackableUITexture;
import com.gtnewhorizons.modularui.api.drawable.IDrawable;
import com.gtnewhorizons.modularui.api.drawable.UITexture;
Expand Down Expand Up @@ -475,6 +478,38 @@ public RecipeMapBuilder<B> disableRenderRealStackSizes() {
return this;
}

/**
* Allows modifying what item inputs get displayed on NEI, without affecting GTRecipe object on backend.
*/
public RecipeMapBuilder<B> neiItemInputsGetter(Function<GTRecipe, ItemStack[]> itemInputsGetter) {
neiPropertiesBuilder.itemInputsGetter(itemInputsGetter);
return this;
}

/**
* Allows modifying what fluid inputs get displayed on NEI, without affecting GTRecipe object on backend.
*/
public RecipeMapBuilder<B> neiFluidInputsGetter(Function<GTRecipe, FluidStack[]> fluidInputsGetter) {
neiPropertiesBuilder.fluidInputsGetter(fluidInputsGetter);
return this;
}

/**
* Allows modifying what item outputs get displayed on NEI, without affecting GTRecipe object on backend.
*/
public RecipeMapBuilder<B> neiItemOutputsGetter(Function<GTRecipe, ItemStack[]> itemOutputsGetter) {
neiPropertiesBuilder.itemOutputsGetter(itemOutputsGetter);
return this;
}

/**
* Allows modifying what fluid outputs get displayed on NEI, without affecting GTRecipe object on backend.
*/
public RecipeMapBuilder<B> neiFluidOutputsGetter(Function<GTRecipe, FluidStack[]> fluidOutputsGetter) {
neiPropertiesBuilder.fluidOutputsGetter(fluidOutputsGetter);
return this;
}

/**
* Sets custom comparator for NEI recipe sort.
*/
Expand Down
44 changes: 14 additions & 30 deletions src/main/java/gregtech/api/recipe/RecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static gregtech.api.util.GTRecipeConstants.ADDITIVE_AMOUNT;
import static gregtech.api.util.GTRecipeConstants.FUEL_VALUE;
import static gregtech.api.util.GTRecipeConstants.GLASS;
import static gregtech.api.util.GTRecipeConstants.PCB_NANITE_MATERIAL;
import static gregtech.api.util.GTRecipeMapUtil.GTRecipeTemplate;
import static gregtech.api.util.GTRecipeMapUtil.asTemplate;
import static gregtech.api.util.GTRecipeMapUtil.buildOrEmpty;
Expand All @@ -20,6 +21,7 @@
import static gregtech.api.util.GTUtility.multiplyStack;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -1102,18 +1104,23 @@ && isArrayEmptyOrNull(b.getFluidOutputs())
.minInputs(3, 1)
.progressBar(GTUITextures.PROGRESSBAR_ASSEMBLE)
.disableOptimize()
.neiHandlerInfo(builder -> builder.setDisplayStack(ItemList.PCBFactory.get(1)))
.neiItemInputsGetter(recipe -> {
Materials naniteMaterial = recipe.getMetadata(PCB_NANITE_MATERIAL);
if (naniteMaterial == null) {
return recipe.mInputs;
}
List<ItemStack> inputs = new ArrayList<>();
inputs.add(recipe.mInputs[0]);
ItemStack naniteStack = naniteMaterial.getNanite(1);
inputs.add(new ItemStack(naniteStack.getItem(), 0, naniteStack.getItemDamage()));
inputs.addAll(Arrays.asList(Arrays.copyOfRange(recipe.mInputs, 1, recipe.mInputs.length)));
return inputs.toArray(new ItemStack[0]);
})
.neiRecipeComparator(
Comparator
.<GTRecipe, Integer>comparing(recipe -> recipe.getMetadataOrDefault(PCBFactoryTierKey.INSTANCE, 1))
.thenComparing(GTRecipe::compareTo))
.build();
public static final RecipeMap<RecipeMapBackend> pcbFactoryRecipesNoNanites = RecipeMapBuilder
.of("gt.recipe.pcbfactorynonanites")
.maxIO(6, 9, 3, 0)
.minInputs(3, 1)
.disableOptimize()
.build();
public static final RecipeMap<RecipeMapBackend> purificationClarifierRecipes = RecipeMapBuilder
.of("gt.recipe.purificationplantclarifier")
.maxIO(1, 4, 1, 1)
Expand Down Expand Up @@ -1236,28 +1243,5 @@ && isArrayEmptyOrNull(b.getFluidOutputs())
b.copy()
.duration(1 * TICK)
.eut(TierEU.RECIPE_UEV))));
RecipeMaps.pcbFactoryRecipes.addDownstream(IRecipeMap.newRecipeMap(b -> {
b = b.copy();
List<ItemStack> itemInputs = new ArrayList<>();

Materials naniteMaterial = null;
for (int i = 0; i < b.getItemInputsBasic().length; i++) {
ItemStack stack = b.getItemInputBasic(i);
if (stack == null) continue;
ItemData data = GTOreDictUnificator.getAssociation(stack);
if (data != null && data.mPrefix != null && data.mPrefix.equals(OrePrefixes.nanite)) {
naniteMaterial = data.mMaterial.mMaterial;
continue;
}
itemInputs.add(stack);
}

if (naniteMaterial != null) {
b.metadata(GTRecipeConstants.PCB_NANITE_MATERIAL, naniteMaterial);
}
return RecipeMaps.pcbFactoryRecipesNoNanites.doAdd(
b.itemInputs(itemInputs.toArray(new ItemStack[0]))
.hidden());
}));
}
}
13 changes: 0 additions & 13 deletions src/main/java/gregtech/api/util/GTRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import gregtech.api.util.extensions.ArrayExt;
import gregtech.common.tileentities.machines.MTEHatchInputBusME;
import gregtech.common.tileentities.machines.MTEHatchInputME;
import gregtech.nei.GTNEIDefaultHandler;
import ic2.core.Ic2Items;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
Expand Down Expand Up @@ -383,18 +382,6 @@ public ItemStack getOutput(int aIndex) {
return GTUtility.copyOrNull(mOutputs[aIndex]);
}

/**
* Dictates the ItemStacks displayed in the output slots of any NEI page handled by the default GT NEI handler.
* Override to make shown items differ from a GTRecipe's item output array
*
* @see GTNEIDefaultHandler
* @param i Slot index
* @return ItemStack to be displayed in the slot
*/
public ItemStack getRepresentativeOutput(int i) {
return getOutput(i);
}

public int getOutputChance(int aIndex) {
if (mChances == null) return 10000;
if (aIndex < 0 || aIndex >= mChances.length) return 10000;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/util/GTRecipeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public class GTRecipeConstants {
/**
* QFT catalyst meta.
*/
public static final RecipeMetadataKey<Integer> QFT_CATALYST_META = SimpleRecipeMetadataKey
.create(Integer.class, "qft_catalyst_meta");
public static final RecipeMetadataKey<ItemStack> QFT_CATALYST = SimpleRecipeMetadataKey
.create(ItemStack.class, "qft_catalyst");

/**
* Tier of advanced compression (HIP/black hole)
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -4660,11 +4660,6 @@ public static byte convertRatioToRedstone(long used, long max, int threshold, bo
return signal;
}

public static ItemStack getNaniteAsCatalyst(Materials material) {
ItemStack aItem = material.getNanite(1);
return new ItemStack(aItem.getItem(), 0, aItem.getItemDamage());
}

public static Stream<NBTTagCompound> streamCompounds(NBTTagList list) {
if (list == null) return Stream.empty();
return IntStream.range(0, list.tagCount())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack a

@Override
public RecipeMap<?> getRecipeMap() {
return RecipeMaps.pcbFactoryRecipesNoNanites;
return RecipeMaps.pcbFactoryRecipes;
}

@Override
Expand Down
Loading

0 comments on commit c5b7781

Please sign in to comment.