3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 19:10:09 +01:00

Fix weird bugs with entities - Fixes #1195

Dieser Commit ist enthalten in:
Aikar 2018-07-05 18:39:43 -04:00
Ursprung 0ae8b2f893
Commit 17525cd54b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 401ADFC9891FAAFE
14 geänderte Dateien mit 61 neuen und 50 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,4 @@
From b55307c8ea1237c0893145e14f48e2e98a68fc5b Mon Sep 17 00:00:00 2001
From 75b50cf5c33d0049e9670329132d0d2521f7f91a Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 4 Jul 2018 02:10:36 -0400
Subject: [PATCH] Store reference to current Chunk for Entity and Block
@ -8,9 +8,18 @@ This enables us a fast reference to the entities current chunk instead
of having to look it up by hashmap lookups.
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 4bbebb25a..b40e60942 100644
index 4bbebb25a..68008fe6a 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -25,7 +25,7 @@ public class Chunk {
private final byte[] g;
private final int[] h;
private final boolean[] i;
- private boolean j;
+ private boolean j; public boolean isLoaded() { return j; } // Paper - OBFHELPER
public final World world;
public final int[] heightMap;
public final int locX;
@@ -33,6 +33,30 @@ public class Chunk {
private boolean m;
public final Map<BlockPosition, TileEntity> tileEntities;
@ -72,16 +81,17 @@ index 4bbebb25a..b40e60942 100644
}
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 3a8902bf1..3829c8c40 100644
index 3a8902bf1..ed090cc50 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1703,6 +1703,13 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@@ -1703,6 +1703,14 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
}
// Paper start
+ private java.lang.ref.WeakReference<Chunk> currentChunk = null;
+ public Chunk getCurrentChunk() {
+ return currentChunk != null ? currentChunk.get() : null;
+ final Chunk chunk = currentChunk != null ? currentChunk.get() : world.getChunkIfLoaded(getChunkX(), getChunkZ());
+ return chunk != null && chunk.isLoaded() ? chunk : null;
+ }
+ public void setCurrentChunk(Chunk chunk) {
+ this.currentChunk = chunk != null ? new java.lang.ref.WeakReference<>(chunk) : null;
@ -90,16 +100,17 @@ index 3a8902bf1..3829c8c40 100644
public final String entityKeyString = entityKey != null ? entityKey.toString() : null;
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
index 672ba3134..88cd5734d 100644
index 672ba3134..d7132c3c0 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
@@ -28,6 +28,13 @@ public abstract class TileEntity implements KeyedObject {
@@ -28,6 +28,14 @@ public abstract class TileEntity implements KeyedObject {
}
// Paper start
+ private java.lang.ref.WeakReference<Chunk> currentChunk = null;
+ public Chunk getCurrentChunk() {
+ return currentChunk != null ? currentChunk.get() : null;
+ final Chunk chunk = currentChunk != null ? currentChunk.get() : world.getChunkIfLoaded(position.getX() >> 4, position.getZ() >> 4);
+ return chunk != null && chunk.isLoaded() ? chunk : null;
+ }
+ public void setCurrentChunk(Chunk chunk) {
+ this.currentChunk = chunk != null ? new java.lang.ref.WeakReference<>(chunk) : null;

Datei anzeigen

@ -1,4 +1,4 @@
From ce52b463a57dd7ff4bc91a569a0da9c9b7080c99 Mon Sep 17 00:00:00 2001
From 8c61ede82f1c1292632024336a7dc758559ab8d9 Mon Sep 17 00:00:00 2001
From: Byteflux <byte@byteflux.net>
Date: Tue, 1 Mar 2016 14:14:15 -0600
Subject: [PATCH] Drop falling block and tnt entities at the specified height
@ -24,10 +24,10 @@ index 0094d1a87..4da846719 100644
+ }
}
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 8dcff9bd4..041af8070 100644
index 137da4255..655340c0b 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1769,6 +1769,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@@ -1770,6 +1770,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
return this.a(new ItemStack(item, i, 0), f);
}

Datei anzeigen

@ -1,11 +1,11 @@
From 76865dffb1ead34f79aa346277c16a9b22d88ba0 Mon Sep 17 00:00:00 2001
From a9191e155ef7c4f82b15db6b6530fb7037159b91 Mon Sep 17 00:00:00 2001
From: Byteflux <byte@byteflux.net>
Date: Tue, 1 Mar 2016 23:45:08 -0600
Subject: [PATCH] Entity Origin API
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 041af8070..43b802855 100644
index 655340c0b..a96513e27 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -149,6 +149,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@ -42,7 +42,7 @@ index 041af8070..43b802855 100644
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Loading entity NBT");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being loaded");
@@ -1731,6 +1744,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@@ -1732,6 +1745,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
protected abstract void b(NBTTagCompound nbttagcompound);

Datei anzeigen

