Skip to content

Commit aa80805

Browse files
committed
Define names for all the jei recipes so that they can be properly bookmarked
1 parent d40defd commit aa80805

17 files changed

+227
-42
lines changed

src/datagen/main/java/mekanism/client/integration/emi/MekanismEmiDefaults.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import mekanism.common.util.EnumUtils;
1919
import net.minecraft.core.HolderLookup;
2020
import net.minecraft.data.PackOutput;
21-
import net.minecraft.resources.ResourceLocation;
2221
import net.minecraft.world.item.Item;
2322
import net.neoforged.neoforge.common.data.ExistingFileHelper;
2423
import net.neoforged.neoforge.registries.DeferredHolder;
@@ -308,8 +307,8 @@ private void addLateGameRecipes() {
308307
addRecipe(basePath + "plutonium_pellet/from_reaction");
309308
addRecipe(basePath + "polonium_pellet/from_reaction");
310309
addRecipe(basePath + "antimatter_pellet/from_gas");
311-
for (ResourceLocation recipe : SPSRecipeViewerRecipe.getSPSRecipes().keySet()) {
312-
addUncheckedRecipe(recipe);
310+
for (SPSRecipeViewerRecipe recipe : SPSRecipeViewerRecipe.getSPSRecipes()) {
311+
addUncheckedRecipe(recipe.id());
313312
}
314313
}
315314
}

src/generators/java/mekanism/generators/client/recipe_viewer/jei/FissionReactorRecipeCategory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import mezz.jei.api.helpers.IGuiHelper;
2424
import mezz.jei.api.recipe.IFocusGroup;
2525
import mezz.jei.api.recipe.RecipeIngredientRole;
26+
import net.minecraft.resources.ResourceLocation;
2627
import org.jetbrains.annotations.NotNull;
28+
import org.jetbrains.annotations.Nullable;
2729

2830
public class FissionReactorRecipeCategory extends BaseRecipeCategory<FissionRecipeViewerRecipe> {
2931

@@ -59,4 +61,10 @@ public void setRecipe(@NotNull IRecipeLayoutBuilder builder, FissionRecipeViewer
5961
initChemical(builder, MekanismJEI.TYPE_GAS, RecipeIngredientRole.OUTPUT, heatedCoolantTank, Collections.singletonList(recipe.outputCoolant()));
6062
initChemical(builder, MekanismJEI.TYPE_GAS, RecipeIngredientRole.OUTPUT, wasteTank, Collections.singletonList(recipe.waste()));
6163
}
64+
65+
@Nullable
66+
@Override
67+
public ResourceLocation getRegistryName(@NotNull FissionRecipeViewerRecipe recipe) {
68+
return recipe.id();
69+
}
6270
}

src/generators/java/mekanism/generators/client/recipe_viewer/recipe/FissionRecipeViewerRecipe.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package mekanism.generators.client.recipe_viewer.recipe;
22

3-
import java.util.HashMap;
4-
import java.util.Map;
3+
import java.util.ArrayList;
4+
import java.util.List;
55
import mekanism.api.MekanismAPI;
66
import mekanism.api.chemical.gas.Gas;
77
import mekanism.api.chemical.gas.GasStack;
88
import mekanism.api.chemical.gas.attribute.GasAttributes.CooledCoolant;
99
import mekanism.api.math.MathUtils;
10-
import mekanism.api.recipes.ingredients.GasStackIngredient;
1110
import mekanism.api.recipes.ingredients.FluidStackIngredient;
11+
import mekanism.api.recipes.ingredients.GasStackIngredient;
1212
import mekanism.api.recipes.ingredients.creator.IngredientCreatorAccess;
1313
import mekanism.client.recipe_viewer.RecipeViewerUtils;
14+
import mekanism.client.recipe_viewer.emi.INamedRVRecipe;
1415
import mekanism.common.registries.MekanismGases;
1516
import mekanism.common.util.HeatUtils;
1617
import mekanism.generators.common.MekanismGenerators;
@@ -20,30 +21,37 @@
2021
import org.jetbrains.annotations.Nullable;
2122

