2021-06-18 07:51:04 +02: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-07-21 19:12:24 +02:00
|
|
|
index bfc855adc411269b63b44157266d6ef7945aa7e0..6fc4b479dcb40b7f6f018731956bc003e95ea05b 100644
|
2021-06-18 07:51:04 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2021-07-11 09:01:29 +02:00
|
|
|
@@ -2034,15 +2034,18 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-06-18 07:51:04 +02:00
|
|
|
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
|
2021-07-21 19:12:24 +02:00
|
|
|
index 75e9350d2dcb2669107a938a8cff2e537488f88f..c1e17b0d7c0b9a55e9061fa4d0bb1805d8f86ba2 100644
|
2021-06-18 07:51:04 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
|
2021-07-21 19:12:24 +02:00
|
|
|
@@ -333,6 +333,11 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
|
2021-06-18 07:51:04 +02:00
|
|
|
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();
|