Paper/Spigot-Server-Patches/0287-Avoid-Chunk-Lookups-for-Entity-TileEntity-Current-Ch.patch
Aikar f835a91d15
Updated Upstream (Bukkit/CraftBukkit), deprecate SentientNPC API
Upstream has added the equivalent of our SentientNPC API, with exception to the EnderDragon.

We've added Mob to the EnderDragon, and our SentientNPC API should behave the same.

Vex#getOwner has been deprecated and a replacement Vex#getSummoner has been added using Mob.

However, since 1.13 is not production ready, SentientNPC API is subject for removal in 1.13.1 since
1.13 API is not compatible with 1.12.

Please move to the Mob interface ASAP.

This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
c5ab54d8 Expand GameRule API
ab9a606c Improve entity hierarchy by adding Mob interface.

CraftBukkit Changes:
29e75648 Expand GameRule API
50e6858b Improve entity hierarchy by adding Mob interface.
0e1d79b4 Correct error in previous patch
2018-08-10 22:20:59 -04:00

90 lines
4.1 KiB
Diff

From 679d49837ab776c02a12d6e1a93206606520080b 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/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index d2e87693fa..1997cbdc65 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -721,6 +721,7 @@ public class Chunk implements IChunkAccess {
((HeightMap) this.heightMap.get(heightmap_type)).a(along);
}
+ public void removeEntity(Entity entity) { b(entity); } // Paper - OBFHELPER
public void b(Entity entity) {
this.a(entity, entity.af);
}
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 852977cab3..fbca973225 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -1221,12 +1221,15 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
int j;
// Paper start - Set based removal lists
for (Entity e : this.g) {
+ /*
j = e.getChunkZ();
int k = e.getChunkX();
if (e.inChunk && this.isChunkLoaded(k, j, true)) {
this.getChunkAt(k, j).b(e);
- }
+ }*/
+ Chunk chunk = e.inChunk ? e.getCurrentChunk() : null;
+ if (chunk != null) chunk.removeEntity(e);
}
for (Entity e : this.g) {
@@ -1287,12 +1290,17 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
this.methodProfiler.e();
this.methodProfiler.a("remove");
if (entity.dead) {
+ // Paper start
+ /*
j = entity.ae;
int l = entity.ag;
if (entity.inChunk && this.isChunkLoaded(j, l, true)) {
this.getChunkAt(j, l).b(entity);
- }
+ }*/
+ Chunk chunk = entity.inChunk ? entity.getCurrentChunk() : null;
+ if (chunk != null) chunk.removeEntity(entity);
+ // Paper end
guardEntityList = false; // Spigot
this.entityList.remove(this.tickPosition--); // CraftBukkit - Use field for loop variable
@@ -1337,7 +1345,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
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;
@@ -1373,8 +1381,11 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
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.18.0