diff --git a/src/main/java/com/klikli_dev/occultism/handlers/ClientSetupEventHandler.java b/src/main/java/com/klikli_dev/occultism/handlers/ClientSetupEventHandler.java index 4d7dbe6ca..67d06e4a1 100644 --- a/src/main/java/com/klikli_dev/occultism/handlers/ClientSetupEventHandler.java +++ b/src/main/java/com/klikli_dev/occultism/handlers/ClientSetupEventHandler.java @@ -160,6 +160,8 @@ public static void onRegisterKeyMappings(RegisterKeyMappingsEvent event) { @SubscribeEvent public static void onClientSetup(FMLClientSetupEvent event) { + TooltipHandler.registerNamespaceToListenTo(Occultism.MODID); + //Register client side event handlers NeoForge.EVENT_BUS.register(Occultism.SELECTED_BLOCK_RENDERER); NeoForge.EVENT_BUS.register(Occultism.THIRD_EYE_EFFECT_RENDERER); diff --git a/src/main/java/com/klikli_dev/occultism/handlers/TooltipHandler.java b/src/main/java/com/klikli_dev/occultism/handlers/TooltipHandler.java index 508c3151f..364d70061 100644 --- a/src/main/java/com/klikli_dev/occultism/handlers/TooltipHandler.java +++ b/src/main/java/com/klikli_dev/occultism/handlers/TooltipHandler.java @@ -37,9 +37,22 @@ import net.neoforged.fml.common.Mod; import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent; +import java.util.ArrayList; +import java.util.List; + @Mod.EventBusSubscriber(modid = Occultism.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class TooltipHandler { + private static final List namespacesToListenFor = new ArrayList<>(); + + /** + * Register a namespace (= mod id) of items to listen for during tooltip handling. + * Should be called in @{@link net.neoforged.fml.event.lifecycle.FMLClientSetupEvent} + */ + public static void registerNamespaceToListenTo(String namespace) { + namespacesToListenFor.add(namespace); + } + @SubscribeEvent public static void onAddInformation(ItemTooltipEvent event) { ItemStack stack = event.getItemStack(); @@ -61,7 +74,7 @@ public static void onAddInformation(ItemTooltipEvent event) { var namespace = BuiltInRegistries.ITEM.getKey(stack.getItem()).getNamespace(); - if(namespace.equals(Occultism.MODID)){ + if (namespacesToListenFor.contains(namespace)) { String tooltipKey = stack.getDescriptionId() + ".auto_tooltip"; boolean tooltipExists = I18n.exists(tooltipKey); if (tooltipExists) {