Skip to content

Commit

Permalink
Update JEI
Browse files Browse the repository at this point in the history
  • Loading branch information
Edivad99 committed Nov 10, 2024
1 parent c7c379f commit c04bf38
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 283 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
18 changes: 10 additions & 8 deletions src/main/java/mods/railcraft/integrations/jei/RecipeTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<RollingRecipe> ROLLING_MACHINE =
RecipeType.create(RailcraftConstants.ID, "rolling_machine", RollingRecipe.class);
public static final RecipeType<RecipeHolder<RollingRecipe>> ROLLING_MACHINE =
RecipeType.createFromVanilla(RailcraftRecipeTypes.ROLLING.get());

public static final RecipeType<CokeOvenRecipe> COKE_OVEN =
RecipeType.create(RailcraftConstants.ID, "coke_oven", CokeOvenRecipe.class);
public static final RecipeType<RecipeHolder<CokeOvenRecipe>> COKE_OVEN =
RecipeType.createFromVanilla(RailcraftRecipeTypes.COKING.get());

public static final RecipeType<BlastFurnaceRecipe> BLAST_FURNACE =
RecipeType.create(RailcraftConstants.ID, "blast_furnace", BlastFurnaceRecipe.class);
public static final RecipeType<RecipeHolder<BlastFurnaceRecipe>> BLAST_FURNACE =
RecipeType.createFromVanilla(RailcraftRecipeTypes.BLASTING.get());

public static final RecipeType<CrusherRecipe> CRUSHER =
RecipeType.create(RailcraftConstants.ID, "crusher", CrusherRecipe.class);
public static final RecipeType<RecipeHolder<CrusherRecipe>> CRUSHER =
RecipeType.createFromVanilla(RailcraftRecipeTypes.CRUSHING.get());

public static final RecipeType<SolidBoilerJEIRecipe> SOLID_BOILER =
RecipeType.create(RailcraftConstants.ID, "solid_boiler", SolidBoilerJEIRecipe.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<BlastFurnaceRecipe> {
public class BlastFurnaceRecipeCategory extends
AbstractRecipeCategory<RecipeHolder<BlastFurnaceRecipe>> {

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<BlastFurnaceRecipe> 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<BlastFurnaceRecipe> 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<BlastFurnaceRecipe> 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<BlastFurnaceRecipe> 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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CokeOvenRecipe> {
public class CokeOvenRecipeCategory extends AbstractRecipeCategory<RecipeHolder<CokeOvenRecipe>> {

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<CokeOvenRecipe> 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<CokeOvenRecipe> 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<CokeOvenRecipe> 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<CokeOvenRecipe> 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);
}
}
Loading

0 comments on commit c04bf38

Please sign in to comment.