From c04bf3872ae53f94d0741827c5ba6fb18b2af3ba Mon Sep 17 00:00:00 2001 From: Davide Albiero Date: Sun, 10 Nov 2024 16:57:52 +0100 Subject: [PATCH] Update JEI --- gradle.properties | 2 +- .../integrations/jei/RailcraftJeiPlugin.java | 12 +-- .../integrations/jei/RecipeTypes.java | 18 ++-- .../category/BlastFurnaceRecipeCategory.java | 91 ++++++++---------- .../jei/category/CokeOvenRecipeCategory.java | 93 +++++++++---------- .../jei/category/CrusherRecipeCategory.java | 55 +++++------ .../category/FluidBoilerRecipeCategory.java | 87 ++++++++--------- .../jei/category/RollingRecipeCategory.java | 47 +++------- .../category/SolidBoilerRecipeCategory.java | 85 ++++++++--------- .../item/crafting/RailcraftRecipeTypes.java | 7 +- .../resources/META-INF/neoforge.mods.toml | 2 +- 11 files changed, 216 insertions(+), 283 deletions(-) diff --git a/gradle.properties b/gradle.properties index 37396335d..0b9692fdb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ mod_license=https://github.com/railcraft-reborn/railcraft/blob/1.21.x/LICENSE.md # Dependencies jupiter_version=5.10.2 -jei_version=19.8.5.118 +jei_version=19.21.0.247 emi_version=1.1.18 patchouli_version=1.21-87-NEOFORGE-SNAPSHOT jade_id=5591256 diff --git a/src/main/java/mods/railcraft/integrations/jei/RailcraftJeiPlugin.java b/src/main/java/mods/railcraft/integrations/jei/RailcraftJeiPlugin.java index b9db6a5a8..fe1575d39 100644 --- a/src/main/java/mods/railcraft/integrations/jei/RailcraftJeiPlugin.java +++ b/src/main/java/mods/railcraft/integrations/jei/RailcraftJeiPlugin.java @@ -105,17 +105,13 @@ public void registerRecipeTransferHandlers(IRecipeTransferRegistration registrat public void registerRecipes(IRecipeRegistration registration) { var recipeManager = Minecraft.getInstance().level.getRecipeManager(); registration.addRecipes(RecipeTypes.ROLLING_MACHINE, - recipeManager.getAllRecipesFor(RailcraftRecipeTypes.ROLLING.get()).stream() - .map(RecipeHolder::value).toList()); + recipeManager.getAllRecipesFor(RailcraftRecipeTypes.ROLLING.get())); registration.addRecipes(RecipeTypes.COKE_OVEN, - recipeManager.getAllRecipesFor(RailcraftRecipeTypes.COKING.get()).stream() - .map(RecipeHolder::value).toList()); + recipeManager.getAllRecipesFor(RailcraftRecipeTypes.COKING.get())); registration.addRecipes(RecipeTypes.BLAST_FURNACE, - recipeManager.getAllRecipesFor(RailcraftRecipeTypes.BLASTING.get()).stream() - .map(RecipeHolder::value).toList()); + recipeManager.getAllRecipesFor(RailcraftRecipeTypes.BLASTING.get())); registration.addRecipes(RecipeTypes.CRUSHER, - recipeManager.getAllRecipesFor(RailcraftRecipeTypes.CRUSHING.get()).stream() - .map(RecipeHolder::value).toList()); + recipeManager.getAllRecipesFor(RailcraftRecipeTypes.CRUSHING.get())); registration.addRecipes(RecipeTypes.SOLID_BOILER, SolidBoilerRecipeCategory.getBoilerRecipes()); registration.addRecipes(RecipeTypes.FLUID_BOILER, FluidBoilerRecipeCategory.getBoilerRecipes()); diff --git a/src/main/java/mods/railcraft/integrations/jei/RecipeTypes.java b/src/main/java/mods/railcraft/integrations/jei/RecipeTypes.java index f81a73b74..0ef0fd22b 100644 --- a/src/main/java/mods/railcraft/integrations/jei/RecipeTypes.java +++ b/src/main/java/mods/railcraft/integrations/jei/RecipeTypes.java @@ -7,21 +7,23 @@ import mods.railcraft.world.item.crafting.BlastFurnaceRecipe; import mods.railcraft.world.item.crafting.CokeOvenRecipe; import mods.railcraft.world.item.crafting.CrusherRecipe; +import mods.railcraft.world.item.crafting.RailcraftRecipeTypes; import mods.railcraft.world.item.crafting.RollingRecipe; +import net.minecraft.world.item.crafting.RecipeHolder; public class RecipeTypes { - public static final RecipeType ROLLING_MACHINE = - RecipeType.create(RailcraftConstants.ID, "rolling_machine", RollingRecipe.class); + public static final RecipeType> ROLLING_MACHINE = + RecipeType.createFromVanilla(RailcraftRecipeTypes.ROLLING.get()); - public static final RecipeType COKE_OVEN = - RecipeType.create(RailcraftConstants.ID, "coke_oven", CokeOvenRecipe.class); + public static final RecipeType> COKE_OVEN = + RecipeType.createFromVanilla(RailcraftRecipeTypes.COKING.get()); - public static final RecipeType BLAST_FURNACE = - RecipeType.create(RailcraftConstants.ID, "blast_furnace", BlastFurnaceRecipe.class); + public static final RecipeType> BLAST_FURNACE = + RecipeType.createFromVanilla(RailcraftRecipeTypes.BLASTING.get()); - public static final RecipeType CRUSHER = - RecipeType.create(RailcraftConstants.ID, "crusher", CrusherRecipe.class); + public static final RecipeType> CRUSHER = + RecipeType.createFromVanilla(RailcraftRecipeTypes.CRUSHING.get()); public static final RecipeType SOLID_BOILER = RecipeType.create(RailcraftConstants.ID, "solid_boiler", SolidBoilerJEIRecipe.class); diff --git a/src/main/java/mods/railcraft/integrations/jei/category/BlastFurnaceRecipeCategory.java b/src/main/java/mods/railcraft/integrations/jei/category/BlastFurnaceRecipeCategory.java index 977d213ab..7c6f04eba 100644 --- a/src/main/java/mods/railcraft/integrations/jei/category/BlastFurnaceRecipeCategory.java +++ b/src/main/java/mods/railcraft/integrations/jei/category/BlastFurnaceRecipeCategory.java @@ -2,15 +2,15 @@ import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableAnimated; import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +import mezz.jei.api.gui.placement.HorizontalAlignment; +import mezz.jei.api.gui.placement.VerticalAlignment; +import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.recipe.IFocusGroup; import mezz.jei.api.recipe.RecipeIngredientRole; -import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.api.recipe.category.AbstractRecipeCategory; import mods.railcraft.Translations; -import mods.railcraft.api.core.RailcraftConstants; import mods.railcraft.integrations.jei.RailcraftJeiPlugin; import mods.railcraft.integrations.jei.RecipeTypes; import mods.railcraft.world.item.RailcraftItems; @@ -19,81 +19,70 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; -public class BlastFurnaceRecipeCategory implements IRecipeCategory { +public class BlastFurnaceRecipeCategory extends + AbstractRecipeCategory> { private static final int WIDTH = 82; private static final int HEIGHT = 54; - private static final ResourceLocation BACKGROUND = - RailcraftConstants.rl("textures/gui/container/blast_furnace.png"); - - private final IDrawable background, icon, flame, arrow; + private final IDrawable flame, arrow; public BlastFurnaceRecipeCategory(IGuiHelper guiHelper) { - this.background = guiHelper.createDrawable(BACKGROUND, 55, 16, WIDTH, HEIGHT); - var itemStack = new ItemStack(RailcraftItems.BLAST_FURNACE_BRICKS.get()); - this.icon = guiHelper.createDrawableItemStack(itemStack); - - this.flame = guiHelper.createAnimatedDrawable( - guiHelper.createDrawable(BACKGROUND, 176, 0, 14, 14), - 200, IDrawableAnimated.StartDirection.TOP, true); - this.arrow = guiHelper.createAnimatedDrawable( - guiHelper.createDrawable(BACKGROUND, 177, 14, 22, 15), - 200, IDrawableAnimated.StartDirection.LEFT, false); - } - - @Override - public RecipeType getRecipeType() { - return RecipeTypes.BLAST_FURNACE; - } + super( + RecipeTypes.BLAST_FURNACE, + Component.translatable(Translations.Jei.BLAST_FURNACE), + guiHelper.createDrawableItemLike(RailcraftItems.BLAST_FURNACE_BRICKS.get()), + WIDTH, + HEIGHT + ); - @Override - public Component getTitle() { - return Component.translatable(Translations.Jei.BLAST_FURNACE); + this.flame = guiHelper.createAnimatedRecipeFlame(200); + this.arrow = guiHelper.createAnimatedRecipeArrow(200); } @Override - public IDrawable getBackground() { - return this.background; - } - - @Override - public IDrawable getIcon() { - return this.icon; - } - - @Override - public void draw(BlastFurnaceRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, - double mouseX, double mouseY) { + public void draw(RecipeHolder recipeHolder, IRecipeSlotsView recipeSlotsView, + GuiGraphics guiGraphics, double mouseX, double mouseY) { this.flame.draw(guiGraphics, 1, 20); this.arrow.draw(guiGraphics, 25, 19); + } + @Override + public void createRecipeExtras(IRecipeExtrasBuilder builder, + RecipeHolder recipeHolder, IFocusGroup focuses) { + var recipe = recipeHolder.value(); int cookTime = recipe.getCookingTime(); if (cookTime > 0) { int cookTimeSeconds = cookTime / SharedConstants.TICKS_PER_SECOND; - var timeString = Component.translatable("gui.jei.category.smelting.time.seconds", - cookTimeSeconds); - var font = Minecraft.getInstance().font; - int stringWidth = font.width(timeString); - guiGraphics.drawString(font, timeString, getBackground().getWidth() - stringWidth - 30, - 45, RailcraftJeiPlugin.TEXT_COLOR, false); + var timeString = + Component.translatable("gui.jei.category.smelting.time.seconds", cookTimeSeconds); + builder.addText(timeString, WIDTH, 45) + .setTextAlignment(VerticalAlignment.BOTTOM) + .setTextAlignment(HorizontalAlignment.CENTER) + .setColor(RailcraftJeiPlugin.TEXT_COLOR); } } @Override - public void setRecipe(IRecipeLayoutBuilder builder, BlastFurnaceRecipe recipe, + public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder recipeHolder, IFocusGroup focuses) { + var recipe = recipeHolder.value(); var ingredients = recipe.getIngredients(); builder - .addSlot(RecipeIngredientRole.INPUT, 1, 1) + .addInputSlot(1, 1) + .setStandardSlotBackground() .addIngredients(ingredients.getFirst()); + builder.addSlot(RecipeIngredientRole.RENDER_ONLY, 1, 37) + .setStandardSlotBackground(); builder - .addSlot(RecipeIngredientRole.OUTPUT, 61, 5) + .addOutputSlot(61, 5) + .setOutputSlotBackground() .addItemStack(recipe.getResultItem(Minecraft.getInstance().level.registryAccess())); - builder.addSlot(RecipeIngredientRole.OUTPUT, 61, 37) + builder.addOutputSlot(61, 37) + .setStandardSlotBackground() .addItemStack(new ItemStack(RailcraftItems.SLAG.get(), recipe.getSlagOutput())); } } diff --git a/src/main/java/mods/railcraft/integrations/jei/category/CokeOvenRecipeCategory.java b/src/main/java/mods/railcraft/integrations/jei/category/CokeOvenRecipeCategory.java index 30a7a8612..ffdd410dc 100644 --- a/src/main/java/mods/railcraft/integrations/jei/category/CokeOvenRecipeCategory.java +++ b/src/main/java/mods/railcraft/integrations/jei/category/CokeOvenRecipeCategory.java @@ -2,14 +2,14 @@ import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableAnimated; import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +import mezz.jei.api.gui.placement.HorizontalAlignment; +import mezz.jei.api.gui.placement.VerticalAlignment; +import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.neoforge.NeoForgeTypes; import mezz.jei.api.recipe.IFocusGroup; -import mezz.jei.api.recipe.RecipeIngredientRole; -import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.api.recipe.category.AbstractRecipeCategory; import mods.railcraft.Translations; import mods.railcraft.api.core.RailcraftConstants; import mods.railcraft.integrations.jei.RailcraftJeiPlugin; @@ -21,81 +21,74 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; -public class CokeOvenRecipeCategory implements IRecipeCategory { +public class CokeOvenRecipeCategory extends AbstractRecipeCategory> { - private static final int WIDTH = 124; + private static final int WIDTH = 127; private static final int HEIGHT = 49; private static final ResourceLocation BACKGROUND = RailcraftConstants.rl("textures/gui/container/coke_oven.png"); - private final IDrawable background, icon, flame, arrow; + private final IDrawable tankBackground, tankOverlay, flame, arrow; public CokeOvenRecipeCategory(IGuiHelper guiHelper) { - this.background = guiHelper.createDrawable(BACKGROUND, 15, 23, WIDTH, HEIGHT); - var itemStack = new ItemStack(RailcraftItems.COKE_OVEN_BRICKS.get()); - this.icon = guiHelper.createDrawableItemStack(itemStack); + super( + RecipeTypes.COKE_OVEN, + Component.translatable(Translations.Jei.COKE_OVEN), + guiHelper.createDrawableItemLike(RailcraftItems.COKE_OVEN_BRICKS.get()), + WIDTH, + HEIGHT + ); - this.flame = guiHelper.createAnimatedDrawable( - guiHelper.createDrawable(BACKGROUND, 176, 47, 14, 14), - 200, IDrawableAnimated.StartDirection.TOP, true); - this.arrow = guiHelper.createAnimatedDrawable( - guiHelper.createDrawable(BACKGROUND, 176, 61, 22, 15), - 200, IDrawableAnimated.StartDirection.LEFT, false); + this.tankBackground = guiHelper.createDrawable(BACKGROUND, 89, 23, 50, 49); + this.tankOverlay = guiHelper.createDrawable(BACKGROUND, 176, 0, 48, 47); + this.flame = guiHelper.createAnimatedRecipeFlame(200); + this.arrow = guiHelper.createAnimatedRecipeArrow(200); } @Override - public RecipeType getRecipeType() { - return RecipeTypes.COKE_OVEN; - } - - @Override - public Component getTitle() { - return Component.translatable(Translations.Jei.COKE_OVEN); - } - - @Override - public IDrawable getBackground() { - return this.background; - } - - @Override - public IDrawable getIcon() { - return this.icon; + public void draw(RecipeHolder recipeHolder, IRecipeSlotsView recipeSlotsView, + GuiGraphics guiGraphics, double mouseX, double mouseY) { + this.flame.draw(guiGraphics, 1, 3); + this.arrow.draw(guiGraphics, 20, 21); } @Override - public void draw(CokeOvenRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, - double mouseX, double mouseY) { - this.flame.draw(guiGraphics, 1, 3); - this.arrow.draw(guiGraphics, 19, 21); - + public void createRecipeExtras(IRecipeExtrasBuilder builder, + RecipeHolder recipeHolder, IFocusGroup focuses) { + var recipe = recipeHolder.value(); int cookTime = recipe.getCookingTime(); if (cookTime > 0) { int cookTimeSeconds = cookTime / SharedConstants.TICKS_PER_SECOND; - var timeString = Component.translatable("gui.jei.category.smelting.time.seconds", - cookTimeSeconds); - var font = Minecraft.getInstance().font; - int stringWidth = font.width(timeString); - guiGraphics.drawString(font, timeString, getBackground().getWidth() - stringWidth - 80, 43, - RailcraftJeiPlugin.TEXT_COLOR, false); + var timeString = + Component.translatable("gui.jei.category.smelting.time.seconds", cookTimeSeconds); + builder.addText(timeString, WIDTH - 70, 50) + .setTextAlignment(VerticalAlignment.BOTTOM) + .setTextAlignment(HorizontalAlignment.CENTER) + .setColor(RailcraftJeiPlugin.TEXT_COLOR); } } @Override - public void setRecipe(IRecipeLayoutBuilder builder, CokeOvenRecipe recipe, IFocusGroup focuses) { + public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder recipeHolder, + IFocusGroup focuses) { + var recipe = recipeHolder.value(); var ingredients = recipe.getIngredients(); builder - .addSlot(RecipeIngredientRole.INPUT, 1, 20) + .addInputSlot(1, 20) + .setStandardSlotBackground() .addIngredients(ingredients.getFirst()); builder - .addSlot(RecipeIngredientRole.OUTPUT, 46, 20) + .addOutputSlot(49, 20) + .setOutputSlotBackground() .addItemStack(recipe.getResultItem(Minecraft.getInstance().level.registryAccess())); // Not the actual capacity, but is 10000 for a better visibility - builder.addSlot(RecipeIngredientRole.OUTPUT, 75, 1) + builder.addOutputSlot(78, 1) .addIngredient(NeoForgeTypes.FLUID_STACK, recipe.getCreosote()) - .setFluidRenderer(10_000, true, 48, 47); + .setFluidRenderer(10_000, true, 48, 47) + .setOverlay(tankOverlay, 0, 0) + .setBackground(tankBackground, -1, -1); } } diff --git a/src/main/java/mods/railcraft/integrations/jei/category/CrusherRecipeCategory.java b/src/main/java/mods/railcraft/integrations/jei/category/CrusherRecipeCategory.java index e70b26c01..181ae0099 100644 --- a/src/main/java/mods/railcraft/integrations/jei/category/CrusherRecipeCategory.java +++ b/src/main/java/mods/railcraft/integrations/jei/category/CrusherRecipeCategory.java @@ -6,9 +6,7 @@ import mezz.jei.api.gui.ingredient.IRecipeSlotsView; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.recipe.IFocusGroup; -import mezz.jei.api.recipe.RecipeIngredientRole; -import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.api.recipe.category.AbstractRecipeCategory; import mods.railcraft.Translations; import mods.railcraft.api.core.RailcraftConstants; import mods.railcraft.integrations.jei.RecipeTypes; @@ -19,8 +17,9 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; -public class CrusherRecipeCategory implements IRecipeCategory { +public class CrusherRecipeCategory extends AbstractRecipeCategory> { private static final int WIDTH = 144; private static final int HEIGHT = 54; @@ -28,50 +27,38 @@ public class CrusherRecipeCategory implements IRecipeCategory { private static final ResourceLocation BACKGROUND = RailcraftConstants.rl("textures/gui/container/crusher.png"); - private final IDrawable background, icon, arrow; + private final IDrawable background, arrow; public CrusherRecipeCategory(IGuiHelper guiHelper) { - this.background = guiHelper.createDrawable(BACKGROUND, 0, 171, WIDTH, HEIGHT); - var itemStack = new ItemStack(RailcraftItems.CRUSHER.get()); - this.icon = guiHelper.createDrawableItemStack(itemStack); + super( + RecipeTypes.CRUSHER, + Component.translatable(Translations.Jei.CRUSHER), + guiHelper.createDrawableItemLike(RailcraftItems.CRUSHER.get()), + WIDTH, + HEIGHT + ); + this.background = guiHelper.createDrawable(BACKGROUND, 0, 171, WIDTH, HEIGHT); this.arrow = guiHelper.createAnimatedDrawable( guiHelper.createDrawable(BACKGROUND, 144, 171, 29, 53), - 500, IDrawableAnimated.StartDirection.LEFT, false); - } - - @Override - public RecipeType getRecipeType() { - return RecipeTypes.CRUSHER; - } - - @Override - public Component getTitle() { - return Component.translatable(Translations.Jei.CRUSHER); - } - - @Override - public IDrawable getBackground() { - return this.background; - } - - @Override - public IDrawable getIcon() { - return this.icon; + 200, IDrawableAnimated.StartDirection.LEFT, false); } @Override - public void draw(CrusherRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, - double mouseX, double mouseY) { + public void draw(RecipeHolder recipeHolder, IRecipeSlotsView recipeSlotsView, + GuiGraphics guiGraphics, double mouseX, double mouseY) { + this.background.draw(guiGraphics); this.arrow.draw(guiGraphics, 58, 0); } @Override - public void setRecipe(IRecipeLayoutBuilder builder, CrusherRecipe recipe, IFocusGroup focuses) { + public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder recipeHolder, + IFocusGroup focuses) { + var recipe = recipeHolder.value(); var ingredients = recipe.getIngredients(); builder - .addSlot(RecipeIngredientRole.INPUT, 19, 19) + .addInputSlot(19, 19) .addIngredients(ingredients.getFirst()); var outputs = recipe.getProbabilityOutputs(); @@ -83,7 +70,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, CrusherRecipe recipe, IFocus itemStack = outputs.get(index - 1).getOutput(); } var recipeLayout = builder - .addSlot(RecipeIngredientRole.OUTPUT, 91 + x * 18, y * 18 + 1) + .addOutputSlot(91 + x * 18, y * 18 + 1) .addItemStack(itemStack); if (!itemStack.isEmpty()) { recipeLayout.addRichTooltipCallback((recipeSlotView, tooltip) -> { diff --git a/src/main/java/mods/railcraft/integrations/jei/category/FluidBoilerRecipeCategory.java b/src/main/java/mods/railcraft/integrations/jei/category/FluidBoilerRecipeCategory.java index 4db879688..ba273ae8f 100644 --- a/src/main/java/mods/railcraft/integrations/jei/category/FluidBoilerRecipeCategory.java +++ b/src/main/java/mods/railcraft/integrations/jei/category/FluidBoilerRecipeCategory.java @@ -3,14 +3,14 @@ import java.util.List; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableAnimated; import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +import mezz.jei.api.gui.placement.HorizontalAlignment; +import mezz.jei.api.gui.placement.VerticalAlignment; +import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.neoforge.NeoForgeTypes; import mezz.jei.api.recipe.IFocusGroup; -import mezz.jei.api.recipe.RecipeIngredientRole; -import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.api.recipe.category.AbstractRecipeCategory; import mods.railcraft.Translations; import mods.railcraft.api.core.RailcraftConstants; import mods.railcraft.integrations.jei.RailcraftJeiPlugin; @@ -18,15 +18,13 @@ import mods.railcraft.integrations.jei.recipe.FluidBoilerJEIRecipe; import mods.railcraft.world.item.RailcraftItems; import mods.railcraft.world.level.material.RailcraftFluids; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluids; import net.neoforged.neoforge.fluids.FluidStack; -public class FluidBoilerRecipeCategory implements IRecipeCategory { +public class FluidBoilerRecipeCategory extends AbstractRecipeCategory { public static final int WIDTH = 117; public static final int HEIGHT = 54; @@ -34,62 +32,59 @@ public class FluidBoilerRecipeCategory implements IRecipeCategory getRecipeType() { - return RecipeTypes.FLUID_BOILER; - } - - @Override - public Component getTitle() { - return Component.translatable(Translations.Jei.FLUID_BOILER); - } + super( + RecipeTypes.FLUID_BOILER, + Component.translatable(Translations.Jei.FLUID_BOILER), + guiHelper.createDrawableItemLike(RailcraftItems.FLUID_FUELED_FIREBOX.get()), + WIDTH, + HEIGHT + ); - @Override - public IDrawable getBackground() { - return this.background; - } - - @Override - public IDrawable getIcon() { - return this.icon; + this.tankBackground = guiHelper.createDrawable(BACKGROUND, 16, 22, 18, 49); + this.tankOverlay = guiHelper.createDrawable(BACKGROUND, 176, 0, 16, 47); + this.heatBackground = guiHelper.createDrawable(BACKGROUND, 39, 24, 8, 45); + this.heatOverlay = guiHelper.createDrawable(BACKGROUND, 176, 61, 6, 43); + this.flame = guiHelper.createAnimatedRecipeFlame(200); } @Override public void draw(FluidBoilerJEIRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) { + this.heatBackground.draw(guiGraphics, 23, 5); + this.heatOverlay.draw(guiGraphics, 23 + 1, 5 + 1); this.flame.draw(guiGraphics, 46, 19); - this.bar.draw(guiGraphics, 24, 6); + } - var font = Minecraft.getInstance().font; - var temp = recipe.temperature() + "°C"; - guiGraphics.drawString(font, temp, getBackground().getWidth() - font.width(temp) - 50, 43, - RailcraftJeiPlugin.TEXT_COLOR, false); + @Override + public void createRecipeExtras(IRecipeExtrasBuilder builder, FluidBoilerJEIRecipe recipe, + IFocusGroup focuses) { + var text = recipe.temperature() + "°C"; + builder.addText(Component.literal(text), WIDTH - 10, 50) + .setTextAlignment(VerticalAlignment.BOTTOM) + .setTextAlignment(HorizontalAlignment.CENTER) + .setColor(RailcraftJeiPlugin.TEXT_COLOR); } @Override public void setRecipe(IRecipeLayoutBuilder builder, FluidBoilerJEIRecipe recipe, IFocusGroup focuses) { - builder.addSlot(RecipeIngredientRole.OUTPUT, 1, 4) + builder.addOutputSlot(1, 4) .addIngredient(NeoForgeTypes.FLUID_STACK, recipe.steam()) - .setFluidRenderer(10_000, true, 16, 47); - builder.addSlot(RecipeIngredientRole.INPUT, 73, 4) + .setFluidRenderer(10_000, true, 16, 47) + .setOverlay(tankOverlay, 0, 0) + .setBackground(tankBackground, -1, -1); + builder.addInputSlot(73, 4) .addIngredient(NeoForgeTypes.FLUID_STACK, recipe.fuel()) - .setFluidRenderer(10_000, true, 16, 47); - builder.addSlot(RecipeIngredientRole.INPUT, 100, 4) + .setFluidRenderer(10_000, true, 16, 47) + .setOverlay(tankOverlay, 0, 0) + .setBackground(tankBackground, -1, -1); + builder.addInputSlot(100, 4) .addIngredient(NeoForgeTypes.FLUID_STACK, recipe.water()) - .setFluidRenderer(10_000, true, 16, 47); + .setFluidRenderer(10_000, true, 16, 47) + .setOverlay(tankOverlay, 0, 0) + .setBackground(tankBackground, -1, -1); } public static List getBoilerRecipes() { diff --git a/src/main/java/mods/railcraft/integrations/jei/category/RollingRecipeCategory.java b/src/main/java/mods/railcraft/integrations/jei/category/RollingRecipeCategory.java index 7a34f20c8..0b545b1bb 100644 --- a/src/main/java/mods/railcraft/integrations/jei/category/RollingRecipeCategory.java +++ b/src/main/java/mods/railcraft/integrations/jei/category/RollingRecipeCategory.java @@ -2,61 +2,40 @@ import java.util.List; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; -import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.ingredient.ICraftingGridHelper; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.recipe.IFocusGroup; -import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.api.recipe.category.AbstractRecipeCategory; import mods.railcraft.Translations; import mods.railcraft.integrations.jei.RecipeTypes; import mods.railcraft.world.item.RailcraftItems; import mods.railcraft.world.item.crafting.RollingRecipe; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; -public class RollingRecipeCategory implements IRecipeCategory { +public class RollingRecipeCategory extends AbstractRecipeCategory> { private static final int WIDTH = 116; private static final int HEIGHT = 54; - private static final ResourceLocation CRAFTING_TABLE = - ResourceLocation.withDefaultNamespace("textures/gui/container/crafting_table.png"); - - private final IDrawable background, icon; private final ICraftingGridHelper craftingGridHelper; public RollingRecipeCategory(IGuiHelper guiHelper) { - this.background = guiHelper.createDrawable(CRAFTING_TABLE, 29, 16, WIDTH, HEIGHT); - var itemStack = new ItemStack(RailcraftItems.MANUAL_ROLLING_MACHINE.get()); - this.icon = guiHelper.createDrawableItemStack(itemStack); + super( + RecipeTypes.ROLLING_MACHINE, + Component.translatable(Translations.Jei.METAL_ROLLING), + guiHelper.createDrawableItemLike(RailcraftItems.MANUAL_ROLLING_MACHINE.get()), + WIDTH, + HEIGHT + ); this.craftingGridHelper = guiHelper.createCraftingGridHelper(); } @Override - public RecipeType getRecipeType() { - return RecipeTypes.ROLLING_MACHINE; - } - - @Override - public Component getTitle() { - return Component.translatable(Translations.Jei.METAL_ROLLING); - } - - @Override - public IDrawable getBackground() { - return this.background; - } - - @Override - public IDrawable getIcon() { - return this.icon; - } - - @Override - public void setRecipe(IRecipeLayoutBuilder builder, RollingRecipe recipe, IFocusGroup focuses) { + public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder recipeHolder, + IFocusGroup focuses) { + var recipe = recipeHolder.value(); var registryAccess = Minecraft.getInstance().level.registryAccess(); this.craftingGridHelper.createAndSetOutputs(builder, List.of(recipe.getResultItem(registryAccess))); int width = recipe.getWidth(); diff --git a/src/main/java/mods/railcraft/integrations/jei/category/SolidBoilerRecipeCategory.java b/src/main/java/mods/railcraft/integrations/jei/category/SolidBoilerRecipeCategory.java index c01075204..2cb86f4ce 100644 --- a/src/main/java/mods/railcraft/integrations/jei/category/SolidBoilerRecipeCategory.java +++ b/src/main/java/mods/railcraft/integrations/jei/category/SolidBoilerRecipeCategory.java @@ -3,14 +3,15 @@ import java.util.List; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableAnimated; import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +import mezz.jei.api.gui.placement.HorizontalAlignment; +import mezz.jei.api.gui.placement.VerticalAlignment; +import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.neoforge.NeoForgeTypes; import mezz.jei.api.recipe.IFocusGroup; import mezz.jei.api.recipe.RecipeIngredientRole; -import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.api.recipe.category.AbstractRecipeCategory; import mods.railcraft.Translations; import mods.railcraft.api.core.RailcraftConstants; import mods.railcraft.integrations.jei.RailcraftJeiPlugin; @@ -18,75 +19,71 @@ import mods.railcraft.integrations.jei.recipe.SolidBoilerJEIRecipe; import mods.railcraft.world.item.RailcraftItems; import mods.railcraft.world.level.material.RailcraftFluids; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluids; import net.neoforged.neoforge.fluids.FluidStack; -public class SolidBoilerRecipeCategory implements IRecipeCategory { +public class SolidBoilerRecipeCategory extends AbstractRecipeCategory { public static final int WIDTH = 117; public static final int HEIGHT = 54; - public static final ResourceLocation BACKGROUND = + private static final ResourceLocation BACKGROUND = RailcraftConstants.rl("textures/gui/container/solid_fueled_steam_boiler.png"); - private final IDrawable background, icon, flame, bar; + private final IDrawable tankBackground, tankOverlay, heatBackground, heatOverlay, flame; public SolidBoilerRecipeCategory(IGuiHelper guiHelper) { - this.background = guiHelper.createDrawable(BACKGROUND, 16, 19, WIDTH, HEIGHT); - var itemStack = new ItemStack(RailcraftItems.SOLID_FUELED_FIREBOX.get()); - this.icon = guiHelper.createDrawableItemStack(itemStack); - - this.flame = guiHelper.createAnimatedDrawable( - guiHelper.createDrawable(BACKGROUND, 176, 47, 14, 14), - 200, IDrawableAnimated.StartDirection.TOP, true); - this.bar = guiHelper.createDrawable(BACKGROUND, 176, 61, 6, 43); - } - - @Override - public RecipeType getRecipeType() { - return RecipeTypes.SOLID_BOILER; - } - - @Override - public Component getTitle() { - return Component.translatable(Translations.Jei.SOLID_BOILER); - } - - @Override - public IDrawable getBackground() { - return this.background; - } + super( + RecipeTypes.SOLID_BOILER, + Component.translatable(Translations.Jei.SOLID_BOILER), + guiHelper.createDrawableItemLike(RailcraftItems.SOLID_FUELED_FIREBOX.get()), + WIDTH, + HEIGHT + ); - @Override - public IDrawable getIcon() { - return this.icon; + this.tankBackground = guiHelper.createDrawable(BACKGROUND, 16, 22, 18, 49); + this.tankOverlay = guiHelper.createDrawable(BACKGROUND, 176, 0, 16, 47); + this.heatBackground = guiHelper.createDrawable(BACKGROUND, 39, 24, 8, 45); + this.heatOverlay = guiHelper.createDrawable(BACKGROUND, 176, 61, 6, 43); + this.flame = guiHelper.createAnimatedRecipeFlame(200); } @Override public void draw(SolidBoilerJEIRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) { + this.heatBackground.draw(guiGraphics, 23, 5); + this.heatOverlay.draw(guiGraphics, 23 + 1, 5 + 1); this.flame.draw(guiGraphics, 46, 3); - this.bar.draw(guiGraphics, 24, 6); + } - var font = Minecraft.getInstance().font; - var temp = recipe.temperature() + "°C"; - guiGraphics.drawString(font, temp, getBackground().getWidth() - font.width(temp) - 50, 43, - RailcraftJeiPlugin.TEXT_COLOR, false); + @Override + public void createRecipeExtras(IRecipeExtrasBuilder builder, SolidBoilerJEIRecipe recipe, + IFocusGroup focuses) { + var text = recipe.temperature() + "°C"; + builder.addText(Component.literal(text), WIDTH - 10, 50) + .setTextAlignment(VerticalAlignment.BOTTOM) + .setTextAlignment(HorizontalAlignment.CENTER) + .setColor(RailcraftJeiPlugin.TEXT_COLOR); } @Override public void setRecipe(IRecipeLayoutBuilder builder, SolidBoilerJEIRecipe recipe, IFocusGroup focuses) { - builder.addSlot(RecipeIngredientRole.OUTPUT, 1, 4) + builder.addOutputSlot(1, 4) .addIngredient(NeoForgeTypes.FLUID_STACK, recipe.steam()) - .setFluidRenderer(10_000, true, 16, 47); - builder.addSlot(RecipeIngredientRole.INPUT, 100, 4) + .setFluidRenderer(10_000, true, 16, 47) + .setOverlay(tankOverlay, 0, 0) + .setBackground(tankBackground, -1, -1); + builder.addInputSlot(100, 4) .addIngredient(NeoForgeTypes.FLUID_STACK, recipe.water()) - .setFluidRenderer(10_000, true, 16, 47); + .setFluidRenderer(10_000, true, 16, 47) + .setOverlay(tankOverlay, 0, 0) + .setBackground(tankBackground, -1, -1); + + builder.addSlot(RecipeIngredientRole.RENDER_ONLY, 46, 20) + .setStandardSlotBackground(); } public static List getBoilerRecipes() { diff --git a/src/main/java/mods/railcraft/world/item/crafting/RailcraftRecipeTypes.java b/src/main/java/mods/railcraft/world/item/crafting/RailcraftRecipeTypes.java index 125c8e61a..4ba4850c0 100644 --- a/src/main/java/mods/railcraft/world/item/crafting/RailcraftRecipeTypes.java +++ b/src/main/java/mods/railcraft/world/item/crafting/RailcraftRecipeTypes.java @@ -39,11 +39,6 @@ public static void register(IEventBus modEventBus) { } private static > DeferredHolder, RecipeType> register(String name) { - return deferredRegister.register(name, () -> new RecipeType() { - @Override - public String toString() { - return RailcraftConstants.rl(name).toString(); - } - }); + return deferredRegister.register(name, () -> RecipeType.simple(RailcraftConstants.rl(name))); } } diff --git a/src/main/resources/META-INF/neoforge.mods.toml b/src/main/resources/META-INF/neoforge.mods.toml index 98bf10cf5..d4ebd8c1f 100644 --- a/src/main/resources/META-INF/neoforge.mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -33,4 +33,4 @@ issueTrackerURL = "https://github.com/railcraft-reborn/railcraft/issues" modId = "jei" ordering = "NONE" side = "BOTH" - versionRange = "[19.8.5,)" + versionRange = "[19.21.0.247,)"