From 4b7050d4b4eacd9af917f6fed8225181fd114bdb Mon Sep 17 00:00:00 2001 From: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Date: Mon, 9 Dec 2024 21:07:15 +1100 Subject: [PATCH] Improve JEI Ingredient Tooltip Support --- src/main/groovy-tests/jeiTests.groovy | 38 ++++++++++ .../nomiceu/nomilabs/config/LabsConfig.java | 8 +- .../nomilabs/groovy/GroovyHelpers.java | 5 ++ .../mixinhelper/RecipeTooltipAdder.java | 24 ++++++ .../nomilabs/integration/jei/JEIPlugin.java | 73 ++++++++++++++++++- .../ShapedRecipeBuilderMixin.java | 38 ++++++++++ .../ShapelessRecipeBuilderMixin.java | 45 +++++++++++- .../jei/CraftingRecipeCategoryMixin.java | 27 +++++-- .../mixin/jei/GuiIngredientMixin.java | 32 ++++++++ .../resources/assets/nomilabs/lang/en_us.lang | 2 +- src/main/resources/mixins.nomilabs.jei.json | 4 +- 11 files changed, 282 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/nomiceu/nomilabs/groovy/mixinhelper/RecipeTooltipAdder.java create mode 100644 src/main/java/com/nomiceu/nomilabs/mixin/jei/GuiIngredientMixin.java diff --git a/src/main/groovy-tests/jeiTests.groovy b/src/main/groovy-tests/jeiTests.groovy index 43f0f882..60dc97ea 100644 --- a/src/main/groovy-tests/jeiTests.groovy +++ b/src/main/groovy-tests/jeiTests.groovy @@ -65,3 +65,41 @@ addRecipeOutputTooltip(item('minecraft:gold_ingot'), resource('minecraft:gold_in // Add a translated crafting recipe output tooltip for a specific recipe for a stack (Higher Priority than wild recipe name) addRecipeOutputTooltip(item('minecraft:iron_ingot'), resource('minecraft:iron_ingot_from_nuggets'), translatable('tooltip.nomilabs.universalnavigator.description'), translatable('tooltip.nomilabs.growth_chamber.description'), translatable('tooltip.nomilabs.dme_sim_chamber.description')) + +// Use in a crafting shaped/shapeless builder +crafting.shapedBuilder() + .output(item('minecraft:apple')) + .matrix('AAA', 'AAA', 'ABA') + .key('A', item('minecraft:diamond')) + .key('B', item('minecraft:apple')) + .setOutputTooltip(translatableLiteral('A Very Low Carrot Gold Ingot.').addFormat(TextFormatting.GOLD), + translatable('tooltip.nomilabs.growth_chamber.description')) + .register() + +/** + * Recipe Input Tooltips. These are tooltips that appear on CRAFTING TABLE recipes, on a specific registry name and index. + */ + +// Similar outside of builder + +// In a crafting shaped/shapeless builder +crafting.shapelessBuilder() + .output(item('minecraft:apple')) + .input(item('minecraft:diamond'), item('minecraft:apple')) + // You must specify an index between 0 and 8! This represents the slot number. It goes from left to right, top to bottom. + // E.g. slot 1 = 1st row, 2nd column + .setInputTooltip(1, translatableLiteral('Is a Gold Ingot.').addFormat(TextFormatting.GOLD), + translatable('tooltip.nomilabs.growth_chamber.description')) + .register() + +crafting.shapedBuilder() + .output(item('minecraft:apple')) + .matrix('AAA', 'ABA', 'ABA') + .key('A', item('minecraft:diamond')) + .key('B', item('minecraft:apple')) + // You must specify an index between 0 and 8! This represents the slot number. It goes from left to right, top to bottom. + // E.g. slot 4 = 2nd row, 2nd column + .setInputTooltip(4, translatableLiteral('Is a Gold Ingot?').addFormat(TextFormatting.GOLD), + translatable('tooltip.nomilabs.growth_chamber.description')) + .register() + diff --git a/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java b/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java index a67f1325..de542d78 100644 --- a/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java +++ b/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java @@ -264,12 +264,12 @@ public static class ModIntegration { public boolean enableTopAddonsIntegration = true; @Config.Comment({ - "Whether to add a Empty Line between any Crafting Recipe Output Tooltips in JEI.", - "Examples of Crafting Recipe Output Tooltips are `Recipe By ` and `Recipe ID: `.", + "Whether to add a Empty Line between any Ingredient Tooltips in JEI.", + "Examples of Ingredient Tooltips are `Recipe By `, `Recipe ID: `, and `Accepts any: `.", "[default: true]", }) - @Config.LangKey("config.nomilabs.mod_integration.jei_crafting_output_empty_line") - public boolean addJEICraftingOutputEmptyLine = true; + @Config.LangKey("config.nomilabs.mod_integration.jei_ing_empty_line") + public boolean addJEIIngEmptyLine = true; @Config.Comment({ "Whether to enable Better Questing Fluid Task Fixes.", diff --git a/src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java b/src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java index 2c539b9e..3e4e34ee 100644 --- a/src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java +++ b/src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java @@ -192,6 +192,11 @@ public static void addRecipeOutputTooltip(ItemStack stack, ResourceLocation reci JEIPlugin.addGroovyRecipeOutputTooltip(stack, recipeName, tooltip); } + public static void addRecipeInputTooltip(ResourceLocation recipeName, int slotIndex, + LabsTranslate.Translatable... tooltip) { + JEIPlugin.addGroovyRecipeInputTooltip(recipeName, slotIndex, tooltip); + } + /* Hiding Ignore NBT */ public static void hideItemIgnoreNBT(ItemStack stack) { JEIPlugin.hideItemNBTMatch(stack, (tag) -> true); diff --git a/src/main/java/com/nomiceu/nomilabs/groovy/mixinhelper/RecipeTooltipAdder.java b/src/main/java/com/nomiceu/nomilabs/groovy/mixinhelper/RecipeTooltipAdder.java new file mode 100644 index 00000000..fadafc95 --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/groovy/mixinhelper/RecipeTooltipAdder.java @@ -0,0 +1,24 @@ +package com.nomiceu.nomilabs.groovy.mixinhelper; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import com.nomiceu.nomilabs.integration.jei.JEIPlugin; +import com.nomiceu.nomilabs.util.LabsTranslate; + +public class RecipeTooltipAdder { + + public static void addTooltips(ResourceLocation rl, ItemStack recipeOutput, + LabsTranslate.Translatable[][] inputTooltip, + LabsTranslate.Translatable[] outputTooltip) { + if (inputTooltip != null) { + for (int i = 0; i < inputTooltip.length; i++) { + var tooltip = inputTooltip[i]; + if (tooltip != null) + JEIPlugin.addGroovyRecipeInputTooltip(rl, i, tooltip); + } + } + if (outputTooltip != null) + JEIPlugin.addGroovyRecipeOutputTooltip(recipeOutput, rl, outputTooltip); + } +} diff --git a/src/main/java/com/nomiceu/nomilabs/integration/jei/JEIPlugin.java b/src/main/java/com/nomiceu/nomilabs/integration/jei/JEIPlugin.java index 0d511190..06890fba 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/jei/JEIPlugin.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/jei/JEIPlugin.java @@ -17,6 +17,7 @@ import org.jetbrains.annotations.NotNull; import com.cleanroommc.groovyscript.api.GroovyBlacklist; +import com.cleanroommc.groovyscript.api.GroovyLog; import com.cleanroommc.groovyscript.registry.ReloadableRegistryManager; import com.google.common.collect.HashBasedTable; import com.google.common.collect.ImmutableList; @@ -25,6 +26,7 @@ import com.nomiceu.nomilabs.item.registry.LabsItems; import com.nomiceu.nomilabs.util.ItemTagMeta; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import mezz.jei.api.IJeiRuntime; import mezz.jei.api.IModPlugin; import mezz.jei.api.IModRegistry; @@ -38,16 +40,22 @@ public class JEIPlugin implements IModPlugin { private static final ResourceLocation WILDCARD_LOCATION = new ResourceLocation("*", "*"); + private static final Map> DESCRIPTIONS = new HashMap<>(); private static final Map> GROOVY_DESCRIPTIONS = new HashMap<>(); + private static final Table> RECIPE_OUTPUT_TOOLTIPS = HashBasedTable .create(); private static final Table> GROOVY_RECIPE_OUTPUT_TOOLTIPS = HashBasedTable .create(); - private static final List>> IGNORE_NBT_HIDE = new ArrayList<>(); - private static Table> COMPILED_RECIPE_OUTPUT_TOOLTIPS = null; + private static final Map[]> RECIPE_INPUT_TOOLTIPS = new Object2ObjectOpenHashMap<>(); + private static final Map[]> GROOVY_RECIPE_INPUT_TOOLTIPS = new Object2ObjectOpenHashMap<>(); + private static Map[]> COMPILED_RECIPE_INPUT_TOOLTIPS = null; + + private static final List>> IGNORE_NBT_HIDE = new ArrayList<>(); + private static IIngredientRegistry itemRegistry; @Override @@ -73,6 +81,7 @@ public void onRuntimeAvailable(@NotNull IJeiRuntime jeiRuntime) { Collections.singletonList(new ItemStack(LabsItems.INFO_ITEM))); } + /* Hiding Helpers */ public static void hideItemNBTMatch(ItemStack itemStack, Function condition) { IGNORE_NBT_HIDE.add(Pair.of(itemStack, condition)); } @@ -92,6 +101,7 @@ public static List>> getIgnore return ImmutableList.copyOf(IGNORE_NBT_HIDE); } + /* Descriptions */ public static void addDescription(@NotNull ItemStack stack, Translatable... description) { addDescription(DESCRIPTIONS, new ItemTagMeta(stack), (list) -> Collections.addAll(list, description)); } @@ -106,6 +116,7 @@ private static void addDescription(Map> map, addToList.accept(map.get(stack)); } + /* Recipe Output Tooltip */ public static void addRecipeOutputTooltip(@NotNull ItemStack stack, Translatable... tooltip) { addRecipeOutputTooltip(stack, WILDCARD_LOCATION, tooltip); } @@ -158,10 +169,68 @@ public static List getRecipeOutputTooltip(ItemStack stack, ResourceLocat return new ArrayList<>(); } + /* Recipe Input Tooltip */ + public static void addRecipeInputTooltip(@NotNull ResourceLocation recipeName, int slotIndex, + Translatable... tooltip) { + if (slotIndex < 0 || slotIndex > 8) + throw new IllegalArgumentException("Add Recipe Input Tooltip: Slot Index must be between 0 and 8!"); + + addRecipeInputTooltip(RECIPE_INPUT_TOOLTIPS, recipeName, slotIndex, + (list) -> Collections.addAll(list, tooltip)); + } + + public static void addGroovyRecipeInputTooltip(@NotNull ResourceLocation recipeName, int slotIndex, + Translatable... tooltip) { + if (slotIndex < 0 || slotIndex > 8) { + GroovyLog.get().error("Add Recipe Input Tooltip: Slot Index must be between 0 and 8!"); + return; + } + + addRecipeInputTooltip(GROOVY_RECIPE_INPUT_TOOLTIPS, recipeName, slotIndex, + (list) -> Collections.addAll(list, tooltip)); + } + + private static void addRecipeInputTooltip(Map[]> map, + @NotNull ResourceLocation recipeName, int slotIndex, + Consumer> addToList) { + // noinspection unchecked + var recipeTooltips = map.computeIfAbsent(recipeName, (k) -> (List[]) new List[9]); + var existingTranslations = recipeTooltips[slotIndex]; + + if (existingTranslations == null) existingTranslations = new ArrayList<>(); + addToList.accept(existingTranslations); + recipeTooltips[slotIndex] = existingTranslations; + } + + private static void cacheRecipeInputTooltips() { + if (COMPILED_RECIPE_INPUT_TOOLTIPS != null) return; + + COMPILED_RECIPE_INPUT_TOOLTIPS = new Object2ObjectOpenHashMap<>(RECIPE_INPUT_TOOLTIPS); + GROOVY_RECIPE_INPUT_TOOLTIPS.forEach((key, value) -> { + for (int i = 0; i < value.length; i++) { + var tooltips = value[i]; + if (tooltips == null) continue; + addRecipeInputTooltip(COMPILED_RECIPE_INPUT_TOOLTIPS, key, i, (list) -> list.addAll(tooltips)); + } + }); + } + + public static List getRecipeInputTooltip(ResourceLocation recipeName, int slotIndex) { + cacheRecipeInputTooltips(); + + if (!COMPILED_RECIPE_INPUT_TOOLTIPS.containsKey(recipeName)) return new ArrayList<>(); + + var tooltips = COMPILED_RECIPE_INPUT_TOOLTIPS.get(recipeName)[slotIndex]; + if (tooltips == null) return new ArrayList<>(); + return tooltips.stream().map(Translatable::translate).collect(Collectors.toList()); + } + public static void onReload() { GROOVY_DESCRIPTIONS.clear(); GROOVY_RECIPE_OUTPUT_TOOLTIPS.clear(); + GROOVY_RECIPE_INPUT_TOOLTIPS.clear(); IGNORE_NBT_HIDE.clear(); COMPILED_RECIPE_OUTPUT_TOOLTIPS = null; + COMPILED_RECIPE_INPUT_TOOLTIPS = null; } } diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/groovyscript/ShapedRecipeBuilderMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/groovyscript/ShapedRecipeBuilderMixin.java index 0bb7699e..1f33997c 100644 --- a/src/main/java/com/nomiceu/nomilabs/mixin/groovyscript/ShapedRecipeBuilderMixin.java +++ b/src/main/java/com/nomiceu/nomilabs/mixin/groovyscript/ShapedRecipeBuilderMixin.java @@ -15,12 +15,20 @@ import com.cleanroommc.groovyscript.api.IIngredient; import com.cleanroommc.groovyscript.compat.vanilla.CraftingRecipeBuilder; import com.cleanroommc.groovyscript.registry.AbstractCraftingRecipeBuilder; +import com.nomiceu.nomilabs.groovy.mixinhelper.RecipeTooltipAdder; import com.nomiceu.nomilabs.groovy.mixinhelper.ShapedRecipeClassFunction; import com.nomiceu.nomilabs.groovy.mixinhelper.ShapedRecipeClassFunctionSimplified; import com.nomiceu.nomilabs.groovy.mixinhelper.StrictableRecipe; +import com.nomiceu.nomilabs.util.LabsTranslate; import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap; +/** + * Allows for recipes to be 'strict'. This means, in JEI, the list of 'matching stacks' will be displayed + * exactly as set, instead of expanding wildcards and removing duplicates. + *

+ * Also allows setting custom shaped class, and adding recipe input/output tooltips in JEI. + */ @Mixin(value = CraftingRecipeBuilder.Shaped.class, remap = false) @SuppressWarnings("unused") public abstract class ShapedRecipeBuilderMixin extends AbstractCraftingRecipeBuilder.AbstractShaped { @@ -31,6 +39,12 @@ public abstract class ShapedRecipeBuilderMixin extends AbstractCraftingRecipeBui @Unique private boolean labs$isStrict = false; + @Unique + private LabsTranslate.Translatable[][] labs$inputTooltip = null; + + @Unique + private LabsTranslate.Translatable[] labs$outputTooltip = null; + /** * Default Ignored Constructor */ @@ -70,6 +84,25 @@ public CraftingRecipeBuilder.Shaped recipeClassFunction(ShapedRecipeClassFunctio return (CraftingRecipeBuilder.Shaped) (Object) this; } + @Unique + public CraftingRecipeBuilder.Shaped setOutputTooltip(LabsTranslate.Translatable... tooltip) { + labs$outputTooltip = tooltip; + return (CraftingRecipeBuilder.Shaped) (Object) this; + } + + @Unique + public CraftingRecipeBuilder.Shaped setInputTooltip(int slotIndex, LabsTranslate.Translatable... tooltip) { + if (slotIndex < 0 || slotIndex > 8) { + GroovyLog.get().error("Add Recipe Input Tooltip: Slot Index must be between 0 and 8!"); + return (CraftingRecipeBuilder.Shaped) (Object) this; + } + + if (labs$inputTooltip == null) labs$inputTooltip = new LabsTranslate.Translatable[9][0]; + + labs$inputTooltip[slotIndex] = tooltip; + return (CraftingRecipeBuilder.Shaped) (Object) this; + } + @Redirect(method = "register()Lnet/minecraft/item/crafting/IRecipe;", at = @At(value = "INVOKE", target = "Lcom/cleanroommc/groovyscript/compat/vanilla/CraftingRecipeBuilder$Shaped;validateShape(Lcom/cleanroommc/groovyscript/api/GroovyLog$Msg;Ljava/util/List;[Ljava/lang/String;Lit/unimi/dsi/fastutil/chars/Char2ObjectOpenHashMap;Lcom/cleanroommc/groovyscript/registry/AbstractCraftingRecipeBuilder$IRecipeCreator;)Ljava/lang/Object;"), @@ -95,4 +128,9 @@ public Object registerWithClassFunction2(CraftingRecipeBuilder.Shaped instance, return validateShape(msg, list, (width1, height1, ingredients) -> labs$recipeClassFunction .createRecipe(output, width1, height1, ingredients, mirrored, recipeFunction, recipeAction)); } + + @Inject(method = "register()Lnet/minecraft/item/crafting/IRecipe;", at = @At("TAIL")) + private void addRecipeTooltips(CallbackInfoReturnable cir) { + RecipeTooltipAdder.addTooltips(name, output, labs$inputTooltip, labs$outputTooltip); + } } diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/groovyscript/ShapelessRecipeBuilderMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/groovyscript/ShapelessRecipeBuilderMixin.java index d158afa2..e53b83a0 100644 --- a/src/main/java/com/nomiceu/nomilabs/mixin/groovyscript/ShapelessRecipeBuilderMixin.java +++ b/src/main/java/com/nomiceu/nomilabs/mixin/groovyscript/ShapelessRecipeBuilderMixin.java @@ -8,20 +8,39 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import com.cleanroommc.groovyscript.api.GroovyLog; import com.cleanroommc.groovyscript.compat.vanilla.CraftingRecipeBuilder; +import com.cleanroommc.groovyscript.registry.AbstractCraftingRecipeBuilder; +import com.nomiceu.nomilabs.groovy.mixinhelper.RecipeTooltipAdder; import com.nomiceu.nomilabs.groovy.mixinhelper.StrictableRecipe; +import com.nomiceu.nomilabs.util.LabsTranslate; /** * Allows for recipes to be 'strict'. This means, in JEI, the list of 'matching stacks' will be displayed * exactly as set, instead of expanding wildcards and removing duplicates. + *

+ * Also allows adding recipe input/output tooltips in JEI. */ @Mixin(value = CraftingRecipeBuilder.Shapeless.class, remap = false) @SuppressWarnings("unused") -public class ShapelessRecipeBuilderMixin { +public abstract class ShapelessRecipeBuilderMixin extends AbstractCraftingRecipeBuilder.AbstractShapeless { @Unique private boolean labs$isStrict = false; + @Unique + private LabsTranslate.Translatable[][] labs$inputTooltip = null; + + @Unique + private LabsTranslate.Translatable[] labs$outputTooltip = null; + + /** + * Default Ignored Constructor + */ + private ShapelessRecipeBuilderMixin(int width, int height) { + super(width, height); + } + /** * Makes recipes 'strict'. This means, in JEI, the list of 'matching stacks' will be displayed * exactly as set, instead of expanding wildcards and removing duplicates. @@ -32,6 +51,25 @@ public CraftingRecipeBuilder.Shapeless strictJEIHandling() { return (CraftingRecipeBuilder.Shapeless) (Object) this; } + @Unique + public CraftingRecipeBuilder.Shapeless setOutputTooltip(LabsTranslate.Translatable... tooltip) { + labs$outputTooltip = tooltip; + return (CraftingRecipeBuilder.Shapeless) (Object) this; + } + + @Unique + public CraftingRecipeBuilder.Shapeless setInputTooltip(int slotIndex, LabsTranslate.Translatable... tooltip) { + if (slotIndex < 0 || slotIndex > 8) { + GroovyLog.get().error("Add Recipe Input Tooltip: Slot Index must be between 0 and 8!"); + return (CraftingRecipeBuilder.Shapeless) (Object) this; + } + + if (labs$inputTooltip == null) labs$inputTooltip = new LabsTranslate.Translatable[9][0]; + + labs$inputTooltip[slotIndex] = tooltip; + return (CraftingRecipeBuilder.Shapeless) (Object) this; + } + @Inject(method = "register()Lnet/minecraft/item/crafting/IRecipe;", at = @At("RETURN")) private void setStrict(CallbackInfoReturnable cir) { var val = cir.getReturnValue(); @@ -39,4 +77,9 @@ private void setStrict(CallbackInfoReturnable cir) { if (labs$isStrict) strict.labs$setStrict(); } + + @Inject(method = "register()Lnet/minecraft/item/crafting/IRecipe;", at = @At("TAIL")) + private void addRecipeTooltips(CallbackInfoReturnable cir) { + RecipeTooltipAdder.addTooltips(name, output, labs$inputTooltip, labs$outputTooltip); + } } diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/jei/CraftingRecipeCategoryMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/jei/CraftingRecipeCategoryMixin.java index 8cbd6b38..b5999f29 100644 --- a/src/main/java/com/nomiceu/nomilabs/mixin/jei/CraftingRecipeCategoryMixin.java +++ b/src/main/java/com/nomiceu/nomilabs/mixin/jei/CraftingRecipeCategoryMixin.java @@ -21,7 +21,8 @@ import mezz.jei.plugins.vanilla.crafting.CraftingRecipeCategory; /** - * Allows adding Custom Recipe Output Tooltips, and adds a new line before any recipe output tooltip (including `Recipe + * Allows adding Custom Recipe Input and Output Tooltips, and adds a new line before any recipe output tooltip + * (including `Recipe * By `) */ @Mixin(value = CraftingRecipeCategory.class, remap = false) @@ -31,10 +32,26 @@ public class CraftingRecipeCategoryMixin { @Final private static int craftOutputSlot; + @Shadow + @Final + private static int craftInputSlot1; + @Inject(method = "lambda$setRecipe$0", at = @At("HEAD")) - private static void addRecipeOutputTooltip(ResourceLocation registryName, int slotIndex, boolean input, - ItemStack stack, List tooltip, CallbackInfo ci) { - if (LabsSide.isServer() || slotIndex != craftOutputSlot) return; + private static void addRecipeIngredientTooltips(ResourceLocation registryName, int slotIndex, boolean input, + ItemStack stack, List tooltip, CallbackInfo ci) { + if (LabsSide.isServer()) return; + + if (slotIndex != craftOutputSlot) { + int index = slotIndex - craftInputSlot1; + if (index < 0 || index > 8) return; + + var inputTooltip = JEIPlugin.getRecipeInputTooltip(registryName, index); + if (LabsConfig.modIntegration.addJEIIngEmptyLine && !inputTooltip.isEmpty()) + tooltip.add(""); + tooltip.addAll(inputTooltip); + return; + } + boolean modIdDifferent = false; ResourceLocation itemRegistryName = stack.getItem().getRegistryName(); if (itemRegistryName != null) { @@ -45,7 +62,7 @@ private static void addRecipeOutputTooltip(ResourceLocation registryName, int sl boolean showAdvanced = Minecraft.getMinecraft().gameSettings.advancedItemTooltips || GuiScreen.isShiftKeyDown(); var outputTooltip = JEIPlugin.getRecipeOutputTooltip(stack, registryName); - if (LabsConfig.modIntegration.addJEICraftingOutputEmptyLine && + if (LabsConfig.modIntegration.addJEIIngEmptyLine && (modIdDifferent || showAdvanced || !outputTooltip.isEmpty())) tooltip.add(""); tooltip.addAll(outputTooltip); diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/jei/GuiIngredientMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/jei/GuiIngredientMixin.java new file mode 100644 index 00000000..9c50295a --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/jei/GuiIngredientMixin.java @@ -0,0 +1,32 @@ +package com.nomiceu.nomilabs.mixin.jei; + +import java.util.List; + +import net.minecraft.client.Minecraft; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import com.llamalad7.mixinextras.sugar.Local; +import com.nomiceu.nomilabs.config.LabsConfig; + +import mezz.jei.gui.ingredients.GuiIngredient; + +/** + * Allows adding a newline before ore tooltip. + */ +@Mixin(value = GuiIngredient.class, remap = false) +public class GuiIngredientMixin { + + @Inject(method = "drawTooltip", + at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z"), + locals = LocalCapture.CAPTURE_FAILHARD) + private void addNewLine(Minecraft minecraft, int xOffset, int yOffset, int mouseX, int mouseY, T value, + CallbackInfo ci, @Local List tooltip) { + if (LabsConfig.modIntegration.addJEIIngEmptyLine) + tooltip.add(""); + } +} diff --git a/src/main/resources/assets/nomilabs/lang/en_us.lang b/src/main/resources/assets/nomilabs/lang/en_us.lang index 48fd2ee8..1e81eb3b 100644 --- a/src/main/resources/assets/nomilabs/lang/en_us.lang +++ b/src/main/resources/assets/nomilabs/lang/en_us.lang @@ -47,7 +47,7 @@ config.nomilabs.mod_integration.ender_storage=Enable Ender Storage Integration config.nomilabs.mod_integration.ender_io=Enable Ender IO Integration config.nomilabs.mod_integration.ftb_utils=Enable FTB Utilities Integration config.nomilabs.mod_integration.top_addons=Enable TOP Addons Integration -config.nomilabs.mod_integration.jei_crafting_output_empty_line=Add JEI Crafting Output Tooltip Empty Line +config.nomilabs.mod_integration.jei_ing_empty_line=Add JEI Ingredient Tooltip Empty Line config.nomilabs.mod_integration.bqu_fluid_task_fixes=Enable BQu Fluid Task Fixes config.nomilabs.mod_integration.effortlessbuilding=Effortless Building Integration Settings diff --git a/src/main/resources/mixins.nomilabs.jei.json b/src/main/resources/mixins.nomilabs.jei.json index b2267173..326d2cf9 100644 --- a/src/main/resources/mixins.nomilabs.jei.json +++ b/src/main/resources/mixins.nomilabs.jei.json @@ -9,6 +9,8 @@ "IngredientInfoRecipeMixin", "RecipeCategoryTabMixin" ], - "client": [], + "client": [ + "GuiIngredientMixin" + ], "server": [] }