From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: wangxyper Date: Mon, 16 Jan 2023 19:05:17 +0800 Subject: [PATCH] Hearse: Add entity position cache to fix concurrent problem-1 Original license: MIT Original project: https://github.com/Era4FunMC/Hearse diff --git a/src/main/java/co/earthme/hearse/util/EntityPositionCache.java b/src/main/java/co/earthme/hearse/util/EntityPositionCache.java new file mode 100644 index 0000000000000000000000000000000000000000..0ff6ef85758c4f5780860178572e128080470d04 --- /dev/null +++ b/src/main/java/co/earthme/hearse/util/EntityPositionCache.java @@ -0,0 +1,24 @@ +package co.earthme.hearse.util; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.Vec3; + +public class EntityPositionCache { + private final double x; + private final double y; + private final double z; + + public EntityPositionCache(Entity entity){ + this.x = entity.getX(); + this.y = entity.getY(); + this.z = entity.getZ(); + } + + public double distanceToSqr(Vec3 vector) { + double d0 = this.x - vector.x; + double d1 = this.y - vector.y; + double d2 = this.z - vector.z; + + return d0 * d0 + d1 * d1 + d2 * d2; + } +}