Skip to content

Commit

Permalink
Update JEI and add a scrolling ingredient grid for showing recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Oct 1, 2024
1 parent a43f347 commit cb2bbc6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import mezz.jei.api.registration.IRecipeRegistration;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeManager;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand All @@ -30,20 +32,24 @@ public void registerCategories(IRecipeCategoryRegistration registration) {

@Override
public void registerRecipes(IRecipeRegistration registration) {
Objects.requireNonNull(Minecraft.getInstance().level).getRecipeManager()
.getAllRecipesFor(ModRecipeTypes.WORKBENCH.get()).forEach(recipe ->
recipe.value().ingredients().forEach(ingredient ->
registration.addRecipes(WorkbenchCategory.RECIPE, List.of(ingredient))));
RecipeManager recipeManager = Objects.requireNonNull(Minecraft.getInstance().level).getRecipeManager();
recipeManager.getAllRecipesFor(ModRecipeTypes.WORKBENCH.get())
.forEach(recipe -> {
List<Ingredient> ingredients = recipe.value().ingredients();
registration.addRecipes(WorkbenchCategory.RECIPE, ingredients);
});
}

@Override
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
registration.addRecipeCatalyst(ModItems.BOTANIST_WORKBENCH.get().getDefaultInstance(), WorkbenchCategory.RECIPE);
registration.addRecipeCatalyst(ModItems.GLASSBLOWER.get().getDefaultInstance(), WorkbenchCategory.RECIPE);
registration.addRecipeCatalyst(ModItems.CARPENTERS_TABLE.get().getDefaultInstance(), WorkbenchCategory.RECIPE);
registration.addRecipeCatalyst(ModItems.LOOM_TABLE.get().getDefaultInstance(), WorkbenchCategory.RECIPE);
registration.addRecipeCatalyst(ModItems.MASON_TABLE.get().getDefaultInstance(), WorkbenchCategory.RECIPE);
registration.addRecipeCatalyst(ModItems.ALCHEMY_BENCH.get().getDefaultInstance(), WorkbenchCategory.RECIPE);
registration.addRecipeCatalyst(ModItems.TINKERING_TABLE.get().getDefaultInstance(), WorkbenchCategory.RECIPE);
registration.addRecipeCatalysts(WorkbenchCategory.RECIPE,
ModItems.BOTANIST_WORKBENCH.get(),
ModItems.GLASSBLOWER.get(),
ModItems.CARPENTERS_TABLE.get(),
ModItems.LOOM_TABLE.get(),
ModItems.MASON_TABLE.get(),
ModItems.ALCHEMY_BENCH.get(),
ModItems.TINKERING_TABLE.get()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,54 @@
import earth.terrarium.chipped.Chipped;
import earth.terrarium.chipped.common.registry.ModItems;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable;
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 net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;

public record WorkbenchCategory(IGuiHelper guiHelper) implements IRecipeCategory<Ingredient> {
import java.util.List;

public class WorkbenchCategory extends AbstractRecipeCategory<Ingredient> {
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(Chipped.MOD_ID, "workbench");
public static final RecipeType<Ingredient> RECIPE = new RecipeType<>(ID, Ingredient.class);

private static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath("jei", "textures/jei/gui/gui_vanilla.png");

@Override
public RecipeType<Ingredient> getRecipeType() {
return RECIPE;
}

@Override
public Component getTitle() {
return Component.translatable("container.chipped.workbench");
public WorkbenchCategory(IGuiHelper guiHelper) {
super(
RECIPE,
Component.translatable("container.chipped.workbench"),
guiHelper.createDrawableItemLike(ModItems.MASON_TABLE.get()),
142,
110
);
}

@Override
public IDrawable getBackground() {
return guiHelper.createDrawable(TEXTURE, 0, 220, 82, 34);
public void setRecipe(IRecipeLayoutBuilder builder, Ingredient recipe, IFocusGroup focuses) {
builder.addInputSlot(6, 9)
.setStandardSlotBackground()
.setPosition(0, 0, getWidth(), getHeight(), HorizontalAlignment.CENTER, VerticalAlignment.TOP)
.addIngredients(recipe);

for (ItemStack stack : recipe.getItems()) {
builder.addOutputSlot()
.addItemStack(stack);
}
}

@Override
public IDrawable getIcon() {
return guiHelper.createDrawableItemStack(ModItems.MASON_TABLE.get().getDefaultInstance());
}
public void createRecipeExtras(IRecipeExtrasBuilder builder, Ingredient recipe, IFocusGroup focuses) {
List<IRecipeSlotDrawable> outputs = builder.getRecipeSlots().getSlots(RecipeIngredientRole.OUTPUT);

@Override
public void setRecipe(IRecipeLayoutBuilder builder, Ingredient recipe, IFocusGroup focuses) {
builder.addSlot(RecipeIngredientRole.INPUT, 1, 9).addIngredients(recipe);
builder.addSlot(RecipeIngredientRole.OUTPUT, 61, 9).addIngredients(recipe);
builder.addScrollGridWidget(outputs, 7, 5)
.setPosition(0, 0, getWidth(), getHeight(), HorizontalAlignment.CENTER, VerticalAlignment.BOTTOM);
}
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ parchmentVersion=2024.07.28

modMenuVersion=11.0.2
reiVersion=16.0.754
jeiVersion=19.14.2.147
# jei versions: https://github.com/mezz/JustEnoughItems#1211
jeiVersion=19.19.3.224

resourcefulLibVersion=3.0.9
athenaVersion=4.0.1
7 changes: 7 additions & 0 deletions neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ modId = "athena"
type="required"
versionRange = "[4.0.0,)"
ordering = "NONE"
side = "CLIENT"

[[dependencies.chipped]]
modId = "jei"
type="optional"
versionRange = "[19.19.3,)"
ordering = "NONE"
side = "CLIENT"

0 comments on commit cb2bbc6

Please sign in to comment.