aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-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 }