aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/features/BrokenHypeNotif.kt
blob: 589c046850a622af2a32f634032698b388a7b4a2 (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
package dulkirmod.features

import dulkirmod.DulkirMod.Companion.mc
import dulkirmod.config.Config
import dulkirmod.utils.TabListUtils
import dulkirmod.utils.TitleUtils
import dulkirmod.utils.Utils
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound

var oldKill = -1
var oldChampionXp = -1.0
var oldID = ""

fun brokenHypeNotif() {
    if (!Config.notifyHype) return

    var kill = -1
    var championXp = -1.0
    var id = ""

    if (mc.thePlayer == null) return

    val stack: ItemStack = mc.thePlayer.heldItem ?: return

    // get info about held item
    if (stack.hasTagCompound()) {
        val tag: NBTTagCompound = stack.tagCompound
        if (tag.hasKey("ExtraAttributes", 10)) {
            val ea: NBTTagCompound = tag.getCompoundTag("ExtraAttributes")
            if (ea.hasKey("id", 8)) {
                id = ea.getString("id")
            }
            if (ea.hasKey("stats_book", 99)) {
                kill = ea.getInteger("stats_book")
            }
            if (ea.hasKey("champion_combat_xp", 99)) {
                championXp = ea.getDouble("champion_combat_xp")
            }
        }
    }

    // check if same item as previous run
    if (id == "") {
        return
    } else if (id != oldID) {
        // Check if this is a valid item for testing whether bestiary is broken.
        // That is, to be specific, check that it has champion and book of stats.
        // If it doesn't, don't reset because it can't be used anyway.
        if (kill == -1 || championXp == -1.0) {
            return
        }
        // If we get here this is a new item that is legitimate for testing bugged xp, in theory.
        oldID = id
        oldKill = kill
        oldChampionXp = championXp
        return
    }

    // If this section of the code is reached, then we have the same item, and we can check for updated stats
    if (oldKill != kill && oldChampionXp == championXp && TabListUtils.area != "Private Island") {
        mc.thePlayer.playSound("random.anvil_land", 1f * Config.bestiaryNotifVol, 0f)
        val color = Utils.getColorString(Config.bestiaryNotifColor)
        TitleUtils.drawStringForTime("${color}Hype Broken", 5000)
    }
    // update item regardless of whether it is bugged or not
    oldKill = kill
    oldChampionXp = championXp
}