PaperMC/patches/server/0447-Optimize-ServerLevels-chunk-level-checking-methods.patch
Jake Potrebic 55d5c1650f
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#6149)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
17c35d6e SPIGOT-6637: Revert "#636: Add FurnaceStartSmeltEvent"
4b27230b SPIGOT-6623: Missing API reasons for entity freezing
e1528c85 #636: Add FurnaceStartSmeltEvent

CraftBukkit Changes:
a6292cc3 SPIGOT-6637: Revert "#874: Add FurnaceStartSmeltEvent"
f4066854 SPIGOT-6579: DragonFireBall movement with setDirection jumps around a lot
9add952b SPIGOT-6623: Missing API reasons for entity freezing
2ea359f1 #874: Add FurnaceStartSmeltEvent
be8d625e SPIGOT-5560, SPIGOT-6574, SPIGOT-6632: Remove no longer needed tile entity fix

Spigot Changes:
eac3cd96 Rebuild patches
2021-07-11 09:01:29 +02:00

64 lines
3.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Thu, 16 Apr 2020 16:13:59 -0700
Subject: [PATCH] Optimize ServerLevels chunk level checking methods
These can be hot functions (i.e entity ticking and block ticking),
so inline where possible, and avoid the abstraction of the
Either class.
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index b31271a50740a77bc97ab47fdfe23f11a2a76618..79338bd6349b1e454f190e4daab030859d5fdf47 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -2034,15 +2034,18 @@ public class ServerLevel extends Level implements WorldGenLevel {
public boolean isPositionTickingWithEntitiesLoaded(BlockPos blockposition) {
long i = ChunkPos.asLong(blockposition);
- return this.chunkSource.isPositionTicking(i) && this.areEntitiesLoaded(i);
+ // Paper start - optimize is ticking ready type functions
+ ChunkHolder chunkHolder = this.chunkSource.chunkMap.getVisibleChunkIfPresent(i);
+ return chunkHolder != null && chunkHolder.isTickingReady() && this.areEntitiesLoaded(i);
+ // Paper end
}
public boolean isPositionEntityTicking(BlockPos blockposition) {
- return this.entityManager.isPositionTicking(blockposition);
+ return this.entityManager.isPositionTicking(ChunkPos.asLong(blockposition)); // Paper
}
public boolean isPositionEntityTicking(ChunkPos chunkcoordintpair) {
- return this.entityManager.isPositionTicking(chunkcoordintpair);
+ return this.entityManager.isPositionTicking(chunkcoordintpair.toLong()); // Paper
}
private final class EntityCallbacks implements LevelCallback<Entity> {
diff --git a/src/main/java/net/minecraft/world/level/ChunkPos.java b/src/main/java/net/minecraft/world/level/ChunkPos.java
index 439f82a48e6f6ce7b4773505ced32324cacb302d..2a99aa989ac5c19d99bb3cbc0934425e46573cd7 100644
--- a/src/main/java/net/minecraft/world/level/ChunkPos.java
+++ b/src/main/java/net/minecraft/world/level/ChunkPos.java
@@ -48,7 +48,7 @@ public class ChunkPos {
}
public static long asLong(BlockPos blockPos) {
- return asLong(SectionPos.blockToSectionCoord(blockPos.getX()), SectionPos.blockToSectionCoord(blockPos.getZ()));
+ return (((long)blockPos.getX() >> 4) & 4294967295L) | ((((long)blockPos.getZ() >> 4) & 4294967295L) << 32); // Paper - inline
}
public static int getX(long pos) {
diff --git a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
index a56cfcf5ac735147f3f2bd029a2b1a4e889d5b4f..5a0a1b01e89b122811b0b567e1ee27081953e638 100644
--- a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
+++ b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
@@ -327,6 +327,11 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
public LevelEntityGetter<T> getEntityGetter() {
return this.entityGetter;
}
+ // Paper start
+ public final boolean isPositionTicking(long position) {
+ return this.chunkVisibility.get(position).isTicking();
+ }
+ // Paper end
public boolean isPositionTicking(BlockPos blockPos) {
return this.chunkVisibility.get(ChunkPos.asLong(blockPos)).isTicking();