aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0279-Avoid-Chunk-Lookups-for-Entity-TileEntity-Current-Ch.patch
blob: f0ca1f81c32f49660924c0380965f6d245f6142b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
From 2419083c0b4fd0a0f99df2c3c0fbb40cf3530960 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 24d169eee..bf563df53 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -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;
 
             j = entity.chunkZ;
-            if (entity.inChunk && this.isChunkLoaded(k, j, true)) {
-                this.getChunkAt(k, j).b(entity);
-            }
+            Chunk chunk = entity.getCurrentChunk(); // Paper
+            if (chunk != null) chunk.removeEntity(entity); // Paper
         //} // Paper - merge
 
         //for (Entity e : this.g) { // Paper - merge
@@ -1261,9 +1259,10 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
                 j = entity.chunkX;
                 int l = entity.chunkZ;
 
-                if (entity.inChunk && this.isChunkLoaded(j, l, true)) {
-                    this.getChunkAt(j, l).b(entity);
-                }
+                // Paper start
+                Chunk chunk = entity.getCurrentChunk();
+                if (chunk != null) chunk.removeEntity(entity);
+                // Paper end
 
                 guardEntityList = false; // Spigot
                 this.entityList.remove(this.tickPosition--); // CraftBukkit - Use field for loop variable
@@ -1308,7 +1307,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
                 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.scheduledForUnload == null;
@@ -1344,8 +1343,11 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
                 tilesThisCycle--;
                 this.tileEntityListTick.remove(tileTickPosition--);
                 //this.tileEntityList.remove(tileentity); // Paper - remove unused list
-                if (this.isLoaded(tileentity.getPosition())) {
-                    this.getChunkAtWorldCoords(tileentity.getPosition()).d(tileentity.getPosition());
+                // Paper start
+                net.minecraft.server.Chunk chunk = tileentity.getCurrentChunk();
+                if (chunk != null) {
+                    chunk.removeTileEntity(tileentity.getPosition());
+                    // Paper end
                 }
             }
         }
-- 
2.21.0