2223
//If null -> coolant is water
23-
public record FissionRecipeViewerRecipe(@Nullable GasStackIngredient inputCoolant, GasStackIngredient fuel, GasStack outputCoolant, GasStack waste) {
24+
public record FissionRecipeViewerRecipe(ResourceLocation id, @Nullable GasStackIngredient inputCoolant, GasStackIngredient fuel, GasStack outputCoolant, GasStack waste)
25+
implements INamedRVRecipe {
2426

2527
public FluidStackIngredient waterInput() {
2628
return IngredientCreatorAccess.fluid().from(FluidTags.WATER, MathUtils.clampToInt(outputCoolant().getAmount()));
2729
}
2830

29-
public static Map<ResourceLocation, FissionRecipeViewerRecipe> getFissionRecipes() {
31+
public static List<FissionRecipeViewerRecipe> getFissionRecipes() {
3032
//Note: The recipes below ignore thermal conductivity and just take enthalpy into account and it rounds the amount of coolant
3133
//TODO: Eventually we may want to try and improve on that but for now this should be fine
32-
Map<ResourceLocation, FissionRecipeViewerRecipe> recipes = new HashMap<>();
34+
List<FissionRecipeViewerRecipe> recipes = new ArrayList<>();
3335
double energyPerFuel = MekanismGeneratorsConfig.generators.energyPerFissionFuel.get().doubleValue();
3436
//Special case water recipe
3537
long coolantAmount = Math.round(energyPerFuel * HeatUtils.getSteamEnergyEfficiency() / HeatUtils.getWaterThermalEnthalpy());
36-
recipes.put(RecipeViewerUtils.synthetic(MekanismGenerators.rl("water"), "fission"), new FissionRecipeViewerRecipe(null, IngredientCreatorAccess.gasStack().from(MekanismGases.FISSILE_FUEL, 1),
37-
MekanismGases.STEAM.getStack(coolantAmount), MekanismGases.NUCLEAR_WASTE.getStack(1)));
38+
recipes.add(new FissionRecipeViewerRecipe(
39+
RecipeViewerUtils.synthetic(MekanismGenerators.rl("water"), "fission"),
40+
null, IngredientCreatorAccess.gasStack().from(MekanismGases.FISSILE_FUEL, 1),
41+
MekanismGases.STEAM.getStack(coolantAmount), MekanismGases.NUCLEAR_WASTE.getStack(1)
42+
));
3843
//Go through all gases and add each coolant
3944
for (Gas gas : MekanismAPI.GAS_REGISTRY) {
4045
CooledCoolant cooledCoolant = gas.get(CooledCoolant.class);
4146
if (cooledCoolant != null) {
4247
//If it is a cooled coolant add a recipe for it
4348
Gas heatedCoolant = cooledCoolant.getHeatedGas();
4449
long amount = Math.round(energyPerFuel / cooledCoolant.getThermalEnthalpy());
45-
recipes.put(RecipeViewerUtils.synthetic(gas.getRegistryName(), "fission", MekanismGenerators.MODID), new FissionRecipeViewerRecipe(IngredientCreatorAccess.gasStack().from(gas, amount),
46-
IngredientCreatorAccess.gasStack().from(MekanismGases.FISSILE_FUEL, 1), heatedCoolant.getStack(amount), MekanismGases.NUCLEAR_WASTE.getStack(1)));
50+
recipes.add(new FissionRecipeViewerRecipe(
51+
RecipeViewerUtils.synthetic(gas.getRegistryName(), "fission", MekanismGenerators.MODID),
52+
IngredientCreatorAccess.gasStack().from(gas, amount), IngredientCreatorAccess.gasStack().from(MekanismGases.FISSILE_FUEL, 1),
53+
heatedCoolant.getStack(amount), MekanismGases.NUCLEAR_WASTE.getStack(1)
54+
));
4755
}
4856
}
4957
return recipes;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package mekanism.client.recipe_viewer.emi;
2+
3+
import net.minecraft.resources.ResourceLocation;
4+
5+
public interface INamedRVRecipe {
6+
7+
ResourceLocation id();
8+
}

src/main/java/mekanism/client/recipe_viewer/emi/MekanismEmi.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ public static <RECIPE> void addCategoryAndRecipes(EmiRegistry registry, IRecipeV
335335
}
336336
}
337337

338+
public static <RECIPE extends INamedRVRecipe> void addCategoryAndRecipes(EmiRegistry registry, IRecipeViewerRecipeType<RECIPE> recipeType,
339+
BasicRecipeCreator<RECIPE> recipeCreator, List<RECIPE> recipes) {
340+
MekanismEmiRecipeCategory category = addCategory(registry, recipeType);
341+
for (RECIPE recipe : recipes) {
342+
registry.addRecipe(recipeCreator.create(category, recipe.id(), recipe));
343+
}
344+
}
345+
338346
private static MekanismEmiRecipeCategory addCategory(EmiRegistry registry, IRecipeViewerRecipeType<?> recipeType) {
339347
MekanismEmiRecipeCategory category = MekanismEmiRecipeCategory.create(recipeType);
340348
registry.addCategory(category);

src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ public IDrawable getIcon() {
208208
return icon;
209209
}
210210

211+
@Nullable
212+
@Override
213+
public abstract ResourceLocation getRegistryName(RECIPE recipe);
214+
211215
protected IProgressInfoHandler getSimpleProgressTimer() {
212216
if (timer == null) {
213217
timer = guiHelper.createTickTimer(SharedConstants.TICKS_PER_SECOND, SharedConstants.TICKS_PER_SECOND, false);

src/main/java/mekanism/client/recipe_viewer/jei/HolderRecipeCategory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22

33
import mekanism.client.recipe_viewer.type.IRecipeViewerRecipeType;
44
import mezz.jei.api.helpers.IGuiHelper;
5+
import net.minecraft.resources.ResourceLocation;
56
import net.minecraft.world.item.crafting.Recipe;
67
import net.minecraft.world.item.crafting.RecipeHolder;
8+
import org.jetbrains.annotations.NotNull;
79

810
public abstract class HolderRecipeCategory<RECIPE extends Recipe<?>> extends BaseRecipeCategory<RecipeHolder<RECIPE>> {
911

1012
protected HolderRecipeCategory(IGuiHelper helper, IRecipeViewerRecipeType<RECIPE> recipeType) {
1113
super(helper, MekanismJEI.holderRecipeType(recipeType), recipeType.getTextComponent(), createIcon(helper, recipeType), recipeType.xOffset(), recipeType.yOffset(), recipeType.width(), recipeType.height());
1214
}
15+
16+
@NotNull
17+
@Override
18+
public ResourceLocation getRegistryName(RecipeHolder<RECIPE> recipe) {
19+
return recipe.id();
20+
}
1321
}

src/main/java/mekanism/client/recipe_viewer/jei/RecipeRegistryHelper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ private RecipeRegistryHelper() {
2525
}
2626

2727
public static void registerCondensentrator(IRecipeRegistration registry) {
28-
List<RotaryRecipe> condensentratorRecipes = new ArrayList<>();
29-
List<RotaryRecipe> decondensentratorRecipes = new ArrayList<>();
28+
List<RecipeHolder<RotaryRecipe>> condensentratorRecipes = new ArrayList<>();
29+
List<RecipeHolder<RotaryRecipe>> decondensentratorRecipes = new ArrayList<>();
3030
for (RecipeHolder<RotaryRecipe> recipeHolder : MekanismRecipeType.ROTARY.getRecipes(null)) {
3131
RotaryRecipe recipe = recipeHolder.value();
3232
if (recipe.hasGasToFluid()) {
33-
condensentratorRecipes.add(recipe);
33+
condensentratorRecipes.add(recipeHolder);
3434
}
3535
if (recipe.hasFluidToGas()) {
36-
decondensentratorRecipes.add(recipe);
36+
decondensentratorRecipes.add(recipeHolder);
3737
}
3838
}
39-
register(registry, RecipeViewerRecipeType.CONDENSENTRATING, condensentratorRecipes);
40-
register(registry, RecipeViewerRecipeType.DECONDENSENTRATING, decondensentratorRecipes);
39+
registry.addRecipes(MekanismJEI.holderRecipeType(RecipeViewerRecipeType.CONDENSENTRATING), condensentratorRecipes);
40+
registry.addRecipes(MekanismJEI.holderRecipeType(RecipeViewerRecipeType.DECONDENSENTRATING), decondensentratorRecipes);
4141
}
4242

4343
public static <RECIPE extends MekanismRecipe<?>> void register(IRecipeRegistration registry, IRecipeViewerRecipeType<RECIPE> recipeType,

src/main/java/mekanism/client/recipe_viewer/jei/machine/BoilerRecipeCategory.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import mezz.jei.api.recipe.IFocusGroup;
2525
import mezz.jei.api.recipe.RecipeIngredientRole;
2626
import net.minecraft.client.gui.GuiGraphics;
27+
import net.minecraft.resources.ResourceLocation;
2728
import org.jetbrains.annotations.NotNull;
2829
import org.jetbrains.annotations.Nullable;
2930

@@ -77,6 +78,12 @@ protected void renderElements(BoilerRecipeViewerRecipe recipe, IRecipeSlotsView
7778
}
7879
}
7980

81+
@Nullable
82+
@Override
83+
public ResourceLocation getRegistryName(@NotNull BoilerRecipeViewerRecipe recipe) {
84+
return recipe.id();
85+
}
86+
8087
@Override
8188
public void setRecipe(@NotNull IRecipeLayoutBuilder builder, BoilerRecipeViewerRecipe recipe, @NotNull IFocusGroup focusGroup) {
8289
initFluid(builder, RecipeIngredientRole.INPUT, waterTank, recipe.water().getRepresentations());

src/main/java/mekanism/client/recipe_viewer/jei/machine/ItemStackToFluidOptionalItemRecipeCategory.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@
1212
import mekanism.client.gui.element.progress.ProgressType;
1313
import mekanism.client.gui.element.slot.GuiSlot;
1414
import mekanism.client.gui.element.slot.SlotType;
15+
import mekanism.client.recipe_viewer.RecipeViewerUtils;
1516
import mekanism.client.recipe_viewer.jei.BaseRecipeCategory;
1617
import mekanism.client.recipe_viewer.type.IRecipeViewerRecipeType;
18+
import mekanism.common.Mekanism;
1719
import mekanism.common.tile.component.config.DataType;
20+
import mekanism.common.util.RegistryUtils;
1821
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
1922
import mezz.jei.api.helpers.IGuiHelper;
2023
import mezz.jei.api.recipe.IFocusGroup;
2124
import mezz.jei.api.recipe.RecipeIngredientRole;
25+
import net.minecraft.resources.ResourceLocation;
2226
import net.minecraft.world.item.ItemStack;
2327
import net.neoforged.neoforge.fluids.FluidStack;
2428
import org.jetbrains.annotations.NotNull;
29+
import org.jetbrains.annotations.Nullable;
2530

2631
public class ItemStackToFluidOptionalItemRecipeCategory extends BaseRecipeCategory<ItemStackToFluidOptionalItemRecipe> {
2732

@@ -56,4 +61,14 @@ public void setRecipe(@NotNull IRecipeLayoutBuilder builder, ItemStackToFluidOpt
5661
.setSlotName(OUTPUT_ITEM);
5762
}
5863
}
64+
65+
@Nullable
66+
@Override
67+
public ResourceLocation getRegistryName(@NotNull ItemStackToFluidOptionalItemRecipe recipe) {
68+
List<@NotNull ItemStack> representations = recipe.getInput().getRepresentations();
69+
if (representations.size() == 1) {
70+
return RecipeViewerUtils.synthetic(RegistryUtils.getName(representations.getFirst().getItem()), "liquification", Mekanism.MODID);
71+
}
72+
return null;
73+
}
5974
}

0 commit comments

Comments
 (0)