78 lines
3.9 KiB
Diff
78 lines
3.9 KiB
Diff
|
From 9c190db2972a8f21254928867c46fb46f765ea81 Mon Sep 17 00:00:00 2001
|
||
|
From: Aikar <aikar@aikar.co>
|
||
|
Date: Wed, 4 Jul 2018 03:39:51 -0400
|
||
|
Subject: [PATCH] Avoid Chunk Lookups for Entity/TileEntity Current Chunk
|
||
|
|
||
|
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
|
||
|
index 3737fca81..6bd181565 100644
|
||
|
--- a/src/main/java/net/minecraft/server/World.java
|
||
|
+++ b/src/main/java/net/minecraft/server/World.java
|
||
|
@@ -759,7 +759,8 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
||
|
if (!tileentity.isRemoved() && tileentity.hasWorld()) {
|
||
|
BlockPosition blockposition = tileentity.getPosition();
|
||
|
|
||
|
- if (this.isLoaded(blockposition) && this.getWorldBorder().a(blockposition)) {
|
||
|
+ Chunk currentChunk = tileentity.getCurrentChunk(); // Paper
|
||
|
+ if (currentChunk != null && this.getWorldBorder().a(blockposition)) { // Paper
|
||
|
try {
|
||
|
gameprofilerfiller.a(() -> {
|
||
|
return String.valueOf(TileEntityTypes.a(tileentity.q()));
|
||
|
@@ -793,7 +794,7 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
||
|
this.tileEntityListTick.remove(tileTickPosition--);
|
||
|
// Spigot end
|
||
|
//this.tileEntityList.remove(tileentity); // Paper - remove unused list
|
||
|
- if (this.isLoaded(tileentity.getPosition())) {
|
||
|
+ if (tileentity.getCurrentChunk() != null ) { // Paper - avoid lookups
|
||
|
this.getChunkAtWorldCoords(tileentity.getPosition()).removeTileEntity(tileentity.getPosition());
|
||
|
}
|
||
|
}
|
||
|
@@ -814,8 +815,9 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
||
|
}
|
||
|
// CraftBukkit end */
|
||
|
|
||
|
- if (this.isLoaded(tileentity1.getPosition())) {
|
||
|
- Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition());
|
||
|
+ Chunk chunk = tileentity1.getCurrentChunk(); // Paper
|
||
|
+ if (chunk != null) { // Paper
|
||
|
+ //Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition()); // 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
|
||
|
index 79be8cfa3..af62ab182 100644
|
||
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
||
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
||
|
@@ -1068,7 +1068,7 @@ public class WorldServer extends World {
|
||
|
}
|
||
|
|
||
|
this.entitiesByUUID.remove(entity.getUniqueID());
|
||
|
- this.getChunkProvider().removeEntity(entity);
|
||
|
+ if (entity.getCurrentChunk() != null ) this.getChunkProvider().removeEntity(entity); // Paper
|
||
|
if (entity instanceof EntityPlayer) {
|
||
|
EntityPlayer entityplayer = (EntityPlayer) entity;
|
||
|
|
||
|
@@ -1122,9 +1122,12 @@ public class WorldServer extends World {
|
||
|
}
|
||
|
|
||
|
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) {
|
||
|
+ if (ichunkaccess != null) {
|
||
|
((Chunk) ichunkaccess).b(entity);
|
||
|
}
|
||
|
|
||
|
--
|
||
|
2.21.0
|
||
|
|