Skip to content

Commit

Permalink
Show sneaking and consuming item in JEI, closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
PanSzelescik committed Sep 4, 2022
1 parent b9a0d79 commit b45ec38
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Stream<ColorizeRecipe> getRecipes() {
.map(Map.Entry::getValue)
.map(ItemStack::new));

return new ColorizeRecipe(validBlocks, item, result);
return new ColorizeRecipe(validBlocks, item, result, this.requireSneaking(), this.consumeItem());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;

public record ColorizeRecipe(Ingredient validBlocks, Ingredient item, ItemStack result) {
public record ColorizeRecipe(Ingredient validBlocks, Ingredient item, ItemStack result, boolean sneaking, boolean consume) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.api.gui.ingredient.IRecipeSlotTooltipCallback;
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 net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
Expand All @@ -19,13 +21,16 @@ public class ColorizeJEICategory implements IRecipeCategory<ColorizeRecipe> {

public static final RecipeType<ColorizeRecipe> RECIPE_TYPE = RecipeType.create("colorize", "colorize", ColorizeRecipe.class);

public static final String TEXTURE_GUI_PATH = "textures/gui/";
public static final String TEXTURE_GUI_VANILLA = TEXTURE_GUI_PATH + "gui_vanilla.png";
public static final ResourceLocation RECIPE_GUI_VANILLA = new ResourceLocation(ModIds.JEI_ID, TEXTURE_GUI_VANILLA);
private static final Component TITLE = Component.translatable("gui.colorize.jei.name");
private static final Component SNEAKING = Component.translatable("gui.colorize.jei.sneaking").withStyle(ChatFormatting.ITALIC).withStyle(ChatFormatting.GRAY);
private static final Component CONSUME = Component.translatable("gui.colorize.jei.consume").withStyle(ChatFormatting.ITALIC).withStyle(ChatFormatting.GRAY);

private static final String TEXTURE_GUI_PATH = "textures/gui/";
private static final String TEXTURE_GUI_VANILLA = TEXTURE_GUI_PATH + "gui_vanilla.png";
private static final ResourceLocation RECIPE_GUI_VANILLA = new ResourceLocation(ModIds.JEI_ID, TEXTURE_GUI_VANILLA);

private final IDrawableStatic background;
private final IDrawable icon;
private final Component title = Component.literal("Colorize");

public ColorizeJEICategory(IGuiHelper guiHelper) {
// Use Anvil texture
Expand All @@ -40,7 +45,7 @@ public RecipeType<ColorizeRecipe> getRecipeType() {

@Override
public Component getTitle() {
return this.title;
return TITLE;
}

@Override
Expand All @@ -55,16 +60,31 @@ public IDrawable getIcon() {

@Override
public void setRecipe(IRecipeLayoutBuilder builder, ColorizeRecipe recipe, IFocusGroup focuses) {
IRecipeSlotTooltipCallback callback = (recipeSlotView, tooltip) -> {
if (recipe.sneaking()) {
tooltip.add(SNEAKING);
}
};
IRecipeSlotTooltipCallback callback2 = (recipeSlotView, tooltip) -> {
callback.onTooltip(recipeSlotView, tooltip);
if (recipe.consume()) {
tooltip.add(CONSUME);
}
};

builder.addSlot(RecipeIngredientRole.CATALYST, 1, 1)
.setSlotName("input")
.addIngredients(recipe.validBlocks());
.addIngredients(recipe.validBlocks())
.addTooltipCallback(callback);

builder.addSlot(RecipeIngredientRole.INPUT, 50, 1)
.setSlotName("item")
.addIngredients(recipe.item());
.addIngredients(recipe.item())
.addTooltipCallback(callback2);

builder.addSlot(RecipeIngredientRole.OUTPUT, 108, 1)
.setSlotName("output")
.addItemStack(recipe.result());
.addItemStack(recipe.result())
.addTooltipCallback(callback);
}
}
5 changes: 5 additions & 0 deletions common/src/main/resources/assets/colorize/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"gui.colorize.jei.name": "Colorize",
"gui.colorize.jei.sneaking": "Requires sneaking",
"gui.colorize.jei.consume": "Consumes this item"
}
5 changes: 5 additions & 0 deletions common/src/main/resources/assets/colorize/lang/pl_pl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"gui.colorize.jei.name": "Colorize",
"gui.colorize.jei.sneaking": "Wymaga skradania się",
"gui.colorize.jei.consume": "Zużywa ten przedmiot"
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minecraft_version=1.19.2
enabled_platforms=fabric,forge

archives_base_name=colorize
mod_version=1.3.0
mod_version=1.3.1
maven_group=pl.panszelescik.colorize

architectury_version=6.2.43
Expand Down

0 comments on commit b45ec38

Please sign in to comment.