aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-06-12 16:48:50 +0200
committerGitHub <noreply@github.com>2024-06-12 16:48:50 +0200
commitaad0618be1a84abec30b35d8ae2ec1db084ff236 (patch)
tree6dc4c6f965b145b14490c2b7de3b6498e6560e06
parentc3ba0fe0121b8eff1056fadfde5b8992d4aafe21 (diff)
downloadskyhanni-aad0618be1a84abec30b35d8ae2ec1db084ff236.tar.gz
skyhanni-aad0618be1a84abec30b35d8ae2ec1db084ff236.tar.bz2
skyhanni-aad0618be1a84abec30b35d8ae2ec1db084ff236.zip
Backend: Fixed wardrobe not using tooltip event (#2062)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt23
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt6
2 files changed, 25 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt
index eae98fb94..128fa9c69 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt
@@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
+import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.MAX_PAGES
import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.MAX_SLOT_PER_PAGE
import at.hannibal2.skyhanni.mixins.transformers.gui.AccessorGuiContainer
@@ -31,6 +32,7 @@ import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.client.renderer.GlStateManager
+import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color
import kotlin.math.min
@@ -180,6 +182,7 @@ object CustomWardrobe {
return wardrobeWarning to wardrobeSlots
}
+ // TODO don't initialize all 18 slots at once, load them lazily when first time hovering over the item.
private fun createArmorTooltipRenderable(
slot: WardrobeSlot,
containerHeight: Int,
@@ -202,7 +205,7 @@ object CustomWardrobe {
Renderable.hoverable(
Renderable.hoverTips(
Renderable.placeholder(containerWidth, hoverableSizes[armorIndex]),
- stack.getTooltip(Minecraft.getMinecraft().thePlayer, false)
+ getToolTip(stack, slot, armorIndex)
),
Renderable.placeholder(containerWidth, hoverableSizes[armorIndex]),
bypassChecks = true
@@ -213,6 +216,24 @@ object CustomWardrobe {
return Renderable.verticalContainer(loreList, spacing = 1)
}
+ private fun getToolTip(
+ stack: ItemStack,
+ slot: WardrobeSlot,
+ armorIndex: Int,
+ ): List<String> {
+ // Get tooltip from minecraft and other mods
+ // TODO add support for advanced tooltip (F3+H)
+ val toolTips = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false)
+
+ // Modify tooltip via SkyHanni Events
+ val mcSlotId = slot.inventorySlots[armorIndex]
+ // if the slot is null, we don't fire LorenzToolTipEvent at all.
+ val mcSlot = InventoryUtils.getSlotAtIndex(mcSlotId) ?: return toolTips
+ LorenzToolTipEvent(mcSlot, stack, toolTips).postAndCatch()
+
+ return toolTips
+ }
+
private fun createFakePlayerRenderable(
slot: WardrobeSlot,
playerWidth: Double,
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
index 53ee6cf7a..ab0afd93c 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
@@ -111,9 +111,9 @@ object InventoryUtils {
}
}
- fun getItemAtSlotIndex(slotIndex: Int): ItemStack? {
- return getItemsInOpenChest().find { it.slotIndex == slotIndex }?.stack
- }
+ fun getItemAtSlotIndex(slotIndex: Int): ItemStack? = getSlotAtIndex(slotIndex)?.stack
+
+ fun getSlotAtIndex(slotIndex: Int): Slot? = getItemsInOpenChest().find { it.slotIndex == slotIndex }
fun NEUInternalName.getAmountInInventory(): Int = countItemsInLowerInventory { it.getInternalNameOrNull() == this }