From 039659fb5a4ac25685575f3793db1e507e971a5b Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Mon, 2 Dec 2024 01:31:59 -0500 Subject: [PATCH] Add Custom Recipe Category support to KubeJS (#2476) --- .../gtceu/api/gui/GuiTextures.java | 8 +- .../gtceu/api/recipe/GTRecipe.java | 12 +-- .../gtceu/api/recipe/GTRecipeSerializer.java | 7 +- .../gtceu/api/recipe/GTRecipeType.java | 20 ++-- .../api/recipe/category/GTRecipeCategory.java | 100 +++++++----------- .../api/recipe/lookup/GTRecipeLookup.java | 10 +- .../gtceu/api/recipe/ui/GTRecipeTypeUI.java | 26 +++-- .../gtceu/common/data/GTRecipeCategories.java | 57 ++++++---- .../gtceu/common/data/GTRecipeTypes.java | 9 +- .../data/recipe/builder/GTRecipeBuilder.java | 12 ++- .../gtceu/integration/emi/GTEMIPlugin.java | 16 +-- .../integration/emi/recipe/GTEmiRecipe.java | 4 +- .../emi/recipe/GTRecipeEMICategory.java | 43 ++++---- .../gtceu/integration/jei/GTJEIPlugin.java | 13 +-- .../jei/recipe/GTRecipeJEICategory.java | 60 +++++------ .../gtceu/integration/kjs/GTRegistryInfo.java | 4 + .../integration/kjs/GregTechKubeJSPlugin.java | 11 ++ .../kjs/builders/GTRecipeCategoryBuilder.java | 62 +++++++++++ .../kjs/recipe/GTRecipeSchema.java | 4 +- .../gtceu/integration/rei/GTREIPlugin.java | 15 +-- .../rei/recipe/GTRecipeDisplay.java | 12 +-- .../rei/recipe/GTRecipeREICategory.java | 70 ++++++------ .../gtceu/utils/ResearchManager.java | 2 - .../{ => category}/arc_furnace_recycling.png | Bin .../{ => category}/extractor_recycling.png | Bin .../{ => category}/macerator_recycling.png | Bin 26 files changed, 289 insertions(+), 288 deletions(-) create mode 100644 src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/GTRecipeCategoryBuilder.java rename src/main/resources/assets/gtceu/textures/gui/icon/{ => category}/arc_furnace_recycling.png (100%) rename src/main/resources/assets/gtceu/textures/gui/icon/{ => category}/extractor_recycling.png (100%) rename src/main/resources/assets/gtceu/textures/gui/icon/{ => category}/macerator_recycling.png (100%) diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/GuiTextures.java b/src/main/java/com/gregtechceu/gtceu/api/gui/GuiTextures.java index 7ee60a2c0a..da93638216 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/GuiTextures.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/GuiTextures.java @@ -3,8 +3,6 @@ import com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; -import net.minecraft.resources.ResourceLocation; - import lombok.val; /** @@ -489,11 +487,11 @@ public class GuiTextures { "gtceu:textures/gui/icon/coke_oven.png"); public static final ResourceTexture ARC_FURNACE_RECYCLING_CATEGORY = new ResourceTexture( - new ResourceLocation("gtceu:textures/gui/icon/arc_furnace_recycling.png"), 0, 0, 16, 16); + "gtceu:textures/gui/icon/category/arc_furnace_recycling.png"); public static final ResourceTexture MACERATOR_RECYCLING_CATEGORY = new ResourceTexture( - new ResourceLocation("gtceu:textures/gui/icon/macerator_recycling.png"), 0, 0, 16, 16); + "gtceu:textures/gui/icon/category/macerator_recycling.png"); public static final ResourceTexture EXTRACTOR_RECYCLING_CATEGORY = new ResourceTexture( - new ResourceLocation("gtceu:textures/gui/icon/extractor_recycling.png"), 0, 0, 16, 16); + "gtceu:textures/gui/icon/category/extractor_recycling.png"); // Covers public static final ResourceTexture COVER_MACHINE_CONTROLLER = new ResourceTexture( diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipe.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipe.java index c592479654..59d89dbb49 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipe.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipe.java @@ -21,7 +21,6 @@ import net.minecraft.world.level.Level; import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet; import lombok.Getter; import lombok.Setter; import org.jetbrains.annotations.NotNull; @@ -64,7 +63,7 @@ public class GTRecipe implements net.minecraft.world.item.crafting.Recipe new ObjectLinkedOpenHashSet<>()) - .add(this); - } + this.recipeCategory = (recipeCategory != GTRecipeCategory.DEFAULT) ? recipeCategory : recipeType.getCategory(); + if (id != null) this.recipeType.addToCategoryMap(this.recipeCategory, this); } public Map, List> copyContents(Map, List> contents, diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeSerializer.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeSerializer.java index 4f82548ad0..38b792e86c 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeSerializer.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeSerializer.java @@ -143,7 +143,6 @@ public GTRecipe fromNetwork(@NotNull ResourceLocation id, @NotNull FriendlyByteB GTRecipeType type = (GTRecipeType) BuiltInRegistries.RECIPE_TYPE.get(recipeType); GTRecipeCategory category = GTRegistries.RECIPE_CATEGORIES.get(categoryLoc); - if (category == null || category == GTRecipeCategory.EMPTY) category = GTRecipeCategory.of(type); GTRecipe recipe = new GTRecipe(type, id, inputs, outputs, tickInputs, tickOutputs, @@ -190,7 +189,7 @@ public void toNetwork(FriendlyByteBuf buf, GTRecipe recipe) { } buf.writeNbt(recipe.data); buf.writeBoolean(recipe.isFuel); - buf.writeResourceLocation(recipe.recipeCategory.getResourceLocation()); + buf.writeResourceLocation(recipe.recipeCategory.registryKey); } private static Codec makeCodec(boolean isKubeLoaded) { @@ -214,7 +213,7 @@ private static Codec makeCodec(boolean isKubeLoaded) { CompoundTag.CODEC.optionalFieldOf("data", new CompoundTag()).forGetter(val -> val.data), ExtraCodecs.NON_NEGATIVE_INT.fieldOf("duration").forGetter(val -> val.duration), Codec.BOOL.optionalFieldOf("isFuel", false).forGetter(val -> val.isFuel), - GTRegistries.RECIPE_CATEGORIES.codec().optionalFieldOf("category", GTRecipeCategory.EMPTY).forGetter(val -> val.recipeCategory)) + GTRegistries.RECIPE_CATEGORIES.codec().optionalFieldOf("category", GTRecipeCategory.DEFAULT).forGetter(val -> val.recipeCategory)) .apply(instance, (type, inputs, outputs, tickInputs, tickOutputs, inputChanceLogics, outputChanceLogics, tickInputChanceLogics, tickOutputChanceLogics, @@ -242,7 +241,7 @@ private static Codec makeCodec(boolean isKubeLoaded) { CompoundTag.CODEC.optionalFieldOf("data", new CompoundTag()).forGetter(val -> val.data), ExtraCodecs.NON_NEGATIVE_INT.fieldOf("duration").forGetter(val -> val.duration), Codec.BOOL.optionalFieldOf("isFuel", false).forGetter(val -> val.isFuel), - GTRegistries.RECIPE_CATEGORIES.codec().optionalFieldOf("category", GTRecipeCategory.EMPTY).forGetter(val -> val.recipeCategory)) + GTRegistries.RECIPE_CATEGORIES.codec().optionalFieldOf("category", GTRecipeCategory.DEFAULT).forGetter(val -> val.recipeCategory)) .apply(instance, GTRecipe::new)); } // @formatter:on diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java index 04f6dda089..70cf8eebf6 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java @@ -93,6 +93,8 @@ public class GTRecipeType implements RecipeType { @Getter protected final Map, List> proxyRecipes; @Getter + private final GTRecipeCategory category; + @Getter private final Map> categoryMap = new Object2ObjectOpenHashMap<>(); private CompoundTag customUICache; @Getter @@ -110,9 +112,8 @@ public class GTRecipeType implements RecipeType { public GTRecipeType(ResourceLocation registryName, String group, RecipeType... proxyRecipes) { this.registryName = registryName; this.group = group; + this.category = GTRecipeCategory.registerDefault(this); recipeBuilder = new GTRecipeBuilder(registryName, this); - recipeBuilder.category( - GTRecipeCategory.of(GTCEu.MOD_ID, registryName.getPath(), this, registryName.toLanguageKey())); // must be linked to stop json contents from shuffling Map, List> map = new Object2ObjectLinkedOpenHashMap<>(); for (RecipeType proxyRecipe : proxyRecipes) { @@ -180,7 +181,7 @@ public GTRecipeType setMaxTooltips(int maxTooltips) { } public GTRecipeType setXEIVisible(boolean XEIVisible) { - this.recipeUI.setXEIVisible(XEIVisible); + this.category.setXEIVisible(XEIVisible); return this; } @@ -341,9 +342,16 @@ public GTRecipe toGTrecipe(ResourceLocation id, Recipe recipe) { return recipes; } - @NotNull - public Map> getRecipesByCategory() { - return Collections.unmodifiableMap(categoryMap); + public void addToCategoryMap(GTRecipeCategory category, GTRecipe recipe) { + categoryMap.computeIfAbsent(category, k -> new ObjectLinkedOpenHashSet<>()).add(recipe); + } + + public Set getCategories() { + return Collections.unmodifiableSet(categoryMap.keySet()); + } + + public Set getRecipesInCategory(GTRecipeCategory category) { + return Collections.unmodifiableSet(categoryMap.getOrDefault(category, Set.of())); } public interface ICustomRecipeLogic { diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/category/GTRecipeCategory.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/category/GTRecipeCategory.java index 5a9b17bbb6..706b328333 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/category/GTRecipeCategory.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/category/GTRecipeCategory.java @@ -5,97 +5,79 @@ import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.common.data.GTRecipeTypes; +import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; +import com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture; + import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Items; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import java.util.Map; - -import javax.annotation.Nullable; - +@Accessors(chain = true) public class GTRecipeCategory { - private static final Map categories = new Object2ObjectOpenHashMap<>(); - public static final GTRecipeCategory EMPTY = new GTRecipeCategory(); + // Placeholder category used if category isn't defined for a recipe for registration + public static final GTRecipeCategory DEFAULT = new GTRecipeCategory("default", GTRecipeTypes.DUMMY_RECIPES); - @Getter - private final String modID; - @Getter - private final String name; - @Getter - private final String uniqueID; - @Getter - private final String translation; + public final ResourceLocation registryKey; + public final String name; @Getter private final GTRecipeType recipeType; - @Nullable @Getter - private Object icon = null; + private final String languageKey; + @Nullable + @Setter + private IGuiTexture icon = null; @Getter - private ResourceLocation resourceLocation; - - public static GTRecipeCategory of(@NotNull String modID, @NotNull String categoryName, - @NotNull GTRecipeType recipeType, @NotNull String translationKey) { - return categories.computeIfAbsent(categoryName, - (k) -> new GTRecipeCategory(modID, categoryName, recipeType, translationKey)); - } - - public static GTRecipeCategory of(@NotNull String modID, @NotNull String categoryName, - @NotNull GTRecipeType recipeType) { - return of(modID, categoryName, recipeType, "%s.recipe.category.%s".formatted(modID, categoryName)); - } - - public static GTRecipeCategory of(@NotNull GTRecipeType recipeType) { - return of(GTCEu.MOD_ID, recipeType.registryName.getPath(), recipeType, recipeType.registryName.toLanguageKey()); - } + @Setter + private boolean isXEIVisible = true; - private GTRecipeCategory() { - this.modID = ""; - this.name = ""; - this.uniqueID = ""; - this.translation = ""; - this.recipeType = GTRecipeTypes.DUMMY_RECIPES; + public GTRecipeCategory(@NotNull GTRecipeType recipeType) { + this.recipeType = recipeType; + this.name = recipeType.registryName.getPath(); + this.registryKey = recipeType.registryName; + this.languageKey = recipeType.registryName.toLanguageKey(); } - private GTRecipeCategory(@NotNull String modID, @NotNull String categoryName, @NotNull GTRecipeType recipeType, - @NotNull String translationKey) { - this.modID = modID; - this.name = categoryName; - this.uniqueID = modID + ":" + this.name; - this.translation = translationKey; + public GTRecipeCategory(@NotNull String categoryName, @NotNull GTRecipeType recipeType) { this.recipeType = recipeType; - this.resourceLocation = new ResourceLocation(modID, categoryName); - GTRegistries.RECIPE_CATEGORIES.register(resourceLocation, this); + this.name = categoryName; + this.registryKey = GTCEu.id(categoryName); + this.languageKey = "%s.recipe.category.%s".formatted(GTCEu.MOD_ID, categoryName); } - public GTRecipeCategory setIcon(@Nullable Object icon) { - this.icon = icon; - return this; + public static GTRecipeCategory registerDefault(@NotNull GTRecipeType recipeType) { + GTRecipeCategory category = new GTRecipeCategory(recipeType); + GTRegistries.RECIPE_CATEGORIES.register(category.registryKey, category); + return category; } - public boolean isXEIVisible() { - return recipeType.getRecipeUI().isXEIVisible(); + public IGuiTexture getIcon() { + if (icon == null) { + if (recipeType.getIconSupplier() != null) icon = new ItemStackTexture(recipeType.getIconSupplier().get()); + else icon = new ItemStackTexture(Items.BARRIER); + } + return icon; } @Override public boolean equals(Object obj) { if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - - GTRecipeCategory that = (GTRecipeCategory) obj; - - return getUniqueID().equals(that.getUniqueID()); + if (!(obj instanceof GTRecipeCategory that)) return false; + return this.registryKey.equals(that.registryKey); } @Override public int hashCode() { - return getUniqueID().hashCode(); + return registryKey.hashCode(); } @Override public String toString() { - return "GTRecipeCategory{" + uniqueID + "}"; + return "GTRecipeCategory{%s}".formatted(name); } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/GTRecipeLookup.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/GTRecipeLookup.java index 7fa375bf96..66ad6ed72a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/GTRecipeLookup.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/GTRecipeLookup.java @@ -4,7 +4,6 @@ import com.gregtechceu.gtceu.api.capability.recipe.*; import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.GTRecipeType; -import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.api.recipe.content.Content; import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; import com.gregtechceu.gtceu.common.data.GTRecipeTypes; @@ -18,7 +17,6 @@ import com.mojang.datafixers.util.Either; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -466,10 +464,7 @@ public boolean addRecipe(GTRecipe recipe) { if (recipe == null) { return false; } - if (recipe.recipeCategory == null) { - recipe.recipeCategory = GTRecipeCategory.of(GTCEu.MOD_ID, recipe.recipeType.registryName.getPath(), - recipe.recipeType, recipe.recipeType.registryName.toLanguageKey()); - } + // Add combustion fuels to the Powerless Jetpack if (recipe.getType() == GTRecipeTypes.COMBUSTION_GENERATOR_FUELS) { Content content = recipe.getInputContents(FluidRecipeCapability.CAP).get(0); @@ -478,8 +473,7 @@ public boolean addRecipe(GTRecipe recipe) { } List> items = fromRecipe(recipe); if (recurseIngredientTreeAdd(recipe, items, lookup, 0, 0)) { - recipeType.getCategoryMap().computeIfAbsent(recipe.recipeCategory, k -> new ObjectLinkedOpenHashSet<>()) - .add(recipe); + recipeType.addToCategoryMap(recipe.recipeCategory, recipe); return true; } return false; diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java index 7ed14fe7f3..2ddc40edb3 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java @@ -58,6 +58,7 @@ import java.util.TreeMap; import java.util.function.BiConsumer; import java.util.function.DoubleSupplier; +import java.util.stream.Collectors; @SuppressWarnings("UnusedReturnValue") public class GTRecipeTypeUI { @@ -84,10 +85,6 @@ public class GTRecipeTypeUI { @Getter protected int maxTooltips = 3; - @Getter - @Setter - private boolean XEIVisible = true; - private CompoundTag customUICache; private Size xeiSize; @Getter @@ -247,18 +244,19 @@ public IEditableUI createEditableUITemplate(final boo widget.getSize().width, widget.getSize().height, IGuiTexture.EMPTY, cd -> { if (cd.isRemote) { if (LDLib.isReiLoaded()) { - recipeType.getRecipesByCategory().keySet() - .forEach(e -> ViewSearchBuilder.builder() - .addCategory(GTRecipeREICategory.CATEGORIES.apply(e)).open()); + ViewSearchBuilder.builder().addCategories( + recipeType.getCategories().stream() + .map(GTRecipeREICategory::machineCategory) + .collect(Collectors.toList())) + .open(); } else if (LDLib.isJeiLoaded()) { - JEIPlugin.jeiRuntime.getRecipesGui() - .showTypes(new ArrayList<>(recipeType.getRecipesByCategory().keySet() - .stream().map(GTRecipeJEICategory.TYPES).toList())); + JEIPlugin.jeiRuntime.getRecipesGui().showTypes( + recipeType.getCategories().stream() + .map(GTRecipeJEICategory::machineType) + .collect(Collectors.toList())); } else if (LDLib.isEmiLoaded()) { - recipeType.getRecipesByCategory().keySet() - .forEach(e -> EmiApi - .displayRecipeCategory( - GTRecipeEMICategory.CATEGORIES.apply(e))); + EmiApi.displayRecipeCategory( + GTRecipeEMICategory.machineCategory(recipeType.getCategory())); } } }).setHoverTooltips("gtceu.recipe_type.show_recipes")); diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeCategories.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeCategories.java index d1bd59a432..5ff36d3e8e 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeCategories.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeCategories.java @@ -3,46 +3,59 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.GTCEuAPI; import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.api.recipe.GTRecipeType; import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.api.registry.GTRegistries; +import com.gregtechceu.gtceu.integration.kjs.GTRegistryInfo; import net.minecraftforge.fml.ModLoader; +import org.jetbrains.annotations.NotNull; + public class GTRecipeCategories { - // Used for recipes you don't want in a category - public static final GTRecipeCategory DUMMY = GTRecipeCategory.of(GTRecipeTypes.DUMMY_RECIPES); + // Alias for recipes that shouldn't be in the category registry + public static final GTRecipeCategory DUMMY = GTRecipeTypes.DUMMY_RECIPES.getCategory(); + // Alias for recipes you don't want visible in XEI + public static final GTRecipeCategory HIDDEN = register("hidden", GTRecipeTypes.DUMMY_RECIPES) + .setXEIVisible(false); - public static final GTRecipeCategory ARC_FURNACE_RECYCLING = GTRecipeCategory - .of(GTCEu.MOD_ID, "arc_furnace_recycling", GTRecipeTypes.ARC_FURNACE_RECIPES) + public static final GTRecipeCategory ARC_FURNACE_RECYCLING = register("arc_furnace_recycling", + GTRecipeTypes.ARC_FURNACE_RECIPES) .setIcon(GuiTextures.ARC_FURNACE_RECYCLING_CATEGORY); - public static final GTRecipeCategory MACERATOR_RECYCLING = GTRecipeCategory - .of(GTCEu.MOD_ID, "macerator_recycling", GTRecipeTypes.MACERATOR_RECIPES) + public static final GTRecipeCategory MACERATOR_RECYCLING = register("macerator_recycling", + GTRecipeTypes.MACERATOR_RECIPES) .setIcon(GuiTextures.MACERATOR_RECYCLING_CATEGORY); - public static final GTRecipeCategory EXTRACTOR_RECYCLING = GTRecipeCategory - .of(GTCEu.MOD_ID, "extractor_recycling", GTRecipeTypes.EXTRACTOR_RECIPES) + public static final GTRecipeCategory EXTRACTOR_RECYCLING = register("extractor_recycling", + GTRecipeTypes.EXTRACTOR_RECIPES) .setIcon(GuiTextures.EXTRACTOR_RECYCLING_CATEGORY); - public static final GTRecipeCategory ORE_CRUSHING = GTRecipeCategory - .of(GTCEu.MOD_ID, "ore_crushing", GTRecipeTypes.MACERATOR_RECIPES); - - public static final GTRecipeCategory ORE_FORGING = GTRecipeCategory - .of(GTCEu.MOD_ID, "ore_forging", GTRecipeTypes.FORGE_HAMMER_RECIPES); - - public static final GTRecipeCategory ORE_BATHING = GTRecipeCategory - .of(GTCEu.MOD_ID, "ore_bathing", GTRecipeTypes.CHEMICAL_BATH_RECIPES); - - public static final GTRecipeCategory CHEM_DYES = GTRecipeCategory - .of(GTCEu.MOD_ID, "chem_dyes", GTRecipeTypes.CHEMICAL_BATH_RECIPES); + public static final GTRecipeCategory ORE_CRUSHING = register("ore_crushing", GTRecipeTypes.MACERATOR_RECIPES); + public static final GTRecipeCategory ORE_FORGING = register("ore_forging", GTRecipeTypes.FORGE_HAMMER_RECIPES); + public static final GTRecipeCategory ORE_BATHING = register("ore_bathing", GTRecipeTypes.CHEMICAL_BATH_RECIPES); + public static final GTRecipeCategory CHEM_DYES = register("chem_dyes", GTRecipeTypes.CHEMICAL_BATH_RECIPES); + public static final GTRecipeCategory INGOT_MOLDING = register("ingot_molding", GTRecipeTypes.ALLOY_SMELTER_RECIPES); - public static final GTRecipeCategory INGOT_MOLDING = GTRecipeCategory - .of(GTCEu.MOD_ID, "ingot_molding", GTRecipeTypes.ALLOY_SMELTER_RECIPES); + public static GTRecipeCategory register(String categoryName, @NotNull GTRecipeType recipeType) { + GTRecipeCategory category = new GTRecipeCategory(categoryName, recipeType); + GTRegistries.RECIPE_CATEGORIES.register(category.registryKey, category); + return category; + } public static void init() { - GTRegistries.RECIPE_CATEGORIES.remove(DUMMY.getResourceLocation()); + // Remove these categories, so they don't get registered in XEI at all, dev or not + GTRegistries.RECIPE_CATEGORIES.remove(DUMMY.registryKey); + GTRegistries.RECIPE_CATEGORIES.remove(GTRecipeTypes.FURNACE_RECIPES.getCategory().registryKey); + if (GTCEu.isKubeJSLoaded()) { + GTRegistryInfo.registerFor(GTRegistries.RECIPE_CATEGORIES.getRegistryName()); + } ModLoader.get().postEvent(new GTCEuAPI.RegisterEvent<>(GTRegistries.RECIPE_CATEGORIES, GTRecipeCategory.class)); GTRegistries.RECIPE_CATEGORIES.freeze(); } + + public static GTRecipeCategory get(String name) { + return GTRegistries.RECIPE_CATEGORIES.get(GTCEu.appendId(name)); + } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java index 017d31c650..d22b9b37a9 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java @@ -12,7 +12,6 @@ import com.gregtechceu.gtceu.api.gui.widget.SlotWidget; import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.recipe.*; -import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.api.recipe.content.Content; import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; import com.gregtechceu.gtceu.api.registry.GTRegistries; @@ -82,8 +81,7 @@ public class GTRecipeTypes { // remove the * 12 if SteamBoilerMachine:240 is uncommented var duration = (builder.duration / 12 / 80); // copied for large boiler if (duration > 0) { - GTRecipeTypes.LARGE_BOILER_RECIPES.copyFrom(builder).duration(duration) - .category(GTRecipeCategory.of(GTRecipeTypes.LARGE_BOILER_RECIPES)).save(provider); + GTRecipeTypes.LARGE_BOILER_RECIPES.copyFrom(builder).duration(duration).save(provider); } }) .setMaxTooltips(1) @@ -98,8 +96,7 @@ public class GTRecipeTypes { .setSlotOverlay(false, false, GuiTextures.FURNACE_OVERLAY_1) .setProgressBar(GuiTextures.PROGRESS_BAR_ARROW, LEFT_TO_RIGHT) .setSteamProgressBar(GuiTextures.PROGRESS_BAR_ARROW_STEAM, LEFT_TO_RIGHT) - .setSound(GTSoundEntries.FURNACE) - .setXEIVisible(false); + .setSound(GTSoundEntries.FURNACE); public final static GTRecipeType ALLOY_SMELTER_RECIPES = register("alloy_smelter", ELECTRIC) .setMaxIOSize(2, 1, 0, 0).setEUIO(IO.IN) @@ -199,7 +196,6 @@ public class GTRecipeTypes { .setSound(GTValues.FOOLS.get() ? GTSoundEntries.SCIENCE : GTSoundEntries.CHEMICAL) .setMaxTooltips(4) .onRecipeBuild((recipeBuilder, provider) -> GTRecipeTypes.LARGE_CHEMICAL_RECIPES.copyFrom(recipeBuilder) - .category(GTRecipeCategory.of(GTRecipeTypes.LARGE_CHEMICAL_RECIPES)) .save(provider)); public final static GTRecipeType COMPRESSOR_RECIPES = register("compressor", ELECTRIC).setMaxIOSize(1, 1, 0, 0) @@ -713,7 +709,6 @@ public static void init() { CREATE_MIXER_RECIPES.copyFrom(builder) .duration(Math.max((builder.duration / 2), 1)) .rpm(64) - .category(GTRecipeCategory.of(CREATE_MIXER_RECIPES)) .save(provider); }); } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/builder/GTRecipeBuilder.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/builder/GTRecipeBuilder.java index d1f8666cea..867fd8528b 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/builder/GTRecipeBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/builder/GTRecipeBuilder.java @@ -20,6 +20,7 @@ import com.gregtechceu.gtceu.api.recipe.ingredient.IntProviderIngredient; import com.gregtechceu.gtceu.api.recipe.ingredient.SizedIngredient; import com.gregtechceu.gtceu.api.registry.GTRegistries; +import com.gregtechceu.gtceu.common.data.GTRecipeCategories; import com.gregtechceu.gtceu.common.data.GTRecipeTypes; import com.gregtechceu.gtceu.common.recipe.condition.*; import com.gregtechceu.gtceu.config.ConfigHolder; @@ -109,7 +110,7 @@ public class GTRecipeBuilder { public GTRecipeBuilder(ResourceLocation id, GTRecipeType recipeType) { this.id = id; this.recipeType = recipeType; - this.recipeCategory = GTRecipeCategory.of(recipeType); + this.recipeCategory = recipeType.getCategory(); } public GTRecipeBuilder(GTRecipe toCopy, GTRecipeType recipeType) { @@ -166,7 +167,7 @@ public GTRecipeBuilder copy(ResourceLocation id) { } public GTRecipeBuilder copyFrom(GTRecipeBuilder builder) { - return builder.copy(builder.id).onSave(null).recipeType(recipeType); + return builder.copy(builder.id).onSave(null).recipeType(recipeType).category(recipeCategory); } public GTRecipeBuilder input(RecipeCapability capability, T obj) { @@ -1091,7 +1092,7 @@ public void toJson(JsonObject json) { json.add("tickInputChanceLogics", chanceLogicsToJson(tickInputChanceLogic)); json.add("tickOutputChanceLogics", chanceLogicsToJson(tickOutputChanceLogic)); - json.addProperty("category", recipeCategory.getResourceLocation().toString()); + json.addProperty("category", recipeCategory.registryKey.toString()); if (!conditions.isEmpty()) { JsonArray array = new JsonArray(); @@ -1176,7 +1177,7 @@ public void save(Consumer consumer) { if (recipeType != null) { if (recipeCategory == null) { GTCEu.LOGGER.error("Recipes must have a category", new IllegalArgumentException()); - } else if (recipeCategory != GTRecipeCategory.EMPTY && recipeCategory.getRecipeType() != recipeType) { + } else if (recipeCategory != GTRecipeCategory.DEFAULT && recipeCategory.getRecipeType() != recipeType) { GTCEu.LOGGER.error("Cannot apply Category with incompatible RecipeType", new IllegalArgumentException()); } @@ -1185,11 +1186,12 @@ public void save(Consumer consumer) { consumer.accept(build()); } + // Hide raw recipes public GTRecipe buildRawRecipe() { var recipe = new GTRecipe(recipeType, id.withPrefix(recipeType.registryName.getPath() + "/"), input, output, tickInput, tickOutput, inputChanceLogic, outputChanceLogic, tickInputChanceLogic, tickOutputChanceLogic, - conditions, List.of(), data, duration, isFuel, recipeCategory); + conditions, List.of(), data, duration, isFuel, GTRecipeCategories.DUMMY); return recipe; } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/emi/GTEMIPlugin.java b/src/main/java/com/gregtechceu/gtceu/integration/emi/GTEMIPlugin.java index 0f2ceb7f4d..dc2d1262fe 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/emi/GTEMIPlugin.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/emi/GTEMIPlugin.java @@ -2,7 +2,6 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.GTValues; -import com.gregtechceu.gtceu.api.machine.MachineDefinition; import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.common.data.GTMachines; @@ -26,7 +25,6 @@ import dev.emi.emi.api.EmiEntrypoint; import dev.emi.emi.api.EmiPlugin; import dev.emi.emi.api.EmiRegistry; -import dev.emi.emi.api.recipe.VanillaEmiRecipeCategories; import dev.emi.emi.api.stack.EmiStack; /** @@ -77,19 +75,7 @@ public void register(EmiRegistry registry) { GTBedrockFluidEmiCategory.registerWorkStations(registry); if (ConfigHolder.INSTANCE.machines.doBedrockOres) GTBedrockOreEmiCategory.registerWorkStations(registry); - for (MachineDefinition definition : GTMachines.ELECTRIC_FURNACE) { - if (definition != null) { - registry.addWorkstation(VanillaEmiRecipeCategories.SMELTING, EmiStack.of(definition.asStack())); - } - } - registry.addWorkstation(VanillaEmiRecipeCategories.SMELTING, - EmiStack.of(GTMachines.STEAM_FURNACE.left().asStack())); - registry.addWorkstation(VanillaEmiRecipeCategories.SMELTING, - EmiStack.of(GTMachines.STEAM_FURNACE.right().asStack())); - registry.addWorkstation(VanillaEmiRecipeCategories.SMELTING, EmiStack.of(GTMachines.STEAM_OVEN.asStack())); - registry.addWorkstation(VanillaEmiRecipeCategories.SMELTING, EmiStack.of(GTMachines.MULTI_SMELTER.asStack())); - registry.addWorkstation( - GTRecipeEMICategory.CATEGORIES.apply(GTRecipeCategory.of(GTRecipeTypes.CHEMICAL_RECIPES)), + registry.addWorkstation(GTRecipeEMICategory.CATEGORIES.apply(GTRecipeTypes.CHEMICAL_RECIPES.getCategory()), EmiStack.of(GTMachines.LARGE_CHEMICAL_REACTOR.asStack())); } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/emi/recipe/GTEmiRecipe.java b/src/main/java/com/gregtechceu/gtceu/integration/emi/recipe/GTEmiRecipe.java index 385ed80bce..2e30ffc4bb 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/emi/recipe/GTEmiRecipe.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/emi/recipe/GTEmiRecipe.java @@ -31,10 +31,10 @@ public class GTEmiRecipe extends ModularEmiRecipe { - final GTRecipeEMICategory category; + final EmiRecipeCategory category; final GTRecipe recipe; - public GTEmiRecipe(GTRecipeEMICategory category, GTRecipe recipe) { + public GTEmiRecipe(GTRecipe recipe, EmiRecipeCategory category) { super(() -> new GTRecipeWidget(recipe)); this.category = category; this.recipe = recipe; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/emi/recipe/GTRecipeEMICategory.java b/src/main/java/com/gregtechceu/gtceu/integration/emi/recipe/GTRecipeEMICategory.java index 11bffd2d79..37b101f9f3 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/emi/recipe/GTRecipeEMICategory.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/emi/recipe/GTRecipeEMICategory.java @@ -7,19 +7,16 @@ import com.gregtechceu.gtceu.common.data.GTRecipeTypes; import com.lowdragmc.lowdraglib.Platform; -import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; +import com.lowdragmc.lowdraglib.emi.IGui2Renderable; import net.minecraft.Util; import net.minecraft.network.chat.Component; -import net.minecraft.world.item.Items; import dev.emi.emi.api.EmiRegistry; import dev.emi.emi.api.recipe.EmiRecipeCategory; -import dev.emi.emi.api.render.EmiRenderable; -import dev.emi.emi.api.render.EmiTexture; +import dev.emi.emi.api.recipe.VanillaEmiRecipeCategories; import dev.emi.emi.api.stack.EmiStack; -import java.util.Set; import java.util.function.Function; import java.util.stream.Stream; @@ -29,29 +26,19 @@ public class GTRecipeEMICategory extends EmiRecipeCategory { .memoize(GTRecipeEMICategory::new); private final GTRecipeCategory category; - public GTRecipeEMICategory(GTRecipeCategory category) { - super(category.getRecipeType().registryName, getDrawable(category), getDrawable(category)); + private GTRecipeEMICategory(GTRecipeCategory category) { + super(category.registryKey, IGui2Renderable.toDrawable(category.getIcon(), 16, 16)); this.category = category; } - public static EmiRenderable getDrawable(GTRecipeCategory category) { - if (category.getIcon() instanceof ResourceTexture tex) { - return new EmiTexture(tex.imageLocation, 0, 0, 16, 16, - (int) tex.imageWidth, (int) tex.imageHeight, (int) tex.imageWidth, (int) tex.imageHeight); - } else if (category.getRecipeType().getIconSupplier() != null) - return EmiStack.of(category.getRecipeType().getIconSupplier().get()); - else - return EmiStack.of(Items.BARRIER); - } - public static void registerDisplays(EmiRegistry registry) { for (GTRecipeCategory category : GTRegistries.RECIPE_CATEGORIES) { + if (!category.isXEIVisible() && !Platform.isDevEnv()) continue; var type = category.getRecipeType(); - if (type == GTRecipeTypes.FURNACE_RECIPES) continue; - if (!type.getRecipeUI().isXEIVisible() && !Platform.isDevEnv()) continue; - var recipes = type.getCategoryMap().getOrDefault(category, Set.of()).stream(); + EmiRecipeCategory emiCategory = CATEGORIES.apply(category); + var recipes = type.getRecipesInCategory(category).stream(); Stream.concat(recipes, type.getRepresentativeRecipes().stream()) - .map(recipe -> new GTEmiRecipe(CATEGORIES.apply(category), recipe)) + .map(recipe -> new GTEmiRecipe(recipe, emiCategory)) .forEach(registry::addRecipe); } } @@ -60,16 +47,22 @@ public static void registerWorkStations(EmiRegistry registry) { for (MachineDefinition machine : GTRegistries.MACHINES) { if (machine.getRecipeTypes() == null) continue; for (GTRecipeType type : machine.getRecipeTypes()) { - if (type == null || !(Platform.isDevEnv() || type.getRecipeUI().isXEIVisible())) continue; - for (GTRecipeCategory category : type.getRecipesByCategory().keySet()) { - registry.addWorkstation(CATEGORIES.apply(category), EmiStack.of(machine.asStack())); + if (type == null) continue; + for (GTRecipeCategory category : type.getCategories()) { + if (!category.isXEIVisible() && !Platform.isDevEnv()) continue; + registry.addWorkstation(machineCategory(category), EmiStack.of(machine.asStack())); } } } } + public static EmiRecipeCategory machineCategory(GTRecipeCategory category) { + if (category == GTRecipeTypes.FURNACE_RECIPES.getCategory()) return VanillaEmiRecipeCategories.SMELTING; + else return CATEGORIES.apply(category); + } + @Override public Component getName() { - return Component.translatable(category.getTranslation()); + return Component.translatable(category.getLanguageKey()); } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/jei/GTJEIPlugin.java b/src/main/java/com/gregtechceu/gtceu/integration/jei/GTJEIPlugin.java index f885afa9d4..f0683bb609 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/jei/GTJEIPlugin.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/jei/GTJEIPlugin.java @@ -1,7 +1,6 @@ package com.gregtechceu.gtceu.integration.jei; import com.gregtechceu.gtceu.GTCEu; -import com.gregtechceu.gtceu.api.machine.MachineDefinition; import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.common.data.GTMachines; @@ -22,7 +21,6 @@ import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; -import mezz.jei.api.constants.RecipeTypes; import mezz.jei.api.helpers.IJeiHelpers; import mezz.jei.api.registration.*; import org.jetbrains.annotations.NotNull; @@ -73,17 +71,8 @@ public void registerRecipeCatalysts(@NotNull IRecipeCatalystRegistration registr GTBedrockFluidInfoCategory.registerRecipeCatalysts(registration); if (ConfigHolder.INSTANCE.machines.doBedrockOres) GTBedrockOreInfoCategory.registerRecipeCatalysts(registration); - for (MachineDefinition definition : GTMachines.ELECTRIC_FURNACE) { - if (definition != null) { - registration.addRecipeCatalyst(definition.asStack(), RecipeTypes.SMELTING); - } - } - registration.addRecipeCatalyst(GTMachines.STEAM_FURNACE.left().asStack(), RecipeTypes.SMELTING); - registration.addRecipeCatalyst(GTMachines.STEAM_FURNACE.right().asStack(), RecipeTypes.SMELTING); - registration.addRecipeCatalyst(GTMachines.STEAM_OVEN.asStack(), RecipeTypes.SMELTING); - registration.addRecipeCatalyst(GTMachines.MULTI_SMELTER.asStack(), RecipeTypes.SMELTING); registration.addRecipeCatalyst(GTMachines.LARGE_CHEMICAL_REACTOR.asStack(), - GTRecipeJEICategory.TYPES.apply(GTRecipeCategory.of(GTRecipeTypes.CHEMICAL_RECIPES))); + GTRecipeJEICategory.TYPES.apply(GTRecipeTypes.CHEMICAL_RECIPES.getCategory())); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/integration/jei/recipe/GTRecipeJEICategory.java b/src/main/java/com/gregtechceu/gtceu/integration/jei/recipe/GTRecipeJEICategory.java index 8815146ce2..affb6e0d76 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/jei/recipe/GTRecipeJEICategory.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/jei/recipe/GTRecipeJEICategory.java @@ -7,15 +7,15 @@ import com.gregtechceu.gtceu.common.data.GTRecipeTypes; import com.lowdragmc.lowdraglib.Platform; -import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; +import com.lowdragmc.lowdraglib.jei.IGui2IDrawable; import com.lowdragmc.lowdraglib.jei.ModularUIRecipeCategory; import net.minecraft.Util; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.Items; import lombok.Getter; +import mezz.jei.api.constants.RecipeTypes; import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.helpers.IJeiHelpers; @@ -25,14 +25,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; import java.util.function.Function; import java.util.stream.Stream; public class GTRecipeJEICategory extends ModularUIRecipeCategory { public static final Function> TYPES = Util - .memoize(category -> new RecipeType<>(category.getResourceLocation(), GTRecipeWrapper.class)); + .memoize(c -> new RecipeType<>(c.registryKey, GTRecipeWrapper.class)); private final GTRecipeCategory category; @Getter @@ -47,37 +46,14 @@ public GTRecipeJEICategory(IJeiHelpers helpers, IGuiHelper guiHelper = helpers.getGuiHelper(); var size = recipeType.getRecipeUI().getJEISize(); this.background = guiHelper.createBlankDrawable(size.width, size.height); - - Object icon1 = category.getIcon(); - if (icon1 instanceof ResourceTexture tex) { - this.icon = helpers.getGuiHelper() - .drawableBuilder(tex.imageLocation, 0, 0, (int) tex.imageWidth, (int) tex.imageHeight) - .setTextureSize(16, 16).build(); - } else if (recipeType.getIconSupplier() != null) { - this.icon = helpers.getGuiHelper().createDrawableItemStack(recipeType.getIconSupplier().get()); - } else { - this.icon = helpers.getGuiHelper().createDrawableItemStack(Items.BARRIER.getDefaultInstance()); - } - } - - @Override - @NotNull - public RecipeType getRecipeType() { - return TYPES.apply(category); - } - - @NotNull - @Override - public Component getTitle() { - return Component.translatable(category.getTranslation()); + this.icon = IGui2IDrawable.toDrawable(category.getIcon(), 16, 16); } public static void registerRecipes(IRecipeRegistration registration) { for (GTRecipeCategory category : GTRegistries.RECIPE_CATEGORIES) { + if (!category.isXEIVisible() && !Platform.isDevEnv()) continue; var type = category.getRecipeType(); - if (type == GTRecipeTypes.FURNACE_RECIPES) continue; - if (!type.getRecipeUI().isXEIVisible() && !Platform.isDevEnv()) continue; - var recipes = type.getCategoryMap().getOrDefault(category, Set.of()).stream(); + var recipes = type.getRecipesInCategory(category).stream(); var wrapped = Stream.concat(recipes, type.getRepresentativeRecipes().stream()) .map(GTRecipeWrapper::new) .toList(); @@ -89,14 +65,32 @@ public static void registerRecipeCatalysts(IRecipeCatalystRegistration registrat for (MachineDefinition machine : GTRegistries.MACHINES) { if (machine.getRecipeTypes() == null) continue; for (GTRecipeType type : machine.getRecipeTypes()) { - if (type == null || !(Platform.isDevEnv() || type.getRecipeUI().isXEIVisible())) continue; - for (GTRecipeCategory category : type.getRecipesByCategory().keySet()) { - registration.addRecipeCatalyst(machine.asStack(), TYPES.apply(category)); + if (type == null) continue; + for (GTRecipeCategory category : type.getCategories()) { + if (!category.isXEIVisible() && !Platform.isDevEnv()) continue; + registration.addRecipeCatalyst(machine.asStack(), machineType(category)); } } } } + public static RecipeType machineType(GTRecipeCategory category) { + if (category == GTRecipeTypes.FURNACE_RECIPES.getCategory()) return RecipeTypes.SMELTING; + return TYPES.apply(category); + } + + @Override + @NotNull + public RecipeType getRecipeType() { + return TYPES.apply(category); + } + + @Override + @NotNull + public Component getTitle() { + return Component.translatable(category.getLanguageKey()); + } + @Override public @Nullable ResourceLocation getRegistryName(@NotNull GTRecipeWrapper wrapper) { return wrapper.recipe.id; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/GTRegistryInfo.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/GTRegistryInfo.java index f67072ce9c..12958e0e13 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/GTRegistryInfo.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/GTRegistryInfo.java @@ -12,6 +12,7 @@ import com.gregtechceu.gtceu.api.data.worldgen.WorldGeneratorUtils; import com.gregtechceu.gtceu.api.machine.MachineDefinition; import com.gregtechceu.gtceu.api.recipe.GTRecipeType; +import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.api.registry.GTRegistry; import com.gregtechceu.gtceu.api.registry.registrate.BuilderBase; @@ -51,6 +52,9 @@ public record BuilderType(String type, Class RECIPE_TYPE = add(GTRegistries.RECIPE_TYPES, GTRecipeType.class); + public static final GTRegistryInfo RECIPE_CATEGORY = add( + GTRegistries.RECIPE_CATEGORIES, + GTRecipeCategory.class); public static final GTRegistryInfo MACHINE = add(GTRegistries.MACHINES, MachineDefinition.class); public static final GTRegistryInfo MATERIAL_ICON_SET = add(GTCEu.id("material_icon_set"), diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java index 5302db7cf6..cfc3db9ad5 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java @@ -41,6 +41,7 @@ import com.gregtechceu.gtceu.api.recipe.GTRecipeSerializer; import com.gregtechceu.gtceu.api.recipe.GTRecipeType; import com.gregtechceu.gtceu.api.recipe.OverclockingLogic; +import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.api.recipe.chance.logic.ChanceLogic; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.common.data.*; @@ -112,6 +113,8 @@ public void init() { GTRegistryInfo.MATERIAL.addType("basic", Material.Builder.class, Material.Builder::new, true); GTRegistryInfo.RECIPE_TYPE.addType("basic", GTRecipeTypeBuilder.class, GTRecipeTypeBuilder::new, true); + GTRegistryInfo.RECIPE_CATEGORY.addType("basic", GTRecipeCategoryBuilder.class, GTRecipeCategoryBuilder::new, + true); GTRegistryInfo.MACHINE.addType("simple", SimpleMachineBuilder.class, (id, args) -> SimpleMachineBuilder.create(id.getPath(), args), true); @@ -263,6 +266,14 @@ public void registerTypeWrappers(ScriptType type, TypeWrappers typeWrappers) { if (o instanceof CharSequence chars) return GTRecipeTypes.get(chars.toString()); return null; }); + typeWrappers.registerSimple(GTRecipeCategory.class, o -> { + if (o instanceof Wrapper w) { + o = w.unwrap(); + } + if (o instanceof GTRecipeCategory recipeCategory) return recipeCategory; + if (o instanceof CharSequence chars) return GTRecipeCategories.get(chars.toString()); + return null; + }); typeWrappers.registerSimple(Element.class, o -> { if (o instanceof Element element) return element; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/GTRecipeCategoryBuilder.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/GTRecipeCategoryBuilder.java new file mode 100644 index 0000000000..00bd0111e9 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/GTRecipeCategoryBuilder.java @@ -0,0 +1,62 @@ +package com.gregtechceu.gtceu.integration.kjs.builders; + +import com.gregtechceu.gtceu.api.recipe.GTRecipeType; +import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; +import com.gregtechceu.gtceu.api.registry.registrate.BuilderBase; +import com.gregtechceu.gtceu.common.data.GTRecipeCategories; + +import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; +import com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture; +import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; + +public class GTRecipeCategoryBuilder extends BuilderBase { + + public transient String name; + public transient GTRecipeType recipeType; + private transient IGuiTexture icon; + private transient boolean isXEIVisible; + + public GTRecipeCategoryBuilder(ResourceLocation id, Object... args) { + super(id); + name = id.getPath(); + recipeType = null; + icon = null; + isXEIVisible = true; + } + + public GTRecipeCategoryBuilder recipeType(GTRecipeType recipeType) { + this.recipeType = recipeType; + return this; + } + + public GTRecipeCategoryBuilder setIcon(IGuiTexture guiTexture) { + this.icon = guiTexture; + return this; + } + + public GTRecipeCategoryBuilder setCustomIcon(ResourceLocation location) { + this.icon = new ResourceTexture(location.withPrefix("textures/").withSuffix(".png")); + return this; + } + + public GTRecipeCategoryBuilder setItemIcon(ItemStack... stacks) { + this.icon = new ItemStackTexture(stacks); + return this; + } + + public GTRecipeCategoryBuilder isXEIVisible(boolean flag) { + this.isXEIVisible = flag; + return this; + } + + @Override + public GTRecipeCategory register() { + var category = GTRecipeCategories.register(name, recipeType) + .setIcon(icon) + .setXEIVisible(isXEIVisible); + return value = category; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/GTRecipeSchema.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/GTRecipeSchema.java index e4ba8b74c5..cca92957b9 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/GTRecipeSchema.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/GTRecipeSchema.java @@ -136,8 +136,8 @@ public GTRecipeJS addCondition(RecipeCondition condition) { return this; } - public GTRecipeJS recipeCategory(GTRecipeCategory category) { - setValue(CATEGORY, category.getResourceLocation()); + public GTRecipeJS category(GTRecipeCategory category) { + setValue(CATEGORY, category.registryKey); save(); return this; } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/rei/GTREIPlugin.java b/src/main/java/com/gregtechceu/gtceu/integration/rei/GTREIPlugin.java index 12a5e1969e..70c5871897 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/rei/GTREIPlugin.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/rei/GTREIPlugin.java @@ -3,7 +3,6 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.data.tag.TagPrefix; import com.gregtechceu.gtceu.api.item.tool.GTToolType; -import com.gregtechceu.gtceu.api.machine.MachineDefinition; import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.common.data.GTBlocks; @@ -34,8 +33,6 @@ import java.util.List; import java.util.Objects; -import static me.shedaniel.rei.plugin.common.BuiltinPlugin.SMELTING; - /** * @author KilaBash * @date 2023/2/25 @@ -66,17 +63,7 @@ public void registerCategories(CategoryRegistry registry) { GTBedrockFluidDisplayCategory.registerWorkstations(registry); if (ConfigHolder.INSTANCE.machines.doBedrockOres) GTBedrockOreDisplayCategory.registerWorkstations(registry); - for (MachineDefinition definition : GTMachines.ELECTRIC_FURNACE) { - if (definition != null) { - registry.addWorkstations(SMELTING, EntryStacks.of(definition.asStack())); - } - } - registry.addWorkstations(SMELTING, EntryStacks.of(GTMachines.STEAM_FURNACE.left().asStack())); - registry.addWorkstations(SMELTING, EntryStacks.of(GTMachines.STEAM_FURNACE.right().asStack())); - registry.addWorkstations(SMELTING, EntryStacks.of(GTMachines.STEAM_OVEN.asStack())); - registry.addWorkstations(SMELTING, EntryStacks.of(GTMachines.MULTI_SMELTER.asStack())); - registry.addWorkstations( - GTRecipeREICategory.CATEGORIES.apply(GTRecipeCategory.of(GTRecipeTypes.CHEMICAL_RECIPES)), + registry.addWorkstations(GTRecipeREICategory.CATEGORIES.apply(GTRecipeTypes.CHEMICAL_RECIPES.getCategory()), EntryStacks.of(GTMachines.LARGE_CHEMICAL_REACTOR.asStack())); } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/rei/recipe/GTRecipeDisplay.java b/src/main/java/com/gregtechceu/gtceu/integration/rei/recipe/GTRecipeDisplay.java index 8156f9df94..f929e453a7 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/rei/recipe/GTRecipeDisplay.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/rei/recipe/GTRecipeDisplay.java @@ -1,7 +1,6 @@ package com.gregtechceu.gtceu.integration.rei.recipe; import com.gregtechceu.gtceu.api.recipe.GTRecipe; -import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.integration.GTRecipeWidget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; @@ -9,19 +8,16 @@ import net.minecraft.resources.ResourceLocation; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; + import java.util.Optional; public class GTRecipeDisplay extends ModularDisplay { private final GTRecipe recipe; - public GTRecipeDisplay(GTRecipe recipe) { - super(() -> new GTRecipeWidget(recipe), GTRecipeREICategory.CATEGORIES.apply(recipe.recipeCategory)); - this.recipe = recipe; - } - - public GTRecipeDisplay(GTRecipe recipe, GTRecipeCategory category) { - super(() -> new GTRecipeWidget(recipe), GTRecipeREICategory.CATEGORIES.apply(category)); + public GTRecipeDisplay(GTRecipe recipe, CategoryIdentifier category) { + super(() -> new GTRecipeWidget(recipe), category); this.recipe = recipe; } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/rei/recipe/GTRecipeREICategory.java b/src/main/java/com/gregtechceu/gtceu/integration/rei/recipe/GTRecipeREICategory.java index 8ef8679276..cac25a8e9a 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/rei/recipe/GTRecipeREICategory.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/rei/recipe/GTRecipeREICategory.java @@ -1,22 +1,18 @@ package com.gregtechceu.gtceu.integration.rei.recipe; import com.gregtechceu.gtceu.api.machine.MachineDefinition; -import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.GTRecipeType; import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.common.data.GTRecipeTypes; import com.lowdragmc.lowdraglib.Platform; -import com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture; -import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; import com.lowdragmc.lowdraglib.rei.IGui2Renderer; import com.lowdragmc.lowdraglib.rei.ModularUIDisplayCategory; import com.lowdragmc.lowdraglib.utils.Size; import net.minecraft.Util; import net.minecraft.network.chat.Component; -import net.minecraft.world.item.Items; import lombok.Getter; import me.shedaniel.rei.api.client.gui.Renderer; @@ -24,14 +20,16 @@ import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.util.EntryStacks; +import me.shedaniel.rei.plugin.common.BuiltinPlugin; import org.jetbrains.annotations.NotNull; import java.util.function.Function; +import java.util.stream.Stream; public class GTRecipeREICategory extends ModularUIDisplayCategory { public static final Function> CATEGORIES = Util - .memoize(category -> CategoryIdentifier.of(category.getResourceLocation())); + .memoize(c -> CategoryIdentifier.of(c.registryKey)); private final GTRecipeCategory category; @Getter @@ -44,15 +42,39 @@ public GTRecipeREICategory(@NotNull GTRecipeCategory category) { var recipeType = category.getRecipeType(); var size = recipeType.getRecipeUI().getJEISize(); this.size = new Size(size.width + 8, size.height + 8); - if (category.getIcon() instanceof ResourceTexture tex) { - icon = IGui2Renderer.toDrawable(tex); - } else if (recipeType.getIconSupplier() != null) { - icon = IGui2Renderer.toDrawable(new ItemStackTexture(recipeType.getIconSupplier().get())); - } else { - icon = IGui2Renderer.toDrawable(new ItemStackTexture(Items.BARRIER.getDefaultInstance())); + this.icon = IGui2Renderer.toDrawable(category.getIcon()); + } + + public static void registerDisplays(DisplayRegistry registry) { + for (GTRecipeCategory category : GTRegistries.RECIPE_CATEGORIES) { + if (!category.isXEIVisible() && !Platform.isDevEnv()) continue; + var type = category.getRecipeType(); + var recipes = type.getRecipesInCategory(category).stream(); + var identifier = CATEGORIES.apply(category); + Stream.concat(recipes, type.getRepresentativeRecipes().stream()) + .map(r -> new GTRecipeDisplay(r, identifier)) + .forEach(registry::add); } } + public static void registerWorkStations(CategoryRegistry registry) { + for (MachineDefinition machine : GTRegistries.MACHINES) { + if (machine.getRecipeTypes() == null) continue; + for (GTRecipeType type : machine.getRecipeTypes()) { + if (type == null) continue; + for (GTRecipeCategory category : type.getCategories()) { + if (!category.isXEIVisible() && !Platform.isDevEnv()) continue; + registry.addWorkstations(machineCategory(category), EntryStacks.of(machine.asStack())); + } + } + } + } + + public static CategoryIdentifier machineCategory(GTRecipeCategory category) { + if (category == GTRecipeTypes.FURNACE_RECIPES.getCategory()) return BuiltinPlugin.SMELTING; + else return CATEGORIES.apply(category); + } + @Override public CategoryIdentifier getCategoryIdentifier() { return CATEGORIES.apply(category); @@ -71,30 +93,6 @@ public int getDisplayWidth(GTRecipeDisplay display) { @NotNull @Override public Component getTitle() { - return Component.translatable(category.getTranslation()); - } - - public static void registerDisplays(DisplayRegistry registry) { - for (GTRecipeCategory category : GTRegistries.RECIPE_CATEGORIES) { - var type = category.getRecipeType(); - if (type == GTRecipeTypes.FURNACE_RECIPES) continue; - if (!type.getRecipeUI().isXEIVisible() && !Platform.isDevEnv()) continue; - registry.registerRecipeFiller(GTRecipe.class, type, GTRecipeDisplay::new); - type.getRepresentativeRecipes().stream() - .map(r -> new GTRecipeDisplay(r, category)) - .forEach(registry::add); - } - } - - public static void registerWorkStations(CategoryRegistry registry) { - for (MachineDefinition machine : GTRegistries.MACHINES) { - if (machine.getRecipeTypes() == null) continue; - for (GTRecipeType type : machine.getRecipeTypes()) { - if (type == null || !(Platform.isDevEnv() || type.getRecipeUI().isXEIVisible())) continue; - for (GTRecipeCategory category : type.getRecipesByCategory().keySet()) { - registry.addWorkstations(CATEGORIES.apply(category), EntryStacks.of(machine.asStack())); - } - } - } + return Component.translatable(category.getLanguageKey()); } } diff --git a/src/main/java/com/gregtechceu/gtceu/utils/ResearchManager.java b/src/main/java/com/gregtechceu/gtceu/utils/ResearchManager.java index 40b9ffad6d..ead4ed2c93 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/ResearchManager.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/ResearchManager.java @@ -10,7 +10,6 @@ import com.gregtechceu.gtceu.api.recipe.GTRecipeType; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.common.data.GTItems; -import com.gregtechceu.gtceu.common.data.GTRecipeCategories; import com.gregtechceu.gtceu.common.data.GTRecipeTypes; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder; @@ -213,7 +212,6 @@ public List getRepresentativeRecipes() { .notConsumable(copiedStick) .outputItems(resultStick) .duration(DURATION).EUt(EUT) - .category(GTRecipeCategories.DUMMY) .buildRawRecipe()); } } diff --git a/src/main/resources/assets/gtceu/textures/gui/icon/arc_furnace_recycling.png b/src/main/resources/assets/gtceu/textures/gui/icon/category/arc_furnace_recycling.png similarity index 100% rename from src/main/resources/assets/gtceu/textures/gui/icon/arc_furnace_recycling.png rename to src/main/resources/assets/gtceu/textures/gui/icon/category/arc_furnace_recycling.png diff --git a/src/main/resources/assets/gtceu/textures/gui/icon/extractor_recycling.png b/src/main/resources/assets/gtceu/textures/gui/icon/category/extractor_recycling.png similarity index 100% rename from src/main/resources/assets/gtceu/textures/gui/icon/extractor_recycling.png rename to src/main/resources/assets/gtceu/textures/gui/icon/category/extractor_recycling.png diff --git a/src/main/resources/assets/gtceu/textures/gui/icon/macerator_recycling.png b/src/main/resources/assets/gtceu/textures/gui/icon/category/macerator_recycling.png similarity index 100% rename from src/main/resources/assets/gtceu/textures/gui/icon/macerator_recycling.png rename to src/main/resources/assets/gtceu/textures/gui/icon/category/macerator_recycling.png