diff --git a/src/main/groovy-tests/jeiTests.groovy b/src/main/groovy-tests/jeiTests.groovy index 3dc7616b..74b1a7cd 100644 --- a/src/main/groovy-tests/jeiTests.groovy +++ b/src/main/groovy-tests/jeiTests.groovy @@ -45,7 +45,14 @@ addDescription(item('minecraft:apple'), translatableLiteral('An Ordinary Apple.. // Add a translated description page for a stack addDescription(item('minecraft:iron_ingot'), translatable('tooltip.nomilabs.greenhouse.description'), translatable('tooltip.nomilabs.dme_sim_chamber.description')) -/* Recipe Output Tooltips. These are tooltips that appear on CRAFTING recipes that output that stack. */ +/* + * Recipe Output Tooltips. These are tooltips that appear on CRAFTING TABLE recipes that output that stack. + * + * They appear BEFORE `Recipe By <MODID>` Tooltips, and AFTER any item tooltips. + * + * You can either PROVIDE or NOT PROVIDE a Resource Location of the Recipe Name. If you PROVIDE, that provided tooltip has + * a higher priority than tooltip of the same stack, but without Recipe Name provided. + */ // Add a crafting recipe output tooltip for a stack addRecipeOutputTooltip(item('minecraft:gold_ingot'), translatableLiteral('A Very Low Carrot Gold Ingot.').addFormat(TextFormatting.GOLD)) @@ -53,8 +60,8 @@ addRecipeOutputTooltip(item('minecraft:gold_ingot'), translatableLiteral('A Very // Add a translated crafting recipe output tooltip for a stack addRecipeOutputTooltip(item('minecraft:iron_ingot'), translatable('tooltip.nomilabs.greenhouse.description'), translatable('tooltip.nomilabs.dme_sim_chamber.description')) -// Add a crafting recipe output tooltip for a specific recipe for a stack (Higher Priority than wild) +// Add a crafting recipe output tooltip for a specific recipe for a stack (Higher Priority than wild recipe name) addRecipeOutputTooltip(item('minecraft:gold_ingot'), resource('minecraft:gold_ingot_from_block'), translatableLiteral('A Very High Carrot Gold Ingot.').addFormat(TextFormatting.GOLD)) -// Add a translated crafting recipe output tooltip for a specific recipe for a stack (Higher Priority than wild) +// 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.greenhouse.description'), translatable('tooltip.nomilabs.dme_sim_chamber.description')) diff --git a/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java b/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java index 0783dba8..3e23d723 100644 --- a/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java +++ b/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java @@ -256,6 +256,14 @@ public static class ModIntegration { @Config.RequiresMcRestart 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 <MOD_ID>` and `Recipe ID: <RECIPE_ID>`.", + "[default: true]", + }) + @Config.LangKey("config.nomilabs.mod_integration.jei_crafting_output_empty_line") + public boolean addJEICraftingOutputEmptyLine = true; + public static class EffortlessBuildingIntegration { @Config.Comment({ "Whether to enable Effortless Building Integration, which splits the parts of reach.", 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 3c8fd44f..0d511190 100644 --- a/src/main/java/com/nomiceu/nomilabs/integration/jei/JEIPlugin.java +++ b/src/main/java/com/nomiceu/nomilabs/integration/jei/JEIPlugin.java @@ -46,6 +46,8 @@ public class JEIPlugin implements IModPlugin { .create(); private static final List<Pair<ItemStack, Function<NBTTagCompound, Boolean>>> IGNORE_NBT_HIDE = new ArrayList<>(); + private static Table<ItemTagMeta, ResourceLocation, List<Translatable>> COMPILED_RECIPE_OUTPUT_TOOLTIPS = null; + private static IIngredientRegistry itemRegistry; @Override @@ -133,18 +135,25 @@ private static void addRecipeOutputTooltip(Table<ItemTagMeta, ResourceLocation, table.put(stack, recipeName, list); } - public static List<String> getRecipeOutputTooltip(ItemStack stack, ResourceLocation recipeName) { - var tempTable = HashBasedTable.create(RECIPE_OUTPUT_TOOLTIPS); + private static void cacheRecipeOutputTooltip() { + if (COMPILED_RECIPE_OUTPUT_TOOLTIPS != null) return; + + COMPILED_RECIPE_OUTPUT_TOOLTIPS = HashBasedTable.create(RECIPE_OUTPUT_TOOLTIPS); GROOVY_RECIPE_OUTPUT_TOOLTIPS.cellSet() - .forEach((cell) -> addRecipeOutputTooltip(tempTable, Objects.requireNonNull(cell.getRowKey()), + .forEach((cell) -> addRecipeOutputTooltip(COMPILED_RECIPE_OUTPUT_TOOLTIPS, + Objects.requireNonNull(cell.getRowKey()), cell.getColumnKey(), (list) -> list.addAll(Objects.requireNonNull(cell.getValue())))); + } + + public static List<String> getRecipeOutputTooltip(ItemStack stack, ResourceLocation recipeName) { + cacheRecipeOutputTooltip(); var itemTagMeta = new ItemTagMeta(stack); - var specific = tempTable.get(itemTagMeta, recipeName); + var specific = COMPILED_RECIPE_OUTPUT_TOOLTIPS.get(itemTagMeta, recipeName); if (specific != null) return specific.stream().map(Translatable::translate).collect(Collectors.toList()); - var wildcard = tempTable.get(itemTagMeta, WILDCARD_LOCATION); + var wildcard = COMPILED_RECIPE_OUTPUT_TOOLTIPS.get(itemTagMeta, WILDCARD_LOCATION); if (wildcard != null) return wildcard.stream().map(Translatable::translate).collect(Collectors.toList()); return new ArrayList<>(); } @@ -153,5 +162,6 @@ public static void onReload() { GROOVY_DESCRIPTIONS.clear(); GROOVY_RECIPE_OUTPUT_TOOLTIPS.clear(); IGNORE_NBT_HIDE.clear(); + COMPILED_RECIPE_OUTPUT_TOOLTIPS = null; } } 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 3435840f..8cbd6b38 100644 --- a/src/main/java/com/nomiceu/nomilabs/mixin/jei/CraftingRecipeCategoryMixin.java +++ b/src/main/java/com/nomiceu/nomilabs/mixin/jei/CraftingRecipeCategoryMixin.java @@ -2,9 +2,10 @@ import java.util.List; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.common.FMLCommonHandler; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -13,10 +14,16 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.nomiceu.nomilabs.config.LabsConfig; import com.nomiceu.nomilabs.integration.jei.JEIPlugin; +import com.nomiceu.nomilabs.util.LabsSide; 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 + * By <modid>`) + */ @Mixin(value = CraftingRecipeCategory.class, remap = false) public class CraftingRecipeCategoryMixin { @@ -27,7 +34,20 @@ public class CraftingRecipeCategoryMixin { @Inject(method = "lambda$setRecipe$0", at = @At("HEAD")) private static void addRecipeOutputTooltip(ResourceLocation registryName, int slotIndex, boolean input, ItemStack stack, List<String> tooltip, CallbackInfo ci) { - if (FMLCommonHandler.instance().getEffectiveSide().isServer() || slotIndex != craftOutputSlot) return; - tooltip.addAll(JEIPlugin.getRecipeOutputTooltip(stack, registryName)); + if (LabsSide.isServer() || slotIndex != craftOutputSlot) return; + boolean modIdDifferent = false; + ResourceLocation itemRegistryName = stack.getItem().getRegistryName(); + if (itemRegistryName != null) { + String itemModId = itemRegistryName.getNamespace(); + modIdDifferent = !registryName.getNamespace().equals(itemModId); + } + + boolean showAdvanced = Minecraft.getMinecraft().gameSettings.advancedItemTooltips || GuiScreen.isShiftKeyDown(); + + var outputTooltip = JEIPlugin.getRecipeOutputTooltip(stack, registryName); + if (LabsConfig.modIntegration.addJEICraftingOutputEmptyLine && + (modIdDifferent || showAdvanced || !outputTooltip.isEmpty())) + tooltip.add(""); + tooltip.addAll(outputTooltip); } } diff --git a/src/main/resources/assets/nomilabs/lang/en_us.lang b/src/main/resources/assets/nomilabs/lang/en_us.lang index 4f50492c..e3764b8b 100644 --- a/src/main/resources/assets/nomilabs/lang/en_us.lang +++ b/src/main/resources/assets/nomilabs/lang/en_us.lang @@ -47,6 +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.effortlessbuilding=Effortless Building Integration Settings config.nomilabs.mod_integration.effortlessbuilding.enable=Enable Effortless Building Integration