@ -1,14 +1,14 @@
From 277b632fc83ffd69f3a61a439efac380e63ffa4b Mon Sep 17 00:00:00 2001
From a949306e1efe3b5ba7ae41b9ea584778b59a5265 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 1 Mar 2016 23:52:34 -0600
Subject: [PATCH] Prevent tile entity and entity crashes
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
index c1f657808..dfdc55583 100644
index 15f18ba1d..33e245e4c 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
@@ -195,7 +195,12 @@ public abstract class TileEntity implements KeyedObject {
@@ -196,7 +196,12 @@ public abstract class TileEntity implements KeyedObject {
}
});
if (this.world != null) {

Datei anzeigen

@ -1,4 +1,4 @@
From b66a86a51ef63edaa49df63bb3cee22e5822e1bb Mon Sep 17 00:00:00 2001
From 00f58d4e46fd30f9bf89b67139eefd50087366b8 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 8 Mar 2016 23:25:45 -0500
Subject: [PATCH] Disable Scoreboards for non players by default
@ -37,10 +37,10 @@ index ec9a87239..b08274d93 100644
if (scoreboard.addPlayerToTeam(s2, s)) {
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 584501787..b4ad611fc 100644
index 21118c031..921b442cd 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -2098,6 +2098,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@@ -2099,6 +2099,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@Nullable
public ScoreboardTeamBase aY() {

Datei anzeigen

@ -1,4 +1,4 @@
From 6e950d7d4b2c87219dfecf46db8af308e8679023 Mon Sep 17 00:00:00 2001
From f51d39ceefb609670b7c3799893a8fe877955807 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 22 Mar 2016 00:55:23 -0400
Subject: [PATCH] Don't teleport dead entities
@ -7,10 +7,10 @@ Had some issue with this in past, and this is the vanilla logic.
Potentially an old CB change that's no longer needed.
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 4a08db5ba..d4ab5fba9 100644
index e8775e66c..7e992aeaa 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -2374,7 +2374,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@@ -2375,7 +2375,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
}
public Entity teleportTo(Location exit, boolean portal) {

Datei anzeigen

@ -1,4 +1,4 @@
From 707f3e9ccf6dd76cc11dbfd61a6ffaf74f563fa6 Mon Sep 17 00:00:00 2001
From ebf30115a7e355668afb258d7e4e96fb9e955442 Mon Sep 17 00:00:00 2001
From: Zach Brown <zach.brown@destroystokyo.com>
Date: Wed, 6 Apr 2016 01:04:23 -0500
Subject: [PATCH] Option to use vanilla per-world scoreboard coloring on names
@ -19,10 +19,10 @@ index abc1aabdd..6ea608ba9 100644
+ }
}
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index d4ab5fba9..7314b4dc5 100644
index 7e992aeaa..08d872318 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -2097,6 +2097,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@@ -2098,6 +2098,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
return this.getFlag(5);
}

Datei anzeigen

@ -1,11 +1,11 @@
From e68a92dac303b69a9ef4935be8935e649a415431 Mon Sep 17 00:00:00 2001
From e33a8ba3bed690fc4acd04253812a8a1285b8e93 Mon Sep 17 00:00:00 2001
From: Zach Brown <zach.brown@destroystokyo.com>
Date: Fri, 22 Apr 2016 18:20:05 -0500
Subject: [PATCH] Vehicle Event Cancellation Changes
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 7314b4dc5..d1f07bbbd 100644
index 08d872318..e6a5bc53c 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -70,7 +70,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@ -17,7 +17,7 @@ index 7314b4dc5..d1f07bbbd 100644
public boolean attachedToPlayer;
public World world;
public double lastX;
@@ -1979,6 +1979,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@@ -1980,6 +1980,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)");
} else {
// CraftBukkit start
@ -25,7 +25,7 @@ index 7314b4dc5..d1f07bbbd 100644
CraftEntity craft = (CraftEntity) entity.getBukkitEntity().getVehicle();
Entity orig = craft == null ? null : craft.getHandle();
if (getBukkitEntity() instanceof Vehicle && entity.getBukkitEntity() instanceof LivingEntity) {
@@ -1994,7 +1995,13 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@@ -1995,7 +1996,13 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
}
}
// CraftBukkit end

Datei anzeigen

