Skip to content

Commit 80f389d

Browse files
authored
Rearrange GT JEI categories (GregTechCEu#2797)
1 parent b742f3f commit 80f389d

17 files changed

+160
-93
lines changed

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

Lines changed: 9 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public class RecipeMap<R extends RecipeBuilder<R>> {
106106
private int maxFluidInputs;
107107
private int maxFluidOutputs;
108108

109+
private final GTRecipeCategory primaryRecipeCategory;
110+
109111
/**
110112
* @deprecated {@link RecipeMapUI#isJEIVisible()}
111113
*/
@@ -128,80 +130,6 @@ public class RecipeMap<R extends RecipeBuilder<R>> {
128130
protected @Nullable SoundEvent sound;
129131
private @Nullable RecipeMap<?> smallRecipeMap;
130132

131-
/**
132-
* Create and register new instance of RecipeMap with specified properties. All
133-
* maximum I/O size for item and fluids will be able to be modified.
134-
*
135-
* @param unlocalizedName the unlocalized name for the RecipeMap
136-
* @param maxInputs the maximum item inputs
137-
* @param maxOutputs the maximum item outputs
138-
* @param maxFluidInputs the maximum fluid inputs
139-
* @param maxFluidOutputs the maximum fluid outputs
140-
* @param defaultRecipeBuilder the default RecipeBuilder for the RecipeMap
141-
* @param isHidden if the RecipeMap should have a category in JEI
142-
*
143-
* @deprecated {@link RecipeMap#RecipeMap(String, R, RecipeMapUIFunction, int, int, int, int)}
144-
*/
145-
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
146-
@Deprecated
147-
public RecipeMap(@NotNull String unlocalizedName,
148-
int maxInputs, int maxOutputs, int maxFluidInputs, int maxFluidOutputs,
149-
@NotNull R defaultRecipeBuilder,
150-
boolean isHidden) {
151-
this(unlocalizedName,
152-
maxInputs, true, maxOutputs, true,
153-
maxFluidInputs, true, maxFluidOutputs, true,
154-
defaultRecipeBuilder, isHidden);
155-
}
156-
157-
/**
158-
* Create and register new instance of RecipeMap with specified properties.
159-
*
160-
* @param unlocalizedName the unlocalized name for the RecipeMap
161-
* @param maxInputs the maximum item inputs
162-
* @param modifyItemInputs if modification of the maximum item input is permitted
163-
* @param maxOutputs the maximum item outputs
164-
* @param modifyItemOutputs if modification of the maximum item output is permitted
165-
* @param maxFluidInputs the maximum fluid inputs
166-
* @param modifyFluidInputs if modification of the maximum fluid input is permitted
167-
* @param maxFluidOutputs the maximum fluid outputs
168-
* @param modifyFluidOutputs if modification of the maximum fluid output is permitted
169-
* @param defaultRecipeBuilder the default RecipeBuilder for the RecipeMap
170-
* @param isHidden if the RecipeMap should have a category in JEI
171-
*
172-
* @deprecated {@link RecipeMap#RecipeMap(String, R, RecipeMapUIFunction, int, int, int, int)}
173-
*/
174-
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
175-
@Deprecated
176-
public RecipeMap(@NotNull String unlocalizedName,
177-
int maxInputs, boolean modifyItemInputs,
178-
int maxOutputs, boolean modifyItemOutputs,
179-
int maxFluidInputs, boolean modifyFluidInputs,
180-
int maxFluidOutputs, boolean modifyFluidOutputs,
181-
@NotNull R defaultRecipeBuilder,
182-
boolean isHidden) {
183-
this.unlocalizedName = unlocalizedName;
184-
185-
this.maxInputs = maxInputs;
186-
this.maxFluidInputs = maxFluidInputs;
187-
this.maxOutputs = maxOutputs;
188-
this.maxFluidOutputs = maxFluidOutputs;
189-
190-
defaultRecipeBuilder.setRecipeMap(this);
191-
defaultRecipeBuilder
192-
.category(GTRecipeCategory.create(GTValues.MODID, unlocalizedName, getTranslationKey(), this));
193-
this.recipeBuilderSample = defaultRecipeBuilder;
194-
195-
this.recipeMapUI = new RecipeMapUI<>(this, modifyItemInputs, modifyItemOutputs, modifyFluidInputs,
196-
modifyFluidOutputs, false);
197-
this.recipeMapUI.setJEIVisible(!isHidden);
198-
199-
RECIPE_MAP_REGISTRY.put(unlocalizedName, this);
200-
201-
this.grsVirtualizedRecipeMap = GregTechAPI.moduleManager.isModuleEnabled(GregTechModules.MODULE_GRS) ?
202-
new VirtualizedRecipeMap(this) : null;
203-
}
204-
205133
/**
206134
* Create and register new instance of RecipeMap with specified properties.
207135
*
@@ -223,10 +151,11 @@ public RecipeMap(@NotNull String unlocalizedName, @NotNull R defaultRecipeBuilde
223151
this.maxFluidInputs = maxFluidInputs;
224152
this.maxOutputs = maxOutputs;
225153
this.maxFluidOutputs = maxFluidOutputs;
154+
this.primaryRecipeCategory = GTRecipeCategory.create(GTValues.MODID, unlocalizedName, getTranslationKey(),
155+
this);
226156

227157
defaultRecipeBuilder.setRecipeMap(this);
228-
defaultRecipeBuilder
229-
.category(GTRecipeCategory.create(GTValues.MODID, unlocalizedName, getTranslationKey(), this));
158+
defaultRecipeBuilder.category(primaryRecipeCategory);
230159
this.recipeBuilderSample = defaultRecipeBuilder;
231160
RECIPE_MAP_REGISTRY.put(unlocalizedName, this);
232161

@@ -1514,6 +1443,10 @@ public void setRecipeMapUI(@NotNull RecipeMapUI<?> recipeMapUI) {
15141443
this.recipeMapUI = recipeMapUI;
15151444
}
15161445

1446+
public @NotNull GTRecipeCategory getPrimaryRecipeCategory() {
1447+
return primaryRecipeCategory;
1448+
}
1449+
15171450
@Override
15181451
@ZenMethod
15191452
public String toString() {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class RecipeMapBuilder<B extends RecipeBuilder<B>> {
4949

5050
private @Nullable Map<ResourceLocation, RecipeBuildAction<B>> buildActions;
5151

52+
private boolean sortToBack;
53+
5254
/**
5355
* @param unlocalizedName the name of the recipemap
5456
* @param defaultRecipeBuilder the default recipe builder of the recipemap
@@ -282,6 +284,18 @@ public RecipeMapBuilder(@NotNull String unlocalizedName, @NotNull B defaultRecip
282284
return this;
283285
}
284286

287+
/**
288+
* Have the primary {@link gregtech.api.recipes.category.GTRecipeCategory} for the RecipeMap be sorted to the end
289+
* of the JEI recipe category list.
290+
*
291+
* @param sortToBack if it should be sorted to the back
292+
* @return this
293+
*/
294+
public @NotNull RecipeMapBuilder<B> jeiSortToBack(boolean sortToBack) {
295+
this.sortToBack = sortToBack;
296+
return this;
297+
}
298+
285299
/**
286300
* <strong>Do not call this twice. RecipeMapBuilders are not re-usable.</strong>
287301
*
@@ -297,6 +311,7 @@ public RecipeMapBuilder(@NotNull String unlocalizedName, @NotNull B defaultRecip
297311
if (buildActions != null) {
298312
recipeMap.onRecipeBuild(buildActions);
299313
}
314+
recipeMap.getPrimaryRecipeCategory().jeiSortToBack(sortToBack);
300315
return recipeMap;
301316
}
302317
}

src/main/java/gregtech/api/recipes/category/GTRecipeCategory.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
66
import org.jetbrains.annotations.NotNull;
77
import org.jetbrains.annotations.Nullable;
8+
import org.jetbrains.annotations.UnmodifiableView;
89

10+
import java.util.Collection;
11+
import java.util.Collections;
912
import java.util.Map;
1013

1114
public final class GTRecipeCategory {
@@ -18,6 +21,7 @@ public final class GTRecipeCategory {
1821
private final String translationKey;
1922
private final RecipeMap<?> recipeMap;
2023
private Object icon;
24+
private boolean sortToBack;
2125

2226
/**
2327
* Create a GTRecipeCategory
@@ -44,11 +48,18 @@ public static GTRecipeCategory getByName(@NotNull String categoryName) {
4448
return categories.get(categoryName);
4549
}
4650

51+
/**
52+
* @return all of the GTRecipeCategory instances
53+
*/
54+
public static @NotNull @UnmodifiableView Collection<GTRecipeCategory> getCategories() {
55+
return Collections.unmodifiableCollection(categories.values());
56+
}
57+
4758
private GTRecipeCategory(@NotNull String modid, @NotNull String name, @NotNull String translationKey,
4859
@NotNull RecipeMap<?> recipeMap) {
4960
this.modid = modid;
5061
this.name = name;
51-
this.uniqueID = modid + ':' + this.name;
62+
this.uniqueID = modid + '.' + this.name;
5263
this.translationKey = translationKey;
5364
this.recipeMap = recipeMap;
5465
}
@@ -85,7 +96,7 @@ public RecipeMap<?> getRecipeMap() {
8596
* @param icon the icon to use as a JEI category
8697
* @return this
8798
*/
88-
public GTRecipeCategory jeiIcon(@Nullable Object icon) {
99+
public @NotNull GTRecipeCategory jeiIcon(@Nullable Object icon) {
89100
this.icon = icon;
90101
return this;
91102
}
@@ -95,6 +106,19 @@ public Object getJEIIcon() {
95106
return this.icon;
96107
}
97108

109+
/**
110+
* @param sortToBack if the category should be at the end of the JEI category list
111+
* @return this
112+
*/
113+
public @NotNull GTRecipeCategory jeiSortToBack(boolean sortToBack) {
114+
this.sortToBack = sortToBack;
115+
return this;
116+
}
117+
118+
public boolean shouldSortToBackJEI() {
119+
return sortToBack;
120+
}
121+
98122
@Override
99123
public boolean equals(Object o) {
100124
if (this == o) return true;

src/main/java/gregtech/api/recipes/category/RecipeCategories.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ public final class RecipeCategories {
1010
"arc_furnace_recycling",
1111
"gregtech.recipe.category.arc_furnace_recycling",
1212
RecipeMaps.ARC_FURNACE_RECIPES)
13-
.jeiIcon(GuiTextures.ARC_FURNACE_RECYLCING_CATEGORY);
13+
.jeiIcon(GuiTextures.ARC_FURNACE_RECYLCING_CATEGORY)
14+
.jeiSortToBack(true);
1415

1516
public static final GTRecipeCategory MACERATOR_RECYCLING = GTRecipeCategory.create(GTValues.MODID,
1617
"macerator_recycling",
1718
"gregtech.recipe.category.macerator_recycling",
1819
RecipeMaps.MACERATOR_RECIPES)
19-
.jeiIcon(GuiTextures.MACERATOR_RECYLCING_CATEGORY);
20+
.jeiIcon(GuiTextures.MACERATOR_RECYLCING_CATEGORY)
21+
.jeiSortToBack(true);
2022

2123
public static final GTRecipeCategory EXTRACTOR_RECYCLING = GTRecipeCategory.create(GTValues.MODID,
2224
"extractor_recycling",
2325
"gregtech.recipe.category.extractor_recycling",
2426
RecipeMaps.EXTRACTOR_RECIPES)
25-
.jeiIcon(GuiTextures.EXTRACTOR_RECYLCING_CATEGORY);
27+
.jeiIcon(GuiTextures.EXTRACTOR_RECYLCING_CATEGORY)
28+
.jeiSortToBack(true);
2629

2730
private RecipeCategories() {}
2831
}

src/main/java/gregtech/api/recipes/machines/RecipeMapResearchStation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ public RecipeMapResearchStation(@NotNull String unlocalizedName, @NotNull R defa
1616
@NotNull RecipeMapUIFunction recipeMapUI) {
1717
super(unlocalizedName, defaultRecipeBuilder, recipeMapUI, 2, 1, 0, 0);
1818
setSound(GTValues.FOOLS.get() ? GTSoundEvents.SCIENCE : GTSoundEvents.COMPUTATION);
19+
getPrimaryRecipeCategory().jeiSortToBack(true);
1920
}
2021
}

src/main/java/gregtech/api/recipes/machines/RecipeMapScanner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public RecipeMapScanner(@NotNull String unlocalizedName, @NotNull SimpleRecipeBu
2525
@NotNull RecipeMapUIFunction recipeMapUI) {
2626
super(unlocalizedName, defaultRecipeBuilder, recipeMapUI, 2, 1, 1, 0);
2727
setSound(GTSoundEvents.ELECTROLYZER);
28+
getPrimaryRecipeCategory().jeiSortToBack(true);
2829
}
2930

3031
@Override

src/main/java/gregtech/common/ConfigHolder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ public static class ClientOptions {
465465
"Default: true" })
466466
public boolean enableFancyChestRender = true;
467467

468+
@Config.Comment({ "Whether to prefer the Material Tree over other categories in JEI", "Default: false" })
469+
public boolean preferMaterialTreeInJEI = false;
470+
468471
public static class GuiConfig {
469472

470473
@Config.Comment({ "The scrolling speed of widgets", "Default: 13" })

src/main/java/gregtech/integration/jei/JustEnoughItemsModule.java

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import gregtech.api.worldgen.config.BedrockFluidDepositDefinition;
2828
import gregtech.api.worldgen.config.OreDepositDefinition;
2929
import gregtech.api.worldgen.config.WorldGenRegistry;
30+
import gregtech.common.ConfigHolder;
3031
import gregtech.common.blocks.MetaBlocks;
3132
import gregtech.common.items.MetaItems;
3233
import gregtech.common.items.ToolItems;
@@ -70,16 +71,20 @@
7071
import mezz.jei.api.JEIPlugin;
7172
import mezz.jei.api.ingredients.IIngredientRegistry;
7273
import mezz.jei.api.ingredients.VanillaTypes;
74+
import mezz.jei.api.recipe.IRecipeCategory;
7375
import mezz.jei.api.recipe.IRecipeCategoryRegistration;
7476
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
7577
import mezz.jei.config.Constants;
7678
import mezz.jei.input.IShowsRecipeFocuses;
7779
import mezz.jei.input.InputHandler;
80+
import org.jetbrains.annotations.ApiStatus;
7881
import org.jetbrains.annotations.NotNull;
7982

8083
import java.lang.reflect.Field;
8184
import java.util.ArrayList;
8285
import java.util.Collection;
86+
import java.util.Collections;
87+
import java.util.Comparator;
8388
import java.util.List;
8489
import java.util.Map;
8590
import java.util.stream.Collectors;
@@ -156,7 +161,7 @@ public void register(IModRegistry registry) {
156161
ModularUIGuiHandler modularUIGuiHandler = new ModularUIGuiHandler(jeiHelpers.recipeTransferHandlerHelper());
157162
modularUIGuiHandler.blacklistCategory(
158163
IntCircuitCategory.UID,
159-
GTValues.MODID + ":material_tree",
164+
MaterialTreeCategory.UID,
160165
VanillaRecipeCategoryUid.INFORMATION,
161166
VanillaRecipeCategoryUid.FUEL);
162167
registry.getRecipeTransferRegistry().addRecipeTransferHandler(modularUIGuiHandler,
@@ -255,8 +260,7 @@ public void register(IModRegistry registry) {
255260
}
256261
}
257262

258-
String oreByProductId = GTValues.MODID + ":" + "ore_by_product";
259-
registry.addRecipes(oreByproductList, oreByProductId);
263+
registry.addRecipes(oreByproductList, OreByProductCategory.UID);
260264
MetaTileEntity[][] machineLists = {
261265
MetaTileEntities.MACERATOR,
262266
MetaTileEntities.ORE_WASHER,
@@ -268,11 +272,11 @@ public void register(IModRegistry registry) {
268272
};
269273
for (MetaTileEntity[] machine : machineLists) {
270274
if (machine.length < GTValues.LV + 1 || machine[GTValues.LV] == null) continue;
271-
registry.addRecipeCatalyst(machine[GTValues.LV].getStackForm(), oreByProductId);
275+
registry.addRecipeCatalyst(machine[GTValues.LV].getStackForm(), OreByProductCategory.UID);
272276
}
273277

274278
// Material Tree
275-
registry.addRecipes(materialTreeList, GTValues.MODID + ":" + "material_tree");
279+
registry.addRecipes(materialTreeList, MaterialTreeCategory.UID);
276280

277281
// Ore Veins
278282
List<OreDepositDefinition> oreVeins = WorldGenRegistry.getOreDeposits();
@@ -281,7 +285,7 @@ public void register(IModRegistry registry) {
281285
oreInfoList.add(new GTOreInfo(vein));
282286
}
283287

284-
String oreSpawnID = GTValues.MODID + ":" + "ore_spawn_location";
288+
String oreSpawnID = GTOreCategory.UID;
285289
registry.addRecipes(oreInfoList, oreSpawnID);
286290
registry.addRecipeCatalyst(MetaItems.PROSPECTOR_LV.getStackForm(), oreSpawnID);
287291
registry.addRecipeCatalyst(MetaItems.PROSPECTOR_HV.getStackForm(), oreSpawnID);
@@ -295,7 +299,7 @@ public void register(IModRegistry registry) {
295299
fluidVeinInfos.add(new GTFluidVeinInfo(fluidVein));
296300
}
297301

298-
String fluidVeinSpawnID = GTValues.MODID + ":" + "fluid_spawn_location";
302+
String fluidVeinSpawnID = GTFluidVeinCategory.UID;
299303
registry.addRecipes(fluidVeinInfos, fluidVeinSpawnID);
300304
registry.addRecipeCatalyst(MetaItems.PROSPECTOR_HV.getStackForm(), fluidVeinSpawnID);
301305
registry.addRecipeCatalyst(MetaItems.PROSPECTOR_LUV.getStackForm(), fluidVeinSpawnID);
@@ -379,4 +383,42 @@ private void registerRecipeMapCatalyst(IModRegistry registry, RecipeMap<?> recip
379383
}
380384
}
381385
}
386+
387+
/**
388+
* Comparator to sort certain GT categories to the front or back of the JEI category list.
389+
*
390+
* @return the comparator
391+
*/
392+
@ApiStatus.Internal
393+
public static @NotNull Comparator<IRecipeCategory<?>> getRecipeCategoryComparator() {
394+
List<String> backIds = GTRecipeCategory.getCategories().stream()
395+
.filter(GTRecipeCategory::shouldSortToBackJEI)
396+
.map(GTRecipeCategory::getUniqueID)
397+
.collect(Collectors.toCollection(ArrayList::new));
398+
backIds.add(IntCircuitCategory.UID);
399+
backIds.add(MultiblockInfoCategory.UID);
400+
backIds.add(OreByProductCategory.UID);
401+
backIds.add(GTOreCategory.UID);
402+
backIds.add(GTFluidVeinCategory.UID);
403+
List<String> frontIds;
404+
if (ConfigHolder.client.preferMaterialTreeInJEI) {
405+
frontIds = Collections.singletonList(MaterialTreeCategory.UID);
406+
} else {
407+
frontIds = Collections.emptyList();
408+
}
409+
410+
return Comparator.<IRecipeCategory<?>>comparingInt(category -> {
411+
int index = backIds.indexOf(category.getUid());
412+
if (index >= 0) {
413+
return index;
414+
}
415+
return Integer.MIN_VALUE;
416+
}).thenComparingInt(category -> {
417+
int index = frontIds.indexOf(category.getUid());
418+
if (index >= 0) {
419+
return index;
420+
}
421+
return Integer.MAX_VALUE;
422+
});
423+
}
382424
}

0 commit comments

Comments
 (0)