2018-08-04 02:59:35 +02:00
|
|
|
From 996ef85fa987a376159ace734b15c5e476a91470 Mon Sep 17 00:00:00 2001
|
2018-07-04 09:56:57 +02: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 06:06:20 +02:00
|
|
|
index d24d45fdd3..4757081090 100644
|
2018-07-04 09:56:57 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2018-07-15 08:44:37 +02:00
|
|
|
@@ -702,6 +702,7 @@ public class Chunk {
|
2018-07-04 09:56:57 +02:00
|
|
|
// Spigot end
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public void removeEntity(Entity entity) { b(entity); } // Paper - OBFHELPER
|
|
|
|
public void b(Entity entity) {
|
|
|
|
this.a(entity, entity.ac);
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2018-08-04 02:59:35 +02:00
|
|
|
index e361883099..5de8da65c0 100644
|
2018-07-04 09:56:57 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2018-08-04 02:59:35 +02:00
|
|
|
@@ -1513,12 +1513,15 @@ public abstract class World implements IBlockAccess {
|
2018-07-04 09:56:57 +02:00
|
|
|
int j;
|
|
|
|
// Paper start - Set based removal lists
|
|
|
|
for (Entity e : this.f) {
|
|
|
|
+ /*
|
|
|
|
j = e.getChunkZ();
|
|
|
|
int k = e.getChunkX();
|
|
|
|
|
|
|
|
if (e.isAddedToChunk() && this.isChunkLoaded(k, j, true)) {
|
|
|
|
this.getChunkAt(k, j).b(e);
|
|
|
|
- }
|
|
|
|
+ }*/
|
2018-07-12 22:42:56 +02:00
|
|
|
+ Chunk chunk = e.isAddedToChunk() ? e.getCurrentChunk() : null;
|
2018-07-04 09:56:57 +02:00
|
|
|
+ if (chunk != null) chunk.removeEntity(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Entity e : this.f) {
|
2018-08-04 02:59:35 +02:00
|
|
|
@@ -1579,12 +1582,17 @@ public abstract class World implements IBlockAccess {
|
2018-07-04 09:56:57 +02:00
|
|
|
this.methodProfiler.b();
|
|
|
|
this.methodProfiler.a("remove");
|
|
|
|
if (entity.dead) {
|
|
|
|
+ // Paper start
|
|
|
|
+ /*
|
|
|
|
j = entity.ab;
|
|
|
|
int l = entity.ad;
|
|
|
|
|
|
|
|
- if (entity.aa && this.isChunkLoaded(j, l, true)) {
|
|
|
|
+ /*if (entity.aa && this.isChunkLoaded(j, l, true)) {
|
|
|
|
this.getChunkAt(j, l).b(entity);
|
|
|
|
- }
|
|
|
|
+ }*/
|
2018-07-12 22:42:56 +02:00
|
|
|
+ Chunk chunk = entity.isAddedToChunk() ? entity.getCurrentChunk() : null;
|
2018-07-04 09:56:57 +02: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 02:59:35 +02:00
|
|
|
@@ -1629,7 +1637,7 @@ public abstract class World implements IBlockAccess {
|
2018-07-04 09:56:57 +02: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 02:59:35 +02:00
|
|
|
@@ -1665,8 +1673,11 @@ public abstract class World implements IBlockAccess {
|
2018-07-04 09:56:57 +02:00
|
|
|
tilesThisCycle--;
|
|
|
|
this.tileEntityListTick.remove(tileTickPosition--);
|
|
|
|
//this.tileEntityList.remove(tileentity); // Paper - remove unused list
|
|
|
|
- if (this.isLoaded(tileentity.getPosition())) {
|
2018-07-04 23:29:10 +02:00
|
|
|
- this.getChunkAtWorldCoords(tileentity.getPosition()).d(tileentity.getPosition());
|
2018-07-04 09:56:57 +02:00
|
|
|
+ // Paper start
|
|
|
|
+ net.minecraft.server.Chunk chunk = tileentity.getCurrentChunk();
|
|
|
|
+ if (chunk != null) {
|
2018-07-04 23:29:10 +02:00
|
|
|
+ chunk.removeTileEntity(tileentity.getPosition());
|
2018-07-04 09:56:57 +02:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
2018-07-04 23:29:10 +02:00
|
|
|
}
|
2018-07-04 09:56:57 +02:00
|
|
|
--
|
2018-07-12 22:42:56 +02:00
|
|
|
2.18.0
|
2018-07-04 09:56:57 +02:00
|
|
|
|