@ -1,4 +1,4 @@
From 13aa672d8cfd736c9c7210ce4fc8a2183e8aee00 Mon Sep 17 00:00:00 2001
From a179a7106eeb9eb6bd522fb5cc69a752f4d6bbc4 Mon Sep 17 00:00:00 2001
From: Zach Brown <zach.brown@destroystokyo.com>
Date: Sun, 22 May 2016 20:20:55 -0500
Subject: [PATCH] Optional TNT doesn't move in water
@ -32,7 +32,7 @@ index 067cb233e..06acdaaf0 100644
+ }
}
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 945f06c93..cb9ef622c 100644
index 0412e183a..9ce691061 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1114,6 +1114,11 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@ -47,7 +47,7 @@ index 945f06c93..cb9ef622c 100644
if (this.bJ() instanceof EntityBoat) {
this.inWater = false;
} else if (this.world.a(this.getBoundingBox().grow(0.0D, -0.4000000059604645D, 0.0D).shrink(0.001D), Material.WATER, this)) {
@@ -2562,6 +2567,11 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@@ -2563,6 +2568,11 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
}
public boolean bo() {

Datei anzeigen

@ -1,4 +1,4 @@
From 6b71f1dfeb183e977699e690bc59fa6e0acae336 Mon Sep 17 00:00:00 2001
From f4451963bcdefb63b5331539e134a7d553c06fe0 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 18 Jun 2016 23:22:12 -0400
Subject: [PATCH] Delay Chunk Unloads based on Player Movement
@ -40,11 +40,11 @@ index ce43e7bb7..e35e72e8b 100644
+ }
}
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 857df2937..cc9c8b2e0 100644
index 3904a1b8f..bcf68af4f 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -30,6 +30,7 @@ public class Chunk {
private boolean j;
private boolean j; public boolean isLoaded() { return j; } // Paper - OBFHELPER
public final World world;
public final int[] heightMap;
+ public Long scheduledForUnload; // Paper - delay chunk unloads

Datei anzeigen

@ -1,14 +1,14 @@
From 4ca9bb5d12ac04c752cf8983bc7780c811a32a2e Mon Sep 17 00:00:00 2001
From 80e2a4d03877b2324f2047a4aa526ad9f23a863b Mon Sep 17 00:00:00 2001
From: Alfie Cleveland <alfeh@me.com>
Date: Sun, 8 Jan 2017 04:31:36 +0000
Subject: [PATCH] Don't allow entities to ride themselves - #572
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index b13830e87..20324deeb 100644
index 0ed9a8413..646a2d673 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1956,6 +1956,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@@ -1957,6 +1957,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
}
protected void o(Entity entity) {

Datei anzeigen

@ -1,4 +1,4 @@
From d92126ecf2330dfafa65d2dde1dd6d1966cd5ca1 Mon Sep 17 00:00:00 2001
From 955230d3e8ac631d5b64a60aab4c0c97dc0e95ba Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 6 Nov 2017 21:08:22 -0500
Subject: [PATCH] API to get a BlockState without a snapshot
@ -13,10 +13,10 @@ also Avoid NPE during CraftBlockEntityState load if could not get TE
If Tile Entity was null, correct Sign to return empty lines instead of null
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
index d3bc13726..cc7f2069d 100644
index 358c99227..5b5f102e2 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
@@ -284,7 +284,12 @@ public abstract class TileEntity implements KeyedObject {
@@ -285,7 +285,12 @@ public abstract class TileEntity implements KeyedObject {
}
// CraftBukkit start - add method
@ -29,7 +29,7 @@ index d3bc13726..cc7f2069d 100644
if (world == null) return null;
// Spigot start
org.bukkit.block.Block block = world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
@@ -293,7 +298,7 @@ public abstract class TileEntity implements KeyedObject {
@@ -294,7 +299,7 @@ public abstract class TileEntity implements KeyedObject {
return null;
}
// Spigot end

Datei anzeigen

@ -1,4 +1,4 @@
From 7c407762bcc2b69d4ca0e87929e1fd0913060e26 Mon Sep 17 00:00:00 2001
From ce497ce0dd8da9d9b5a3bbddf60f8bfcd70fd03e Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 27 Apr 2016 22:09:52 -0400
Subject: [PATCH] Optimize Hoppers
@ -40,10 +40,10 @@ index fcf6bac08..3092913f5 100644
this.methodProfiler.a(() -> {
return worldserver.getWorldData().getName();
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
index cc7f2069d..78ce2f8bb 100644
index 5b5f102e2..3f6b34489 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
@@ -54,6 +54,7 @@ public abstract class TileEntity implements KeyedObject {
@@ -55,6 +55,7 @@ public abstract class TileEntity implements KeyedObject {
return (MinecraftKey) TileEntity.f.b(oclass);
}
@ -51,7 +51,7 @@ index cc7f2069d..78ce2f8bb 100644
public World getWorld() {
return this.world;
}
@@ -132,6 +133,7 @@ public abstract class TileEntity implements KeyedObject {
@@ -133,6 +134,7 @@ public abstract class TileEntity implements KeyedObject {
public void update() {
if (this.world != null) {

Datei anzeigen

@ -1,4 +1,4 @@
From f1e9152d385aad3dee238c0d2bb920216be1f6d0 Mon Sep 17 00:00:00 2001
From 3bb876e1ca8ad360cad539ed4c278b146a44f71c Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 10 Jun 2018 20:04:42 -0400
Subject: [PATCH] Properly remove entities on dimension teleport
@ -22,10 +22,10 @@ requirement, but plugins (such as my own) use this method to
trigger a "reload" of the entity on the client.
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 00791faf2..70641d479 100644
index fccaebfbd..5d1ea0d55 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -2424,7 +2424,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
@@ -2425,7 +2425,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
}
// CraftBukkit end */