aboutsummaryrefslogtreecommitdiff
path: root/src/compat/rei/java/moe/nea
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-11-17 19:46:42 +0100
committerLinnea Gräf <nea@nea.moe>2024-11-17 19:46:42 +0100
commit3478861ee3604915da032b50fbe3c7b441d6e8b6 (patch)
treee78c81f7865999d1bad5b8d853e247d1228ff5a6 /src/compat/rei/java/moe/nea
parent86cbf9d4221e85dec14300c11393abb325bffcef (diff)
downloadFirmament-3478861ee3604915da032b50fbe3c7b441d6e8b6.tar.gz
Firmament-3478861ee3604915da032b50fbe3c7b441d6e8b6.tar.bz2
Firmament-3478861ee3604915da032b50fbe3c7b441d6e8b6.zip
fix: Fire fabric tooltip events for REI item stacks
Diffstat (limited to 'src/compat/rei/java/moe/nea')
-rw-r--r--src/compat/rei/java/moe/nea/firmament/compat/rei/NEUItemEntryRenderer.kt25
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(