aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/items/ItemDisplayOverlayFeatures.kt
blob: 6a3f7688c57be0393f39115530a87124f6423b79 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package at.hannibal2.skyhanni.items

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiRenderItemEvent
import at.hannibal2.skyhanni.utils.ItemUtils
import at.hannibal2.skyhanni.utils.ItemUtils.cleanName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.between
import at.hannibal2.skyhanni.utils.LorenzUtils.matchRegex
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class ItemDisplayOverlayFeatures {

    @SubscribeEvent
    fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) {
        val item = event.stack ?: return

        if (!LorenzUtils.inSkyblock || item.stackSize != 1) return

        val stackTip = getStackTip(item)

        if (stackTip.isNotEmpty()) {
            GlStateManager.disableLighting()
            GlStateManager.disableDepth()
            GlStateManager.disableBlend()
            event.fr.drawStringWithShadow(
                stackTip,
                (event.x + 17 - event.fr.getStringWidth(stackTip)).toFloat(),
                (event.y + 9).toFloat(),
                16777215
            )
            GlStateManager.enableLighting()
            GlStateManager.enableDepth()
        }

    }

    private fun getStackTip(item: ItemStack): String {
        val name = item.cleanName()

        if (SkyHanniMod.feature.inventory.displayMasterStarNumber) {
            when (name) {
                "First Master Star" -> return "1"
                "Second Master Star" -> return "2"
                "Third Master Star" -> return "3"
                "Fourth Master Star" -> return "4"
                "Fifth Master Star" -> return "5"
            }
        }

        if (SkyHanniMod.feature.inventory.displayMasterSkullNumber) {
            if (name.matchRegex("(.*)Master Skull - Tier .")) {
                return name.substring(name.length - 1)
            }
        }

        if (SkyHanniMod.feature.inventory.displayDungeonHeadFloor) {
            if (name.contains("Golden ") || name.contains("Diamond ")) {
                when {
                    name.contains("Bonzo") -> return "1"
                    name.contains("Scarf") -> return "2"
                    name.contains("Professor") -> return "3"
                    name.contains("Thorn") -> return "4"
                    name.contains("Livid") -> return "5"
                    name.contains("Sadan") -> return "6"
                    name.contains("Necron") -> return "7"
                }
            }
        }

        if (SkyHanniMod.feature.inventory.displayNewYearCakeNumber) {
            if (name.startsWith("New Year Cake (")) {
                return "§b" + name.between("(Year ", ")")
            }
        }

        if (SkyHanniMod.feature.inventory.displayPetLevel) {
            if (ItemUtils.isPet(name)) {
                val level = name.between("Lvl ", "] ").toInt()
                if (level != ItemUtils.maxPetLevel(name)) {
                    return "$level"
                }
            }
        }

        if (SkyHanniMod.feature.inventory.displaySackName) {
            if (ItemUtils.isSack(name)) {
                //TODO fix this and replace other
//                val sackName = grabSackName(name)
                val split = name.split(" ")
                val sackName = split[split.size - 2]
                return (if (name.contains("Enchanted")) "§5" else "") + sackName.substring(0, 2)
            }
        }

        if (SkyHanniMod.feature.inventory.displayMinionTier) {
            if (name.contains(" Minion ")) {
                if (item.getLore().any { it.contains("Place this minion") }) {
                    val array = name.split(" ")
                    val last = array[array.size - 1]
                    return last.romanToDecimal().toString()
                }
            }
        }

        return ""
    }

//    private fun grabSackName(name: String): String {
//        val split = name.split(" ")
//        val text = split[0]
//        for (line in arrayOf("Large", "Medium", "Small", "Enchanted")) {
//            if (text == line) return grabSackName(name.substring(text.length + 1))
//        }
//        return text
//    }
}