From 83ed5f00e9943762d419e1b78f55942b15f9c99c Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:27:51 +1000 Subject: Fix: Estimated item value not working in pv (#1955) --- .../java/at/hannibal2/skyhanni/data/ToolTipData.kt | 23 +++++++++------------- .../features/misc/items/EstimatedItemValue.kt | 11 +++++------ .../mixins/transformers/MixinItemStack.java | 13 ++++++++++++ 3 files changed, 27 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/data/ToolTipData.kt b/src/main/java/at/hannibal2/skyhanni/data/ToolTipData.kt index 258cb244e..70cd9cd34 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ToolTipData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ToolTipData.kt @@ -9,22 +9,13 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import net.minecraft.inventory.Slot import net.minecraft.item.ItemStack -// Please use LorenzToolTipEvent over ItemTooltipEvent if no special EventPriority is necessary +// Please use LorenzToolTipEvent over ItemHoverEvent, ItemHoverEvent is only used for special use cases (e.g. neu pv) object ToolTipData { @JvmStatic - fun getTooltip(stack: ItemStack, toolTip: MutableList): List { - onHover(stack, toolTip) - return onTooltip(toolTip) - } - - private fun onHover(stack: ItemStack, toolTip: MutableList) { - ItemHoverEvent(stack, toolTip).postAndCatch() - } - - fun onTooltip(toolTip: MutableList): List { - val slot = lastSlot ?: return toolTip - val itemStack = slot.stack ?: return toolTip + fun getTooltip(stack: ItemStack, toolTip: MutableList) { + val slot = lastSlot ?: return + val itemStack = slot.stack ?: return try { if (LorenzToolTipEvent(slot, itemStack, toolTip).postAndCatch()) { toolTip.clear() @@ -42,7 +33,11 @@ object ToolTipData { "lore" to itemStack.getLore(), ) } - return toolTip + } + + @JvmStatic + fun onHover(stack: ItemStack, toolTip: MutableList) { + ItemHoverEvent(stack, toolTip).postAndCatch() } var lastSlot: Slot? = null diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt index 299fe6ec5..b2fdf8294 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt @@ -66,14 +66,13 @@ object EstimatedItemValue { fun onTooltip(event: ItemHoverEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.enabled) return + if (Minecraft.getMinecraft().currentScreen !is GuiProfileViewer) return - if (Minecraft.getMinecraft().currentScreen is GuiProfileViewer) { - if (renderedItems == 0) { - updateItem(event.itemStack) - } - tryRendering() - renderedItems++ + if (renderedItems == 0) { + updateItem(event.itemStack) } + tryRendering() + renderedItems++ } /** diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinItemStack.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinItemStack.java index b96075d62..a3c2f85de 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinItemStack.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinItemStack.java @@ -1,10 +1,17 @@ package at.hannibal2.skyhanni.mixins.transformers; +import at.hannibal2.skyhanni.data.ToolTipData; import at.hannibal2.skyhanni.mixins.hooks.ItemStackCachedData; import at.hannibal2.skyhanni.utils.CachedItemData; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; @Mixin(ItemStack.class) public class MixinItemStack implements ItemStackCachedData { @@ -15,4 +22,10 @@ public class MixinItemStack implements ItemStackCachedData { public CachedItemData getSkyhanni_cachedData() { return skyhanni_cachedData; } + + @Inject(method = "getTooltip", at = @At("RETURN")) + public void getTooltip(EntityPlayer playerIn, boolean advanced, CallbackInfoReturnable> ci) { + ItemStack stack = (ItemStack) (Object) this; + ToolTipData.onHover(stack, ci.getReturnValue()); + } } -- cgit