aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0391-Ensure-Entity-position-and-AABB-are-never-invalid.patch
blob: c74d2ed12ef65932c007f62e652d9004f991c5ac (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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 10 May 2020 22:12:46 -0400
Subject: [PATCH] Ensure Entity position and AABB are never invalid

Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>

diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 47094050283625e3b494f5ab6955a2f9c736388d..70380d5807cac6dec19ebe581d685b1e32d8830b 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -639,8 +639,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
     }
 
     public void setPos(double x, double y, double z) {
-        this.setPosRaw(x, y, z);
-        this.setBoundingBox(this.makeBoundingBox());
+        this.setPosRaw(x, y, z, true); // Paper - Block invalid positions and bounding box; force update
+        // this.setBoundingBox(this.makeBoundingBox()); // Paper - Block invalid positions and bounding box; move into setPosRaw
     }
 
     protected AABB makeBoundingBox() {
@@ -4130,7 +4130,29 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
         return this.getZ((2.0D * this.random.nextDouble() - 1.0D) * widthScale);
     }
 
+    // Paper start - Block invalid positions and bounding box
+    public static boolean checkPosition(Entity entity, double newX, double newY, double newZ) {
+        if (Double.isFinite(newX) && Double.isFinite(newY) && Double.isFinite(newZ)) {
+            return true;
+        }
+
+        String entityInfo;
+        try {
+            entityInfo = entity.toString();
+        } catch (Exception ex) {
+            entityInfo = "[Entity info unavailable] ";
+        }
+        LOGGER.error("New entity position is invalid! Tried to set invalid position ({},{},{}) for entity {} located at {}, entity info: {}", newX, newY, newZ, entity.getClass().getName(), entity.position, entityInfo, new Throwable());
+        return false;
+    }
     public final void setPosRaw(double x, double y, double z) {
+        this.setPosRaw(x, y, z, false);
+    }
+    public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) {
+        if (!checkPosition(this, x, y, z)) {
+            return;
+        }
+        // Paper end - Block invalid positions and bounding box
         if (this.position.x != x || this.position.y != y || this.position.z != z) {
             this.position = new Vec3(x, y, z);
             int i = Mth.floor(x);
@@ -4148,6 +4170,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
             this.levelCallback.onMove();
         }
 
+        // Paper start - Block invalid positions and bounding box; don't allow desync of pos and AABB
+        // hanging has its own special logic
+        if (!(this instanceof net.minecraft.world.entity.decoration.HangingEntity) && (forceBoundingBoxUpdate || this.position.x != x || this.position.y != y || this.position.z != z)) {
+            this.setBoundingBox(this.makeBoundingBox());
+        }
+        // Paper end - Block invalid positions and bounding box
     }
 
     public void checkDespawn() {}