9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00

Paper: Optimise CraftWorld#getLoadedChunks

This commit is contained in:
Dreeam
2025-06-06 02:37:29 +08:00
parent 1d30370d7a
commit ae1e3e8355
3 changed files with 47 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ protected net.minecraft.world.entity.Entity dimensions
protected net.minecraft.world.entity.ai.goal.RemoveBlockGoal blockToRemove
protected net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal getTargetConditions()Lnet/minecraft/world/entity/ai/targeting/TargetingConditions;
protected-f net.minecraft.world.level.block.state.BlockBehaviour$BlockStateBase$Cache largeCollisionShape
public net.minecraft.server.level.ServerChunkCache fullChunks
public net.minecraft.server.level.ServerEntity sendDirtyEntityData()V
public net.minecraft.util.Mth SIN
public net.minecraft.world.entity.Entity updateInWaterStateAndDoWaterCurrentPushing()V

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] optimize mob spawning
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index d61da0fbe7f6c181e4084ce60bfe7dab86f361ad..1ce1b21a77cd727b52bd937b65ce97517fed9c68 100644
index 39a31abe25d2bb56b28462cf25d2d09f7722526c..2f927b422c2c4f2f65d822befe3cbfd9e3bb3708 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -70,7 +70,9 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -17,7 +17,7 @@ index d61da0fbe7f6c181e4084ce60bfe7dab86f361ad..1ce1b21a77cd727b52bd937b65ce9751
+ private long delayTimeInhabited = 0L; // Leaf
+ private long delaySpawn = -1L; // Leaf
// Paper start
private final ca.spottedleaf.concurrentutil.map.ConcurrentLong2ReferenceChainedHashTable<net.minecraft.world.level.chunk.LevelChunk> fullChunks = new ca.spottedleaf.concurrentutil.map.ConcurrentLong2ReferenceChainedHashTable<>();
public final ca.spottedleaf.concurrentutil.map.ConcurrentLong2ReferenceChainedHashTable<net.minecraft.world.level.chunk.LevelChunk> fullChunks = new ca.spottedleaf.concurrentutil.map.ConcurrentLong2ReferenceChainedHashTable<>();
public int getFullChunksCount() {
@@ -656,13 +658,37 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
filteredSpawningCategories = List.of();

View File

@@ -0,0 +1,44 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Thu, 5 Jun 2025 08:16:25 -0700
Subject: [PATCH] Paper: Optimise CraftWorld#getLoadedChunks
Original license: GPLv3
Original project: https://github.com/PaperMC/Paper
https://github.com/PaperMC/Paper/commit/24cd24c8cc0df4bea0784e6919c9ba8f1852d46e
We can use the existing full chunk map so that we do not need
to iterate over all ChunkHolders. Additionally, do not use streams
to do the iteration either.
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index caa92e48d031cb54950e6613a82f407d7ed2455a..236be1bb296d0f080d2a8c739d2678655e81e174 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -420,8 +420,23 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override
public Chunk[] getLoadedChunks() {
- List<ChunkHolder> chunks = ca.spottedleaf.moonrise.common.PlatformHooks.get().getVisibleChunkHolders(this.world); // Paper
- return chunks.stream().map(ChunkHolder::getFullChunkNow).filter(Objects::nonNull).map(CraftChunk::new).toArray(Chunk[]::new);
+ // Paper start - Optimise CraftWorld#getLoadedChunks
+ net.minecraft.server.level.ServerChunkCache serverChunkCache = this.getHandle().chunkSource;
+ ca.spottedleaf.moonrise.common.list.ReferenceList<Chunk> chunks = new ca.spottedleaf.moonrise.common.list.ReferenceList<>(new Chunk[serverChunkCache.fullChunks.size()]);
+
+ for (java.util.PrimitiveIterator.OfLong iterator = serverChunkCache.fullChunks.keyIterator(); iterator.hasNext();) {
+ long chunk = iterator.nextLong();
+ chunks.add(new CraftChunk(this.world, ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkX(chunk), ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkZ(chunk)));
+ }
+
+ Chunk[] raw = chunks.getRawDataUnchecked();
+ int size = chunks.size();
+ if (raw.length == size) {
+ // always true when on main
+ return raw;
+ }
+ return java.util.Arrays.copyOf(raw, size);
+ // Paper end - Optimise CraftWorld#getLoadedChunks
}
@Override