blob: 92a36b62363ddc93de2078d637f7be173921b51f (
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
|
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.events.EntityMoveEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWarpEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.getLorenzVec
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.entity.Entity
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@SkyHanniModule
object EntityMovementData {
private val warpingPattern by RepoPattern.pattern(
"data.entity.warping",
"§7(?:Warping|Warping you to your SkyBlock island|Warping using transfer token|Finding player|Sending a visit request)\\.\\.\\."
)
private val entityLocation = mutableMapOf<Entity, LorenzVec>()
fun addToTrack(entity: Entity) {
if (entity !in entityLocation) {
entityLocation[entity] = entity.getLorenzVec()
}
}
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!LorenzUtils.inSkyBlock) return
addToTrack(Minecraft.getMinecraft().thePlayer)
for (entity in entityLocation.keys) {
if (entity.isDead) continue
val newLocation = entity.getLorenzVec()
val oldLocation = entityLocation[entity]!!
val distance = newLocation.distance(oldLocation)
if (distance > 0.01) {
entityLocation[entity] = newLocation
EntityMoveEvent(entity, oldLocation, newLocation, distance).postAndCatch()
}
}
}
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!warpingPattern.matches(event.message)) return
DelayedRun.runNextTick {
LorenzWarpEvent().postAndCatch()
}
}
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
entityLocation.clear()
}
}
|