aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/diana/GriffinBurrowFinder.kt
blob: 9cbabfa2f0c0df815105708992c5867c34d0ee4b (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package at.hannibal2.skyhanni.diana

import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.test.GriffinUtils.draw3DLine
import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypoint
import at.hannibal2.skyhanni.utils.*
import at.hannibal2.skyhanni.utils.ItemUtils.cleanName
import net.minecraft.client.Minecraft
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.network.play.server.S29PacketSoundEffect
import net.minecraft.network.play.server.S2APacketParticles
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
import java.util.*

class GriffinBurrowFinder {

    private var ticks = 0
    val list = mutableListOf<UUID>()
    var lastArrowLine: Line? = null

    @SubscribeEvent
    fun onClientTick(event: ClientTickEvent?) {
        if (!LorenzUtils.inSkyblock) return
        ticks++
        if (ticks % 5 == 0) {
            checkEntities()
        }
    }

    @SubscribeEvent
    fun onWorldChange(event: WorldEvent.Load) {
        lastArrowLine = null
    }

    @SubscribeEvent
    fun onChatMessage(event: LorenzChatEvent) {
        val message = event.message
        if (message.startsWith("§eYou dug out a Griffin Burrow!") ||
            message == "§eYou finished the Griffin burrow chain! §r§7(4/4)"
        ) {
            lastArrowLine = null
        }
    }

    @SubscribeEvent
    fun onWorldRender(event: RenderWorldLastEvent) {
        if (lastArrowLine != null) {
            var start = lastArrowLine!!.start
            val y = (Minecraft.getMinecraft().thePlayer.position.y - 1).toDouble()
            start = LorenzVec(start.x, y, start.z)
            val direction = lastArrowLine!!.direction

            event.drawWaypoint(start, LorenzColor.WHITE)
            val nextPoint = start.add(direction.multiply(10))
//            event.drawWaypoint(nextPoint, LorenzColor.YELLOW)

            event.draw3DLine(start, start.add(direction.multiply(400)), LorenzColor.YELLOW, 3, true)
        }
    }

    var lastHarpTime = 0L
    var lastHarpPitch = 0f
    var lastHarpDistance = 0.0

    @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
    fun onChatPacket(event: PacketEvent.ReceiveEvent) {
        val packet = event.packet
        if (packet is S2APacketParticles) {
            val x = packet.xCoordinate
            val y = packet.yCoordinate
            val z = packet.zCoordinate
            val distance = LorenzVec(x, y, z).distance(Minecraft.getMinecraft().thePlayer.getLorenzVec())
            if (distance < 20) {
//                LorenzDebug.log("")
//                LorenzDebug.log("S2APacketParticles close")
//                var particleType = packet.particleType
//                var particleID = particleType.particleID
//                LorenzDebug.log("particleType: $particleType")
//                LorenzDebug.log("particleID: $particleID")
//                LorenzDebug.log("distance: $distance")
//                LorenzDebug.log("")

            } else {
//                LorenzDebug.log("S2APacketParticles far")
            }
        }
        if (packet is S29PacketSoundEffect) {
            val x = packet.x
            val y = packet.y
            val z = packet.z
            val distance = LorenzVec(x, y, z).distance(Minecraft.getMinecraft().thePlayer.getLorenzVec())
            if (distance < 20) {
                val soundName = packet.soundName
                val pitch = packet.pitch
                val volume = packet.volume
                if (soundName == "game.player.hurt" && volume == 0f) return

                if (soundName == "note.harp") {

                    LorenzDebug.log("harp pitch: $pitch")
                    LorenzDebug.log("distance: $distance")
                    val now = System.currentTimeMillis()
                    if (lastHarpTime != 0L) {
                        LorenzDebug.log("")
                        val diffTime = now - lastHarpTime
                        LorenzDebug.log("diffTime: $diffTime")
                        val diffPitch = pitch - lastHarpPitch
                        LorenzDebug.log("diffPitch: $diffPitch")
                        val diffDistance = distance - lastHarpDistance
                        LorenzDebug.log("diffDistance: $diffDistance")
                    }
                    lastHarpTime = now
                    lastHarpPitch = pitch
                    lastHarpDistance = distance
                    LorenzDebug.log("")
                    return
                }

                LorenzDebug.log("")
                LorenzDebug.log("S29PacketSoundEffect close")

                LorenzDebug.log("soundName: $soundName")
                LorenzDebug.log("pitch: $pitch")
                LorenzDebug.log("volume: $volume")
                LorenzDebug.log("")
            } else {
//                LorenzDebug.log("S29PacketSoundEffect far")
            }
        }
    }

    private fun checkEntities() {
        val playerLocation = Minecraft.getMinecraft().thePlayer.position.toLorenzVec()
        for (entity in Minecraft.getMinecraft().theWorld.loadedEntityList) {
            if (list.contains(entity.uniqueID)) continue
            if (entity !is EntityArmorStand) continue
            val distance = entity.getLorenzVec().distance(playerLocation)
            if (distance > 10) continue


            val itemStack = entity.inventory[0] ?: continue
            if (itemStack.cleanName() != "Arrow") continue

            val rotationYaw = entity.rotationYaw
            val direction = LorenzVec.getFromYawPitch(rotationYaw.toDouble(), 0.0)

            lastArrowLine = Line(entity.getLorenzVec(), direction)
            list.add(entity.uniqueID)
            LorenzDebug.log("distance: $distance")
        }
    }

    class Line(val start: LorenzVec, val direction: LorenzVec)
}