diff --git a/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch b/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch index 3bb77f2c9..ad8a8f8e0 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch @@ -57,6 +57,15 @@ public abstract class Level implements LevelAccessor, AutoCloseable { public static final Codec> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION); +@@ -94,7 +117,7 @@ + public static final int TICKS_PER_DAY = 24000; + public static final int MAX_ENTITY_SPAWN_Y = 20000000; + public static final int MIN_ENTITY_SPAWN_Y = -20000000; +- protected final List blockEntityTickers = Lists.newArrayList(); ++ public final List blockEntityTickers = Lists.newArrayList(); // Paper - public + protected final NeighborUpdater neighborUpdater; + private final List pendingBlockEntityTickers = Lists.newArrayList(); + private boolean tickingBlockEntities; @@ -121,23 +144,74 @@ private final DamageSources damageSources; private long subTickCount; @@ -306,7 +315,7 @@ if (this.isOutsideBuildHeight(pos)) { return false; } else if (!this.isClientSide && this.isDebug()) { -@@ -214,45 +400,124 @@ +@@ -214,44 +400,123 @@ } else { LevelChunk chunk = this.getChunkAt(pos); Block block = state.getBlock(); @@ -390,10 +399,10 @@ + // CraftBukkit end + return true; - } - } - } - ++ } ++ } ++ } ++ + // CraftBukkit start - Split off from above in order to directly send client and physic updates + public void notifyAndUpdatePhysics(BlockPos blockposition, LevelChunk chunk, BlockState oldBlock, BlockState newBlock, BlockState actualBlock, int i, int j) { + BlockState iblockdata = newBlock; @@ -406,7 +415,7 @@ + + if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (this.isClientSide || chunk == null || (chunk.getFullStatus() != null && chunk.getFullStatus().isOrAfter(FullChunkStatus.BLOCK_TICKING)))) { // allow chunk to be null here as chunk.isReady() is false when we send our notification during block placement + this.sendBlockUpdated(blockposition, iblockdata1, iblockdata, i); -+ } + } + + if ((i & 1) != 0) { + this.blockUpdated(blockposition, iblockdata1.getBlock()); @@ -439,13 +448,12 @@ + this.onBlockStateChange(blockposition, iblockdata1, iblockdata2); + } + // CraftBukkit end -+ } -+ } + } + } + // CraftBukkit end -+ + public void onBlockStateChange(BlockPos pos, BlockState oldBlock, BlockState newBlock) {} - @Override @@ -340,10 +605,18 @@ @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 1827df86b..cf38f7505 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -169,6 +169,48 @@ public class CraftWorld extends CraftRegionAccessor implements World { private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftWorld.DATA_TYPE_REGISTRY); private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers + // Paper start - Provide fast information methods + @Override + public int getEntityCount() { + int ret = 0; + for (net.minecraft.world.entity.Entity entity : world.getEntities().getAll()) { + if (entity.isChunkLoaded()) { + ++ret; + } + } + return ret; + } + + @Override + public int getTileEntityCount() { + // We don't use the full world tile entity list, so we must iterate chunks + int size = 0; + for (ChunkHolder playerchunk : ca.spottedleaf.moonrise.common.util.ChunkSystem.getVisibleChunkHolders(this.world)) { + net.minecraft.world.level.chunk.LevelChunk chunk = playerchunk.getTickingChunk(); + if (chunk == null) { + continue; + } + size += chunk.blockEntities.size(); + } + return size; + } + + @Override + public int getTickableTileEntityCount() { + return world.blockEntityTickers.size(); + } + + @Override + public int getChunkCount() { + return this.world.getChunkSource().getFullChunksCount(); + } + + @Override + public int getPlayerCount() { + return world.players().size(); + } + // Paper end + private static final Random rand = new Random(); public CraftWorld(ServerLevel world, ChunkGenerator gen, BiomeProvider biomeProvider, Environment env) {