2019-12-15 18:33:43 +00:00
|
|
|
From 404c8ec69e874c98023af9914dd56c7863dbc99a Mon Sep 17 00:00:00 2001
|
2019-04-30 01:20:24 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Wed, 4 Jul 2018 03:39:51 -0400
|
|
|
|
Subject: [PATCH] Avoid Chunk Lookups for Entity/TileEntity Current Chunk
|
|
|
|
|
2019-12-15 18:33:43 +00:00
|
|
|
SPECIAL 1.14.1 NOTE:
|
2019-05-14 21:54:32 +00:00
|
|
|
This patch caused a memory leak since the tile entity's chunk was set to null
|
|
|
|
before it was removed. Ensure this issue is resolved!
|
|
|
|
|
2019-04-30 01:20:24 +00:00
|
|
|
In many places where we simply want the current chunk the entity
|
|
|
|
is in, instead of doing a hashmap lookup for it, we now have access
|
|
|
|
to the object directly on the Entity/TileEntity object we can directly grab.
|
|
|
|
|
|
|
|
Use that local value instead to reduce lookups in many hot places.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2019-12-15 18:17:16 +00:00
|
|
|
index 985f30372..67159b8a8 100644
|
2019-04-30 01:20:24 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2019-12-15 18:17:16 +00:00
|
|
|
@@ -776,7 +776,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
|
2019-04-30 01:20:24 +00:00
|
|
|
if (!tileentity.isRemoved() && tileentity.hasWorld()) {
|
|
|
|
BlockPosition blockposition = tileentity.getPosition();
|
|
|
|
|
2019-05-14 02:20:58 +00:00
|
|
|
- if (this.chunkProvider.a(blockposition) && this.getWorldBorder().a(blockposition)) {
|
2019-12-15 18:17:16 +00:00
|
|
|
+ if (tileentity.getCurrentChunk() != null && this.getWorldBorder().a(blockposition)) { // Paper
|
2019-04-30 01:20:24 +00:00
|
|
|
try {
|
|
|
|
gameprofilerfiller.a(() -> {
|
2019-12-15 18:17:16 +00:00
|
|
|
return String.valueOf(TileEntityTypes.a(tileentity.getTileType()));
|
|
|
|
@@ -815,8 +815,11 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
|
2019-04-30 01:20:24 +00:00
|
|
|
this.tileEntityListTick.remove(tileTickPosition--);
|
|
|
|
// Spigot end
|
|
|
|
//this.tileEntityList.remove(tileentity); // Paper - remove unused list
|
|
|
|
- if (this.isLoaded(tileentity.getPosition())) {
|
2019-12-15 18:17:16 +00:00
|
|
|
- this.getChunkAtWorldCoords(tileentity.getPosition()).removeTileEntity(tileentity.getPosition());
|
|
|
|
+ // Paper start - use local chunk reference
|
|
|
|
+ Chunk chunk = tileentity.getCurrentChunk();
|
|
|
|
+ if (chunk != null) {
|
|
|
|
+ chunk.removeTileEntity(tileentity.getPosition());
|
|
|
|
+ // Paper end
|
2019-04-30 01:20:24 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-15 18:17:16 +00:00
|
|
|
}
|
|
|
|
@@ -836,8 +839,8 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
|
2019-04-30 01:20:24 +00:00
|
|
|
}
|
|
|
|
// CraftBukkit end */
|
|
|
|
|
|
|
|
- if (this.isLoaded(tileentity1.getPosition())) {
|
|
|
|
- Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition());
|
|
|
|
+ Chunk chunk = tileentity1.getCurrentChunk(); // Paper
|
|
|
|
+ if (chunk != null) { // Paper
|
|
|
|
IBlockData iblockdata = chunk.getType(tileentity1.getPosition());
|
|
|
|
|
|
|
|
chunk.setTileEntity(tileentity1.getPosition(), tileentity1);
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
2019-12-15 18:17:16 +00:00
|
|
|
index 83fb8737a..c473c7d16 100644
|
2019-04-30 01:20:24 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
2019-12-15 18:17:16 +00:00
|
|
|
@@ -1384,9 +1384,12 @@ public class WorldServer extends World {
|
2019-04-30 01:20:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void removeEntityFromChunk(Entity entity) {
|
|
|
|
- IChunkAccess ichunkaccess = this.getChunkAt(entity.chunkX, entity.chunkZ, ChunkStatus.FULL, false);
|
|
|
|
+ // Paper start
|
|
|
|
+ if (!entity.inChunk) return;
|
|
|
|
+ IChunkAccess ichunkaccess = this.getChunkIfLoaded(entity.chunkX, entity.chunkZ);
|
|
|
|
+ // Paper start
|
|
|
|
|
|
|
|
- if (ichunkaccess instanceof Chunk) {
|
2019-12-15 18:17:16 +00:00
|
|
|
+ if (ichunkaccess != null) { // Paper
|
2019-04-30 01:20:24 +00:00
|
|
|
((Chunk) ichunkaccess).b(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
--
|
2019-12-15 18:33:43 +00:00
|
|
|
2.24.1
|
2019-04-30 01:20:24 +00:00
|
|
|
|