2021-06-14 10:37:14 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 10 May 2020 22:12:46 -0400
2024-01-19 12:30:04 +01:00
Subject: [PATCH] Ensure Entity position and AABB are never invalid
2021-06-14 10:37:14 +02:00
2024-01-19 12:30:04 +01:00
Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
2021-06-14 10:37:14 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
2024-10-23 16:55:24 +02:00
index 4faba83eb73e0d313e9131794962b727f7628a50..7fdfe1dd09812df1d8d7e5f95bcaf1b48c814e22 100644
2021-06-14 10:37:14 +02:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2024-10-23 16:55:24 +02:00
@@ -677,8 +677,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
2021-07-09 03:18:32 +02:00
}
2021-06-14 10:37:14 +02:00
public void setPos(double x, double y, double z) {
2021-07-09 03:18:32 +02:00
- this.setPosRaw(x, y, z);
2021-06-14 10:37:14 +02:00
- this.setBoundingBox(this.makeBoundingBox());
2024-01-19 12:30:04 +01:00
+ 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
2021-06-14 10:37:14 +02:00
}
protected AABB makeBoundingBox() {
2024-10-23 16:55:24 +02:00
@@ -4412,7 +4412,29 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
2024-01-19 12:30:04 +01:00
return this.getZ((2.0D * this.random.nextDouble() - 1.0D) * widthScale);
2021-06-14 10:37:14 +02:00
}
2024-01-19 12:30:04 +01:00
+ // 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;
+ }
2021-06-14 10:37:14 +02:00
public final void setPosRaw(double x, double y, double z) {
2021-07-09 03:18:32 +02:00
+ this.setPosRaw(x, y, z, false);
+ }
+ public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) {
2024-01-19 12:30:04 +01:00
+ if (!checkPosition(this, x, y, z)) {
+ return;
+ }
+ // Paper end - Block invalid positions and bounding box
2024-01-24 13:07:40 +01:00
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);
2024-10-23 16:55:24 +02:00
@@ -4430,6 +4452,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
2022-06-08 07:02:19 +02:00
this.levelCallback.onMove();
2021-07-09 03:18:32 +02:00
}
2024-01-19 12:30:04 +01:00
+ // Paper start - Block invalid positions and bounding box; don't allow desync of pos and AABB
2021-07-09 03:18:32 +02:00
+ // 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());
+ }
2024-01-19 12:30:04 +01:00
+ // Paper end - Block invalid positions and bounding box
2021-07-09 03:18:32 +02:00
}
public void checkDespawn() {}