2018-08-05 23:46:43 +00:00
|
|
|
From aa8a90ef5eb5cca3f80f32372e57e32ef42d595c Mon Sep 17 00:00:00 2001
|
2018-07-04 07:56:57 +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
|
|
|
|
|
|
|
|
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/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2018-08-03 05:29:20 +00:00
|
|
|
index d2e87693fa..1997cbdc65 100644
|
2018-07-04 07:56:57 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2018-07-18 23:16:19 +00:00
|
|
|
@@ -721,6 +721,7 @@ public class Chunk implements IChunkAccess {
|
|
|
|
((HeightMap) this.heightMap.get(heightmap_type)).a(along);
|
2018-07-04 07:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ public void removeEntity(Entity entity) { b(entity); } // Paper - OBFHELPER
|
|
|
|
public void b(Entity entity) {
|
2018-07-18 23:16:19 +00:00
|
|
|
this.a(entity, entity.af);
|
2018-07-04 07:56:57 +00:00
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2018-08-05 23:46:43 +00:00
|
|
|
index 852977cab3..fbca973225 100644
|
2018-07-04 07:56:57 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2018-08-04 01:20:57 +00:00
|
|
|
@@ -1221,12 +1221,15 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
2018-07-04 07:56:57 +00:00
|
|
|
int j;
|
|
|
|
// Paper start - Set based removal lists
|
2018-07-18 23:16:19 +00:00
|
|
|
for (Entity e : this.g) {
|
2018-07-04 07:56:57 +00:00
|
|
|
+ /*
|
|
|
|
j = e.getChunkZ();
|
|
|
|
int k = e.getChunkX();
|
|
|
|
|
2018-07-18 23:16:19 +00:00
|
|
|
if (e.inChunk && this.isChunkLoaded(k, j, true)) {
|
2018-07-04 07:56:57 +00:00
|
|
|
this.getChunkAt(k, j).b(e);
|
|
|
|
- }
|
|
|
|
+ }*/
|
2018-07-18 23:16:19 +00:00
|
|
|
+ Chunk chunk = e.inChunk ? e.getCurrentChunk() : null;
|
2018-07-04 07:56:57 +00:00
|
|
|
+ if (chunk != null) chunk.removeEntity(e);
|
|
|
|
}
|
|
|
|
|
2018-07-18 23:16:19 +00:00
|
|
|
for (Entity e : this.g) {
|
2018-08-04 01:20:57 +00:00
|
|
|
@@ -1287,12 +1290,17 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
2018-07-18 23:16:19 +00:00
|
|
|
this.methodProfiler.e();
|
2018-07-04 07:56:57 +00:00
|
|
|
this.methodProfiler.a("remove");
|
|
|
|
if (entity.dead) {
|
|
|
|
+ // Paper start
|
|
|
|
+ /*
|
2018-07-18 23:16:19 +00:00
|
|
|
j = entity.ae;
|
|
|
|
int l = entity.ag;
|
2018-07-04 07:56:57 +00:00
|
|
|
|
2018-07-18 23:16:19 +00:00
|
|
|
if (entity.inChunk && this.isChunkLoaded(j, l, true)) {
|
2018-07-04 07:56:57 +00:00
|
|
|
this.getChunkAt(j, l).b(entity);
|
|
|
|
- }
|
|
|
|
+ }*/
|
2018-07-18 23:16:19 +00:00
|
|
|
+ Chunk chunk = entity.inChunk ? entity.getCurrentChunk() : null;
|
2018-07-04 07:56:57 +00:00
|
|
|
+ if (chunk != null) chunk.removeEntity(entity);
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
guardEntityList = false; // Spigot
|
|
|
|
this.entityList.remove(this.tickPosition--); // CraftBukkit - Use field for loop variable
|
2018-08-04 01:20:57 +00:00
|
|
|
@@ -1337,7 +1345,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
2018-07-04 07:56:57 +00:00
|
|
|
BlockPosition blockposition = tileentity.getPosition();
|
|
|
|
|
|
|
|
// Paper start - Skip ticking in chunks scheduled for unload
|
|
|
|
- net.minecraft.server.Chunk chunk = this.getChunkIfLoaded(blockposition);
|
|
|
|
+ net.minecraft.server.Chunk chunk = tileentity.getCurrentChunk();
|
|
|
|
boolean shouldTick = chunk != null;
|
|
|
|
if(this.paperConfig.skipEntityTickingInChunksScheduledForUnload)
|
|
|
|
shouldTick = shouldTick && !chunk.isUnloading() && chunk.scheduledForUnload == null;
|
2018-08-04 01:20:57 +00:00
|
|
|
@@ -1373,8 +1381,11 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
2018-07-04 07:56:57 +00:00
|
|
|
tilesThisCycle--;
|
|
|
|
this.tileEntityListTick.remove(tileTickPosition--);
|
|
|
|
//this.tileEntityList.remove(tileentity); // Paper - remove unused list
|
|
|
|
- if (this.isLoaded(tileentity.getPosition())) {
|
2018-07-04 21:29:10 +00:00
|
|
|
- this.getChunkAtWorldCoords(tileentity.getPosition()).d(tileentity.getPosition());
|
2018-07-04 07:56:57 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ net.minecraft.server.Chunk chunk = tileentity.getCurrentChunk();
|
|
|
|
+ if (chunk != null) {
|
2018-07-04 21:29:10 +00:00
|
|
|
+ chunk.removeTileEntity(tileentity.getPosition());
|
2018-07-04 07:56:57 +00:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
2018-07-04 21:29:10 +00:00
|
|
|
}
|
2018-07-04 07:56:57 +00:00
|
|
|
--
|
2018-07-12 20:42:56 +00:00
|
|
|
2.18.0
|
2018-07-04 07:56:57 +00:00
|
|
|
|