Skip to content

Commit c96ae44

Browse files
authored
Rework representative recipes and category interactions (GregTechCEu#2525)
1 parent 4a6eef5 commit c96ae44

File tree

16 files changed

+75
-42
lines changed

16 files changed

+75
-42
lines changed

gradle/scripts/moddevgradle.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ neoForge {
7979

8080
data {
8181
data()
82-
sourceSet = sourceSets.main
82+
sourceSet = sourceSets.extra
8383
ideName = "Data Generation"
8484

8585
gameDirectory.set(file('run/data'))

src/generated/resources/assets/gtceu/lang/en_ud.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,9 @@
22992299
"gtceu.fluid_solidifier": "ɹǝıɟıpıןoS pınןℲ",
23002300
"gtceu.forge_hammer": "ɹǝɯɯɐH ǝbɹoℲ",
23012301
"gtceu.forming_press": "ssǝɹԀ buıɯɹoℲ",
2302+
"gtceu.forming_press.naming.named": "ɯǝʇI pǝɯɐNo§",
2303+
"gtceu.forming_press.naming.press": "ssǝɹԀ pǝɯɐNo§",
2304+
"gtceu.forming_press.naming.to_name": "ǝɯɐN oʇ ɯǝʇIo§",
23022305
"gtceu.fusion_reactor": "ɹoʇɔɐǝᴚ uoısnℲ",
23032306
"gtceu.gas_collector": "ɹoʇɔǝןןoƆ sɐ⅁",
23042307
"gtceu.gas_turbine": "ǝuıqɹn⟘ sɐ⅁",
@@ -5063,6 +5066,7 @@
50635066
"material.gtceu.nether_air": "ɹıⱯ ɹǝɥʇǝN",
50645067
"material.gtceu.nether_quartz": "zʇɹɐnὉ ɹǝɥʇǝN",
50655068
"material.gtceu.nether_star": "ɹɐʇS ɹǝɥʇǝN",
5069+
"material.gtceu.netherite": "ǝʇıɹǝɥʇǝN",
50665070
"material.gtceu.netherrack": "ʞɔɐɹɹǝɥʇǝN",
50675071
"material.gtceu.neutronium": "ɯnıuoɹʇnǝN",
50685072
"material.gtceu.nichrome": "ǝɯoɹɥɔıN",

src/generated/resources/assets/gtceu/lang/en_us.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,9 @@
22992299
"gtceu.fluid_solidifier": "Fluid Solidifier",
23002300
"gtceu.forge_hammer": "Forge Hammer",
23012301
"gtceu.forming_press": "Forming Press",
2302+
"gtceu.forming_press.naming.named": "§oNamed Item",
2303+
"gtceu.forming_press.naming.press": "§oNamed Press",
2304+
"gtceu.forming_press.naming.to_name": "§oItem to Name",
23022305
"gtceu.fusion_reactor": "Fusion Reactor",
23032306
"gtceu.gas_collector": "Gas Collector",
23042307
"gtceu.gas_turbine": "Gas Turbine",
@@ -5063,6 +5066,7 @@
50635066
"material.gtceu.nether_air": "Nether Air",
50645067
"material.gtceu.nether_quartz": "Nether Quartz",
50655068
"material.gtceu.nether_star": "Nether Star",
5069+
"material.gtceu.netherite": "Netherite",
50665070
"material.gtceu.netherrack": "Netherrack",
50675071
"material.gtceu.neutronium": "Neutronium",
50685072
"material.gtceu.nichrome": "Nichrome",

src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipe.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public GTRecipe(GTRecipeType recipeType,
122122
this.duration = duration;
123123
this.isFuel = isFuel;
124124
this.recipeCategory = (recipeCategory != GTRecipeCategory.DEFAULT) ? recipeCategory : recipeType.getCategory();
125-
if (id != null) this.recipeType.addToCategoryMap(this.recipeCategory, this);
126125
}
127126

128127
public Map<RecipeCapability<?>, List<Content>> copyContents(Map<RecipeCapability<?>, List<Content>> contents,

src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeSerializer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ public GTRecipe fromNetwork(@NotNull ResourceLocation id, @NotNull FriendlyByteB
149149
inputChanceLogics, outputChanceLogics, tickInputChanceLogics, tickOutputChanceLogics,
150150
conditions, ingredientActions, data, duration, isFuel, category);
151151

152+
recipe.recipeCategory.addRecipe(recipe);
153+
152154
// a little special piece of code for loading all the research entries into the recipe type's list on the
153155
// client.
154156
ResearchCondition researchCondition = conditions.stream().filter(ResearchCondition.class::isInstance).findAny()

src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,14 @@ public GTRecipe toGTrecipe(ResourceLocation id, Recipe<?> recipe) {
331331
return GTRecipeSerializer.SERIALIZER.fromJson(id, builder.build().serializeRecipe());
332332
}
333333

334-
public @NotNull List<GTRecipe> getRepresentativeRecipes() {
335-
List<GTRecipe> recipes = new ArrayList<>();
334+
public void buildRepresentativeRecipes() {
336335
for (ICustomRecipeLogic logic : customRecipeLogicRunners) {
337-
List<GTRecipe> logicRecipes = logic.getRepresentativeRecipes();
338-
if (logicRecipes != null && !logicRecipes.isEmpty()) {
339-
recipes.addAll(logicRecipes);
340-
}
336+
logic.buildRepresentativeRecipes();
341337
}
342-
return recipes;
338+
}
339+
340+
public void addToMainCategory(GTRecipe recipe) {
341+
addToCategoryMap(category, recipe);
343342
}
344343

345344
public void addToCategoryMap(GTRecipeCategory category, GTRecipe recipe) {
@@ -357,19 +356,17 @@ public Set<GTRecipe> getRecipesInCategory(GTRecipeCategory category) {
357356
public interface ICustomRecipeLogic {
358357

359358
/**
360-
* @return A custom recipe to run given the current Scanner's inputs. Will be called only if a registered
359+
* @return A custom recipe to run given the current holder's inputs. Will be called only if a registered
361360
* recipe is not found to run. Return null if no recipe should be run by your logic.
362361
*/
363362
@Nullable
364363
GTRecipe createCustomRecipe(IRecipeCapabilityHolder holder);
365364

366365
/**
367-
* @return A list of Recipes that are never registered, but are added to JEI to demonstrate the custom logic.
368-
* Not required, can return empty or null to not add any.
366+
* Build all representative recipes in this method, then add them to the appropriate recipe category.
367+
* These are added to XEI to demonstrate the custom logic.
368+
* Not required, can NOOP if unneeded.
369369
*/
370-
@Nullable
371-
default List<GTRecipe> getRepresentativeRecipes() {
372-
return null;
373-
}
370+
default void buildRepresentativeRecipes() {}
374371
}
375372
}

src/main/java/com/gregtechceu/gtceu/api/recipe/category/GTRecipeCategory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.gregtechceu.gtceu.api.recipe.category;
22

33
import com.gregtechceu.gtceu.GTCEu;
4+
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
45
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
56
import com.gregtechceu.gtceu.api.registry.GTRegistries;
67
import com.gregtechceu.gtceu.common.data.GTRecipeTypes;
@@ -64,6 +65,10 @@ public IGuiTexture getIcon() {
6465
return icon;
6566
}
6667

68+
public void addRecipe(GTRecipe recipe) {
69+
recipeType.addToCategoryMap(this, recipe);
70+
}
71+
6772
@Override
6873
public boolean equals(Object obj) {
6974
if (this == obj) return true;

src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/GTRecipeLookup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,11 @@ public boolean addRecipe(GTRecipe recipe) {
469469
if (recipe.getType() == GTRecipeTypes.COMBUSTION_GENERATOR_FUELS) {
470470
Content content = recipe.getInputContents(FluidRecipeCapability.CAP).get(0);
471471
FluidIngredient fluid = FluidRecipeCapability.CAP.of(content.content);
472-
PowerlessJetpack.FUELS.put(fluid, recipe.duration);
472+
PowerlessJetpack.FUELS.putIfAbsent(fluid, recipe.duration);
473473
}
474474
List<List<AbstractMapIngredient>> items = fromRecipe(recipe);
475475
if (recurseIngredientTreeAdd(recipe, items, lookup, 0, 0)) {
476-
recipeType.addToCategoryMap(recipe.recipeCategory, recipe);
476+
recipe.recipeCategory.addRecipe(recipe);
477477
return true;
478478
}
479479
return false;

src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
1515
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
1616
import com.gregtechceu.gtceu.api.recipe.RecipeCondition;
17+
import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory;
1718
import com.gregtechceu.gtceu.integration.emi.recipe.GTRecipeEMICategory;
1819
import com.gregtechceu.gtceu.integration.jei.recipe.GTRecipeJEICategory;
1920
import com.gregtechceu.gtceu.integration.rei.recipe.GTRecipeREICategory;
@@ -246,12 +247,14 @@ public IEditableUI<WidgetGroup, RecipeHolder> createEditableUITemplate(final boo
246247
if (LDLib.isReiLoaded()) {
247248
ViewSearchBuilder.builder().addCategories(
248249
recipeType.getCategories().stream()
250+
.filter(GTRecipeCategory::isXEIVisible)
249251
.map(GTRecipeREICategory::machineCategory)
250252
.collect(Collectors.toList()))
251253
.open();
252254
} else if (LDLib.isJeiLoaded()) {
253255
JEIPlugin.jeiRuntime.getRecipesGui().showTypes(
254256
recipeType.getCategories().stream()
257+
.filter(GTRecipeCategory::isXEIVisible)
255258
.map(GTRecipeJEICategory::machineType)
256259
.collect(Collectors.toList()));
257260
} else if (LDLib.isEmiLoaded()) {

src/main/java/com/gregtechceu/gtceu/common/machine/trait/customlogic/FormingPressLogic.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import com.gregtechceu.gtceu.utils.GTStringUtils;
1313

1414
import net.minecraft.nbt.Tag;
15+
import net.minecraft.network.chat.Component;
1516
import net.minecraft.world.item.ItemStack;
17+
import net.minecraft.world.item.Items;
1618

1719
import org.jetbrains.annotations.Nullable;
1820

@@ -79,4 +81,22 @@ public class FormingPressLogic implements GTRecipeType.ICustomRecipeLogic {
7981
}
8082
return null;
8183
}
84+
85+
@Override
86+
public void buildRepresentativeRecipes() {
87+
ItemStack press = GTItems.SHAPE_MOLD_NAME.asStack();
88+
press.setHoverName(Component.translatable("gtceu.forming_press.naming.press"));
89+
ItemStack toName = new ItemStack(Items.NAME_TAG);
90+
toName.setHoverName(Component.translatable("gtceu.forming_press.naming.to_name"));
91+
ItemStack named = new ItemStack(Items.NAME_TAG);
92+
named.setHoverName(Component.translatable("gtceu.forming_press.naming.named"));
93+
var recipe = GTRecipeTypes.FORMING_PRESS_RECIPES.recipeBuilder("copy")
94+
.notConsumable(press)
95+
.inputItems(toName)
96+
.outputItems(named)
97+
.duration(40)
98+
.EUt(4)
99+
.buildRawRecipe();
100+
GTRecipeTypes.FORMING_PRESS_RECIPES.addToMainCategory(recipe);
101+
}
82102
}

0 commit comments

Comments
 (0)