2021-06-18 05:51:04 +00:00
|
|
|
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
|
2022-06-03 04:26:56 +00:00
|
|
|
index 5009ad1a758e192eaf6ca59baab26d2ba58a6c66..894186d25863a437e49ef0c10b2f2dab34af7ed0 100644
|
2021-06-18 05:51:04 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2022-03-13 07:47:54 +00:00
|
|
|
@@ -2169,19 +2169,22 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-11-24 11:38:00 +00:00
|
|
|
}
|
2021-06-18 05:51:04 +00:00
|
|
|
|
2021-11-24 11:38:00 +00:00
|
|
|
private boolean isPositionTickingWithEntitiesLoaded(long chunkPos) {
|
|
|
|
- return this.areEntitiesLoaded(chunkPos) && this.chunkSource.isPositionTicking(chunkPos);
|
2021-06-18 05:51:04 +00:00
|
|
|
+ // Paper start - optimize is ticking ready type functions
|
2021-11-24 11:38:00 +00:00
|
|
|
+ ChunkHolder chunkHolder = this.chunkSource.chunkMap.getVisibleChunkIfPresent(chunkPos);
|
2021-12-09 06:00:45 +00:00
|
|
|
+ return chunkHolder != null && this.chunkSource.isPositionTicking(chunkPos) && chunkHolder.isTickingReady() && this.areEntitiesLoaded(chunkPos);
|
2021-06-18 05:51:04 +00:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
2021-11-24 11:38:00 +00:00
|
|
|
public boolean isPositionEntityTicking(BlockPos pos) {
|
2022-03-01 05:43:03 +00:00
|
|
|
- return this.entityManager.canPositionTick(pos) && this.chunkSource.chunkMap.getDistanceManager().inEntityTickingRange(ChunkPos.asLong(pos));
|
|
|
|
+ return this.entityManager.canPositionTick(ChunkPos.asLong(pos)) && this.chunkSource.chunkMap.getDistanceManager().inEntityTickingRange(ChunkPos.asLong(pos)); // Paper
|
2021-06-18 05:51:04 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 05:43:03 +00:00
|
|
|
public boolean isNaturalSpawningAllowed(BlockPos pos) {
|
|
|
|
- return this.entityManager.canPositionTick(pos);
|
|
|
|
+ return this.entityManager.canPositionTick(ChunkPos.asLong(pos)); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isNaturalSpawningAllowed(ChunkPos pos) {
|
|
|
|
- return this.entityManager.canPositionTick(pos);
|
|
|
|
+ return this.entityManager.canPositionTick(pos.toLong()); // Paper
|
2021-06-18 05:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2022-06-03 04:26:56 +00:00
|
|
|
index 4335132883e959f0c9649d5640b703a291d8a7aa..22d95316eac3731c66dd7dde960e4d71a6b565e2 100644
|
2021-06-18 05:51:04 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/ChunkPos.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/ChunkPos.java
|
2021-11-25 09:19:05 +00:00
|
|
|
@@ -50,7 +50,7 @@ public class ChunkPos {
|
2021-06-18 05:51:04 +00:00
|
|
|
}
|
|
|
|
|
2021-11-24 11:38:00 +00:00
|
|
|
public static long asLong(BlockPos pos) {
|
|
|
|
- return asLong(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ()));
|
|
|
|
+ return (((long)pos.getX() >> 4) & 4294967295L) | ((((long)pos.getZ() >> 4) & 4294967295L) << 32); // Paper - inline
|
2021-06-18 05:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2022-03-01 05:43:03 +00:00
|
|
|
index 1407f30d467fa78bc207a91da0e6395c0a9ba83d..2110cb437807f99994838b57653caefe2f01a9c5 100644
|
2021-06-18 05:51:04 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
|
2021-11-24 11:38:00 +00:00
|
|
|
@@ -383,6 +383,11 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
|
2021-06-18 05:51:04 +00:00
|
|
|
public LevelEntityGetter<T> getEntityGetter() {
|
|
|
|
return this.entityGetter;
|
|
|
|
}
|
|
|
|
+ // Paper start
|
2022-03-01 05:43:03 +00:00
|
|
|
+ public final boolean canPositionTick(long position) {
|
2021-06-18 05:51:04 +00:00
|
|
|
+ return this.chunkVisibility.get(position).isTicking();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
2022-03-01 05:43:03 +00:00
|
|
|
public boolean canPositionTick(BlockPos pos) {
|
2021-11-24 11:38:00 +00:00
|
|
|
return ((Visibility) this.chunkVisibility.get(ChunkPos.asLong(pos))).isTicking();
|