2019-04-06 03:08:45 +00:00
|
|
|
From 857c905119708c593c6cc1b805b45ab2a6b88bf1 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/World.java b/src/main/java/net/minecraft/server/World.java
|
2019-04-06 03:08:45 +00:00
|
|
|
index d87b08a49e..c7712d2e71 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
|
2019-04-06 03:08:45 +00:00
|
|
|
@@ -1110,9 +1110,8 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
|
|
|
int i = entity.chunkX;
|
|
|
|
int j = entity.chunkZ;
|
|
|
|
|
|
|
|
- if (entity.inChunk && this.isChunkLoaded(i, j, true)) {
|
|
|
|
- this.getChunkAt(i, j).b(entity);
|
|
|
|
- }
|
|
|
|
+ Chunk chunk = entity.getCurrentChunk(); // Paper
|
|
|
|
+ if (chunk != null) chunk.removeEntity(entity); // Paper
|
|
|
|
|
|
|
|
// CraftBukkit start - Decrement loop variable field if we've already ticked this entity
|
|
|
|
int index = this.entityList.indexOf(entity);
|
|
|
|
@@ -1196,9 +1195,8 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
|
|
|
int k = entity.chunkX;
|
2018-07-04 07:56:57 +00:00
|
|
|
|
2019-04-06 03:08:45 +00:00
|
|
|
j = entity.chunkZ;
|
|
|
|
- if (entity.inChunk && this.isChunkLoaded(k, j, true)) {
|
|
|
|
- this.getChunkAt(k, j).b(entity);
|
2018-07-04 07:56:57 +00:00
|
|
|
- }
|
2019-04-06 03:08:45 +00:00
|
|
|
+ Chunk chunk = entity.getCurrentChunk(); // Paper
|
|
|
|
+ if (chunk != null) chunk.removeEntity(entity); // Paper
|
|
|
|
//} // Paper - merge
|
2018-07-04 07:56:57 +00:00
|
|
|
|
2019-04-06 03:08:45 +00:00
|
|
|
//for (Entity e : this.g) { // Paper - merge
|
|
|
|
@@ -1262,9 +1260,10 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
2018-12-17 05:18:06 +00:00
|
|
|
j = entity.chunkX;
|
|
|
|
int l = entity.chunkZ;
|
2018-07-04 07:56:57 +00:00
|
|
|
|
2019-04-06 03:08:45 +00:00
|
|
|
- if (entity.inChunk && this.isChunkLoaded(j, l, true)) {
|
|
|
|
- this.getChunkAt(j, l).b(entity);
|
2018-07-04 07:56:57 +00:00
|
|
|
- }
|
2019-04-06 03:08:45 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ Chunk chunk = entity.getCurrentChunk();
|
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
|
2019-04-06 03:08:45 +00:00
|
|
|
@@ -1309,7 +1308,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
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)
|
2018-08-26 18:11:49 +00:00
|
|
|
shouldTick = shouldTick && chunk.scheduledForUnload == null;
|
2019-04-06 03:08:45 +00:00
|
|
|
@@ -1345,8 +1344,11 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
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
|
|
|
--
|
2019-03-20 01:46:00 +00:00
|
|
|
2.21.0
|
2018-07-04 07:56:57 +00:00
|
|
|
|