diff options
author | Linnea Gräf <nea@nea.moe> | 2024-11-17 19:46:42 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-11-17 19:46:42 +0100 |
commit | 3478861ee3604915da032b50fbe3c7b441d6e8b6 (patch) | |
tree | e78c81f7865999d1bad5b8d853e247d1228ff5a6 | |
parent | 86cbf9d4221e85dec14300c11393abb325bffcef (diff) | |
download | Firmament-3478861ee3604915da032b50fbe3c7b441d6e8b6.tar.gz Firmament-3478861ee3604915da032b50fbe3c7b441d6e8b6.tar.bz2 Firmament-3478861ee3604915da032b50fbe3c7b441d6e8b6.zip |
fix: Fire fabric tooltip events for REI item stacks
-rw-r--r-- | src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntryRenderer.kt | 25 |
1 files 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<SBItemStack>, BatchedEntryRenderer<S } val minecraft = MinecraftClient.getInstance() + var canUseVanillaTooltipEvents = false override fun getTooltip(entry: EntryStack<SBItemStack>, 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( |