aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/features/BrokenHyp.kt
blob: 713a9d1404b40d173577866a979b7e229b35e29f (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
package com.dulkirfabric.features

import com.dulkirfabric.DulkirModFabric.mc
import com.dulkirfabric.config.DulkirConfig
import com.dulkirfabric.events.LongUpdateEvent
import com.dulkirfabric.util.TablistUtils
import com.dulkirfabric.util.render.HudRenderUtil
import meteordevelopment.orbit.EventHandler
import net.minecraft.component.DataComponentTypes
import net.minecraft.item.ItemStack
import net.minecraft.text.Style
import net.minecraft.text.Text
import net.minecraft.util.Formatting
import java.time.Duration


object BrokenHyp {

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

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

    @EventHandler
    fun onLong(event: LongUpdateEvent) {
        if (!DulkirConfig.configOptions.brokenHypNotif) return
        val stack: ItemStack = mc.player?.mainHandStack ?: return

        // get info about held item
        val tag = stack.get(DataComponentTypes.CUSTOM_DATA)?.nbt ?: return
        id = tag.getString("id") ?: ""

        kill = tag.getInt("stats_book") ?: -1
        championXp = tag.getDouble("champion_combat_xp") ?: -1.0

        // check if a wither blade, then check if same id
        if (!(id matches "(HYPERION|ASTRAEA|SCYLLA|VALKYRIE)".toRegex())) {
            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.persistentInfo.area != "Private Island") {
            HudRenderUtil.drawTitle(Text.literal("Hype Broken").setStyle(Style.EMPTY.withColor(Formatting.RED)),
                Duration.ofSeconds(2))
        }
        // update item regardless of whether it is bugged or not
        oldKill = kill
        oldChampionXp = championXp
    }
}