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-03-23 22:26:17 +01:00
index 23ee63119d55b40829c03a855ae0f8b214674e10..0c6680bf15b57cf314638ab70d849e033719c0e1 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
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
@@ -652,8 +652,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
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-02-23 23:13:37 +01:00
@@ -4149,7 +4149,29 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
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-02-23 23:13:37 +01:00
@@ -4167,6 +4189,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
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() {}