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
|
2021-11-24 11:38:00 +00:00
|
|
|
index cdacb26699a54659d1e43ec0f73640556a743700..32bfde94533fcba205e0de3bc55baa8359f8fae6 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
|
2021-11-24 11:38:00 +00:00
|
|
|
@@ -2136,15 +2136,18 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
|
|
}
|
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);
|
|
|
|
+ return chunkHolder != null && 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) {
|
|
|
|
- return this.entityManager.isPositionTicking(pos);
|
|
|
|
+ return this.entityManager.isPositionTicking(ChunkPos.asLong(pos)); // Paper
|
2021-06-18 05:51:04 +00:00
|
|
|
}
|
|
|
|
|
2021-11-24 11:38:00 +00:00
|
|
|
public boolean isPositionEntityTicking(ChunkPos pos) {
|
|
|
|
- return this.entityManager.isPositionTicking(pos);
|
|
|
|
+ return this.entityManager.isPositionTicking(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
|
2021-11-24 11:38:00 +00:00
|
|
|
index 18c8988dcb5b475c8738a313f1775b73c9d961f4..32037377737cd45fa55ecbe19c201f424a127714 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-24 11:38:00 +00:00
|
|
|
@@ -49,7 +49,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
|
2021-11-24 11:38:00 +00:00
|
|
|
index e19f5b2c8f485d596a64d5d96e75fa1f4a8255b5..ccafd28e3dc9a03f310eb5bdde85fcb277ef5116 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
|
|
|
|
+ public final boolean isPositionTicking(long position) {
|
|
|
|
+ return this.chunkVisibility.get(position).isTicking();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
2021-11-24 11:38:00 +00:00
|
|
|
public boolean isPositionTicking(BlockPos pos) {
|
|
|
|
return ((Visibility) this.chunkVisibility.get(ChunkPos.asLong(pos))).isTicking();
|