From 3478861ee3604915da032b50fbe3c7b441d6e8b6 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sun, 17 Nov 2024 19:46:42 +0100 Subject: fix: Fire fabric tooltip events for REI item stacks --- .../firmament/compat/rei/NEUItemEntryRenderer.kt | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntryRenderer.kt b/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntryRenderer.kt index a708c5b..336c103 100644 --- a/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntryRenderer.kt +++ b/src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntryRenderer.kt @@ -18,6 +18,7 @@ import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer import me.shedaniel.rei.api.client.gui.widgets.Tooltip import me.shedaniel.rei.api.client.gui.widgets.TooltipContext import me.shedaniel.rei.api.common.entry.EntryStack +import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback import net.minecraft.client.MinecraftClient import net.minecraft.client.gui.DrawContext import net.minecraft.client.render.DiffuseLighting @@ -31,6 +32,7 @@ import net.minecraft.item.tooltip.TooltipType import moe.nea.firmament.compat.rei.FirmamentReiPlugin.Companion.asItemEntry import moe.nea.firmament.events.ItemTooltipEvent import moe.nea.firmament.repo.SBItemStack +import moe.nea.firmament.util.ErrorUtil import moe.nea.firmament.util.MC import moe.nea.firmament.util.mc.displayNameAccordingToNbt import moe.nea.firmament.util.mc.loreAccordingToNbt @@ -48,18 +50,29 @@ object NEUItemEntryRenderer : EntryRenderer, BatchedEntryRenderer, tooltipContext: TooltipContext): Tooltip? { val stack = entry.value.asImmutableItemStack() val lore = mutableListOf(stack.displayNameAccordingToNbt) lore.addAll(stack.loreAccordingToNbt) - ItemTooltipEvent.publish(ItemTooltipEvent( - stack, - tooltipContext.vanillaContext(), - TooltipType.BASIC, - lore - )) + if (canUseVanillaTooltipEvents) { + try { + ItemTooltipCallback.EVENT.invoker().getTooltip( + stack, tooltipContext.vanillaContext(), TooltipType.BASIC, lore + ) + } catch (ex: Exception) { + ErrorUtil.softError("Failed to use vanilla tooltips", ex) + } + } else { + ItemTooltipEvent.publish(ItemTooltipEvent( + stack, + tooltipContext.vanillaContext(), + TooltipType.BASIC, + lore + )) + } // TODO: tags aren't sent as early now so some tooltip components that use tags will crash the game // stack.getTooltip( // Item.TooltipContext.create( -- cgit