mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-23 00:49:31 +00:00
39 lines
1.2 KiB
Diff
39 lines
1.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: wangxyper <wangxyper@163.com>
|
|
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;
|
|
+ }
|
|
+}
|