summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-09-07 12:58:45 +0200
committerLorenz <lo.scherf@gmail.com>2022-09-07 12:58:45 +0200
commit0dcd85d1103e5b8072aa97e186e986febbe6a60b (patch)
tree176539e2f9da95d3bbdb28739886b7ee06adc0b9 /src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt
parent9eac32ec67cd3a1ee5058322125f1350414c64ba (diff)
parenta1f6a1f7f0cda8e6234b4a9d7ea3b823d63049d3 (diff)
downloadskyhanni-0dcd85d1103e5b8072aa97e186e986febbe6a60b.tar.gz
skyhanni-0dcd85d1103e5b8072aa97e186e986febbe6a60b.tar.bz2
skyhanni-0dcd85d1103e5b8072aa97e186e986febbe6a60b.zip
Merge remote-tracking branch 'origin/dev' into dev
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt
new file mode 100644
index 000000000..1e07a6eaa
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt
@@ -0,0 +1,47 @@
+package at.hannibal2.skyhanni.data
+
+import at.hannibal2.skyhanni.events.EntityMoveEvent
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzVec
+import at.hannibal2.skyhanni.utils.getLorenzVec
+import net.minecraft.entity.Entity
+import net.minecraftforge.event.world.WorldEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import net.minecraftforge.fml.common.gameevent.TickEvent
+
+class EntityMovementData {
+
+ companion object {
+ private val entityLocation = mutableMapOf<Entity, LorenzVec>()
+
+ fun addToTrack(entity: Entity) {
+ if (entity !in entityLocation) {
+ entityLocation[entity] = entity.getLorenzVec()
+ }
+ }
+ }
+
+ var tick = 0
+
+ @SubscribeEvent
+ fun onTick(event: TickEvent.ClientTickEvent) {
+ if (!LorenzUtils.inSkyblock) return
+
+ 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).postAndCatch()
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onWorldChange(event: WorldEvent.Load) {
+ entityLocation.clear()
+ }
+} \ No newline at end of file