Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 9 additions & 76 deletions src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public class RecipeMap<R extends RecipeBuilder<R>> {
private int maxFluidInputs;
private int maxFluidOutputs;

private final GTRecipeCategory primaryRecipeCategory;

/**
* @deprecated {@link RecipeMapUI#isJEIVisible()}
*/
Expand All @@ -128,80 +130,6 @@ public class RecipeMap<R extends RecipeBuilder<R>> {
protected @Nullable SoundEvent sound;
private @Nullable RecipeMap<?> smallRecipeMap;

/**
* Create and register new instance of RecipeMap with specified properties. All
* maximum I/O size for item and fluids will be able to be modified.
*
* @param unlocalizedName the unlocalized name for the RecipeMap
* @param maxInputs the maximum item inputs
* @param maxOutputs the maximum item outputs
* @param maxFluidInputs the maximum fluid inputs
* @param maxFluidOutputs the maximum fluid outputs
* @param defaultRecipeBuilder the default RecipeBuilder for the RecipeMap
* @param isHidden if the RecipeMap should have a category in JEI
*
* @deprecated {@link RecipeMap#RecipeMap(String, R, RecipeMapUIFunction, int, int, int, int)}
*/
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
@Deprecated
public RecipeMap(@NotNull String unlocalizedName,
int maxInputs, int maxOutputs, int maxFluidInputs, int maxFluidOutputs,
@NotNull R defaultRecipeBuilder,
boolean isHidden) {
this(unlocalizedName,
maxInputs, true, maxOutputs, true,
maxFluidInputs, true, maxFluidOutputs, true,
defaultRecipeBuilder, isHidden);
}

/**
* Create and register new instance of RecipeMap with specified properties.
*
* @param unlocalizedName the unlocalized name for the RecipeMap
* @param maxInputs the maximum item inputs
* @param modifyItemInputs if modification of the maximum item input is permitted
* @param maxOutputs the maximum item outputs
* @param modifyItemOutputs if modification of the maximum item output is permitted
* @param maxFluidInputs the maximum fluid inputs
* @param modifyFluidInputs if modification of the maximum fluid input is permitted
* @param maxFluidOutputs the maximum fluid outputs
* @param modifyFluidOutputs if modification of the maximum fluid output is permitted
* @param defaultRecipeBuilder the default RecipeBuilder for the RecipeMap
* @param isHidden if the RecipeMap should have a category in JEI
*
* @deprecated {@link RecipeMap#RecipeMap(String, R, RecipeMapUIFunction, int, int, int, int)}
*/
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
@Deprecated
public RecipeMap(@NotNull String unlocalizedName,
int maxInputs, boolean modifyItemInputs,
int maxOutputs, boolean modifyItemOutputs,
int maxFluidInputs, boolean modifyFluidInputs,
int maxFluidOutputs, boolean modifyFluidOutputs,
@NotNull R defaultRecipeBuilder,
boolean isHidden) {
this.unlocalizedName = unlocalizedName;

this.maxInputs = maxInputs;
this.maxFluidInputs = maxFluidInputs;
this.maxOutputs = maxOutputs;
this.maxFluidOutputs = maxFluidOutputs;

defaultRecipeBuilder.setRecipeMap(this);
defaultRecipeBuilder
.category(GTRecipeCategory.create(GTValues.MODID, unlocalizedName, getTranslationKey(), this));
this.recipeBuilderSample = defaultRecipeBuilder;

this.recipeMapUI = new RecipeMapUI<>(this, modifyItemInputs, modifyItemOutputs, modifyFluidInputs,
modifyFluidOutputs, false);
this.recipeMapUI.setJEIVisible(!isHidden);

RECIPE_MAP_REGISTRY.put(unlocalizedName, this);

this.grsVirtualizedRecipeMap = GregTechAPI.moduleManager.isModuleEnabled(GregTechModules.MODULE_GRS) ?
new VirtualizedRecipeMap(this) : null;
}

/**
* Create and register new instance of RecipeMap with specified properties.
*
Expand All @@ -223,10 +151,11 @@ public RecipeMap(@NotNull String unlocalizedName, @NotNull R defaultRecipeBuilde
this.maxFluidInputs = maxFluidInputs;
this.maxOutputs = maxOutputs;
this.maxFluidOutputs = maxFluidOutputs;
this.primaryRecipeCategory = GTRecipeCategory.create(GTValues.MODID, unlocalizedName, getTranslationKey(),
this);

defaultRecipeBuilder.setRecipeMap(this);
defaultRecipeBuilder
.category(GTRecipeCategory.create(GTValues.MODID, unlocalizedName, getTranslationKey(), this));
defaultRecipeBuilder.category(primaryRecipeCategory);
this.recipeBuilderSample = defaultRecipeBuilder;
RECIPE_MAP_REGISTRY.put(unlocalizedName, this);

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

public @NotNull GTRecipeCategory getPrimaryRecipeCategory() {
return primaryRecipeCategory;
}

@Override
@ZenMethod
public String toString() {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/gregtech/api/recipes/RecipeMapBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class RecipeMapBuilder<B extends RecipeBuilder<B>> {

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

private boolean sortToBack;

/**
* @param unlocalizedName the name of the recipemap
* @param defaultRecipeBuilder the default recipe builder of the recipemap
Expand Down Expand Up @@ -282,6 +284,18 @@ public RecipeMapBuilder(@NotNull String unlocalizedName, @NotNull B defaultRecip
return this;
}

/**
* Have the primary {@link gregtech.api.recipes.category.GTRecipeCategory} for the RecipeMap be sorted to the end
* of the JEI recipe category list.
*
* @param sortToBack if it should be sorted to the back
* @return this
*/
public @NotNull RecipeMapBuilder<B> jeiSortToBack(boolean sortToBack) {
this.sortToBack = sortToBack;
return this;
}

/**
* <strong>Do not call this twice. RecipeMapBuilders are not re-usable.</strong>
*
Expand All @@ -297,6 +311,7 @@ public RecipeMapBuilder(@NotNull String unlocalizedName, @NotNull B defaultRecip
if (buildActions != null) {
recipeMap.onRecipeBuild(buildActions);
}
recipeMap.getPrimaryRecipeCategory().jeiSortToBack(sortToBack);
return recipeMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnmodifiableView;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

public final class GTRecipeCategory {
Expand All @@ -18,6 +21,7 @@ public final class GTRecipeCategory {
private final String translationKey;
private final RecipeMap<?> recipeMap;
private Object icon;
private boolean sortToBack;

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

/**
* @return all of the GTRecipeCategory instances
*/
public static @NotNull @UnmodifiableView Collection<GTRecipeCategory> getCategories() {
return Collections.unmodifiableCollection(categories.values());
}

private GTRecipeCategory(@NotNull String modid, @NotNull String name, @NotNull String translationKey,
@NotNull RecipeMap<?> recipeMap) {
this.modid = modid;
this.name = name;
this.uniqueID = modid + ':' + this.name;
this.uniqueID = modid + '.' + this.name;
this.translationKey = translationKey;
this.recipeMap = recipeMap;
}
Expand Down Expand Up @@ -85,7 +96,7 @@ public RecipeMap<?> getRecipeMap() {
* @param icon the icon to use as a JEI category
* @return this
*/
public GTRecipeCategory jeiIcon(@Nullable Object icon) {
public @NotNull GTRecipeCategory jeiIcon(@Nullable Object icon) {
this.icon = icon;
return this;
}
Expand All @@ -95,6 +106,19 @@ public Object getJEIIcon() {
return this.icon;
}

/**
* @param sortToBack if the category should be at the end of the JEI category list
* @return this
*/
public @NotNull GTRecipeCategory jeiSortToBack(boolean sortToBack) {
this.sortToBack = sortToBack;
return this;
}

public boolean shouldSortToBackJEI() {
return sortToBack;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ public final class RecipeCategories {
"arc_furnace_recycling",
"gregtech.recipe.category.arc_furnace_recycling",
RecipeMaps.ARC_FURNACE_RECIPES)
.jeiIcon(GuiTextures.ARC_FURNACE_RECYLCING_CATEGORY);
.jeiIcon(GuiTextures.ARC_FURNACE_RECYLCING_CATEGORY)
.jeiSortToBack(true);

public static final GTRecipeCategory MACERATOR_RECYCLING = GTRecipeCategory.create(GTValues.MODID,
"macerator_recycling",
"gregtech.recipe.category.macerator_recycling",
RecipeMaps.MACERATOR_RECIPES)
.jeiIcon(GuiTextures.MACERATOR_RECYLCING_CATEGORY);
.jeiIcon(GuiTextures.MACERATOR_RECYLCING_CATEGORY)
.jeiSortToBack(true);

public static final GTRecipeCategory EXTRACTOR_RECYCLING = GTRecipeCategory.create(GTValues.MODID,
"extractor_recycling",
"gregtech.recipe.category.extractor_recycling",
RecipeMaps.EXTRACTOR_RECIPES)
.jeiIcon(GuiTextures.EXTRACTOR_RECYLCING_CATEGORY);
.jeiIcon(GuiTextures.EXTRACTOR_RECYLCING_CATEGORY)
.jeiSortToBack(true);

private RecipeCategories() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public RecipeMapResearchStation(@NotNull String unlocalizedName, @NotNull R defa
@NotNull RecipeMapUIFunction recipeMapUI) {
super(unlocalizedName, defaultRecipeBuilder, recipeMapUI, 2, 1, 0, 0);
setSound(GTValues.FOOLS.get() ? GTSoundEvents.SCIENCE : GTSoundEvents.COMPUTATION);
getPrimaryRecipeCategory().jeiSortToBack(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public RecipeMapScanner(@NotNull String unlocalizedName, @NotNull SimpleRecipeBu
@NotNull RecipeMapUIFunction recipeMapUI) {
super(unlocalizedName, defaultRecipeBuilder, recipeMapUI, 2, 1, 1, 0);
setSound(GTSoundEvents.ELECTROLYZER);
getPrimaryRecipeCategory().jeiSortToBack(true);
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/gregtech/common/ConfigHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ public static class ClientOptions {
"Default: true" })
public boolean enableFancyChestRender = true;

@Config.Comment({ "Whether to prefer the Material Tree over other categories in JEI", "Default: false" })
public boolean preferMaterialTreeInJEI = false;

public static class GuiConfig {

@Config.Comment({ "The scrolling speed of widgets", "Default: 13" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import gregtech.api.worldgen.config.BedrockFluidDepositDefinition;
import gregtech.api.worldgen.config.OreDepositDefinition;
import gregtech.api.worldgen.config.WorldGenRegistry;
import gregtech.common.ConfigHolder;
import gregtech.common.blocks.MetaBlocks;
import gregtech.common.items.MetaItems;
import gregtech.common.items.ToolItems;
Expand Down Expand Up @@ -70,16 +71,20 @@
import mezz.jei.api.JEIPlugin;
import mezz.jei.api.ingredients.IIngredientRegistry;
import mezz.jei.api.ingredients.VanillaTypes;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeCategoryRegistration;
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
import mezz.jei.config.Constants;
import mezz.jei.input.IShowsRecipeFocuses;
import mezz.jei.input.InputHandler;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -156,7 +161,7 @@ public void register(IModRegistry registry) {
ModularUIGuiHandler modularUIGuiHandler = new ModularUIGuiHandler(jeiHelpers.recipeTransferHandlerHelper());
modularUIGuiHandler.blacklistCategory(
IntCircuitCategory.UID,
GTValues.MODID + ":material_tree",
MaterialTreeCategory.UID,
VanillaRecipeCategoryUid.INFORMATION,
VanillaRecipeCategoryUid.FUEL);
registry.getRecipeTransferRegistry().addRecipeTransferHandler(modularUIGuiHandler,
Expand Down Expand Up @@ -255,8 +260,7 @@ public void register(IModRegistry registry) {
}
}

String oreByProductId = GTValues.MODID + ":" + "ore_by_product";
registry.addRecipes(oreByproductList, oreByProductId);
registry.addRecipes(oreByproductList, OreByProductCategory.UID);
MetaTileEntity[][] machineLists = {
MetaTileEntities.MACERATOR,
MetaTileEntities.ORE_WASHER,
Expand All @@ -268,11 +272,11 @@ public void register(IModRegistry registry) {
};
for (MetaTileEntity[] machine : machineLists) {
if (machine.length < GTValues.LV + 1 || machine[GTValues.LV] == null) continue;
registry.addRecipeCatalyst(machine[GTValues.LV].getStackForm(), oreByProductId);
registry.addRecipeCatalyst(machine[GTValues.LV].getStackForm(), OreByProductCategory.UID);
}

// Material Tree
registry.addRecipes(materialTreeList, GTValues.MODID + ":" + "material_tree");
registry.addRecipes(materialTreeList, MaterialTreeCategory.UID);

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

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

String fluidVeinSpawnID = GTValues.MODID + ":" + "fluid_spawn_location";
String fluidVeinSpawnID = GTFluidVeinCategory.UID;
registry.addRecipes(fluidVeinInfos, fluidVeinSpawnID);
registry.addRecipeCatalyst(MetaItems.PROSPECTOR_HV.getStackForm(), fluidVeinSpawnID);
registry.addRecipeCatalyst(MetaItems.PROSPECTOR_LUV.getStackForm(), fluidVeinSpawnID);
Expand Down Expand Up @@ -379,4 +383,42 @@ private void registerRecipeMapCatalyst(IModRegistry registry, RecipeMap<?> recip
}
}
}

/**
* Comparator to sort certain GT categories to the front or back of the JEI category list.
*
* @return the comparator
*/
@ApiStatus.Internal
public static @NotNull Comparator<IRecipeCategory<?>> getRecipeCategoryComparator() {
List<String> backIds = GTRecipeCategory.getCategories().stream()
.filter(GTRecipeCategory::shouldSortToBackJEI)
.map(GTRecipeCategory::getUniqueID)
.collect(Collectors.toCollection(ArrayList::new));
backIds.add(IntCircuitCategory.UID);
backIds.add(MultiblockInfoCategory.UID);
backIds.add(OreByProductCategory.UID);
backIds.add(GTOreCategory.UID);
backIds.add(GTFluidVeinCategory.UID);
List<String> frontIds;
if (ConfigHolder.client.preferMaterialTreeInJEI) {
frontIds = Collections.singletonList(MaterialTreeCategory.UID);
} else {
frontIds = Collections.emptyList();
}

return Comparator.<IRecipeCategory<?>>comparingInt(category -> {
int index = backIds.indexOf(category.getUid());
if (index >= 0) {
return index;
}
return Integer.MIN_VALUE;
}).thenComparingInt(category -> {
int index = frontIds.indexOf(category.getUid());
if (index >= 0) {
return index;
}
return Integer.MAX_VALUE;
});
}
}
Loading
Loading