aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/ToolTipData.kt
blob: 258cb244e1564c277a59c31eed9d65f142a20dfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.events.item.ItemHoverEvent
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
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
object ToolTipData {

    @JvmStatic
    fun getTooltip(stack: ItemStack, toolTip: MutableList<String>): List<String> {
        onHover(stack, toolTip)
        return onTooltip(toolTip)
    }

    private fun onHover(stack: ItemStack, toolTip: MutableList<String>) {
        ItemHoverEvent(stack, toolTip).postAndCatch()
    }

    fun onTooltip(toolTip: MutableList<String>): List<String> {
        val slot = lastSlot ?: return toolTip
        val itemStack = slot.stack ?: return toolTip
        try {
            if (LorenzToolTipEvent(slot, itemStack, toolTip).postAndCatch()) {
                toolTip.clear()
            }
        } catch (e: Throwable) {
            ErrorManager.logErrorWithData(
                e, "Error in item tool tip parsing or rendering detected",
                "toolTip" to toolTip,
                "slot" to slot,
                "slotNumber" to slot.slotNumber,
                "slotIndex" to slot.slotIndex,
                "itemStack" to itemStack,
                "name" to itemStack.name,
                "internal name" to itemStack.getInternalName(),
                "lore" to itemStack.getLore(),
            )
        }
        return toolTip
    }

    var lastSlot: Slot? = null

}