9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
This commit is contained in:
hayanesuru
2025-06-28 23:11:18 +09:00
parent b82c666c16
commit fd34d9f626
2 changed files with 22 additions and 22 deletions

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Async chunk sending
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
index 0bca3843e8568b37cda6ae312bdf4f423a0891a9..71561ac77e32d7f971c343ad83a268c076ce668a 100644
index 0bca3843e8568b37cda6ae312bdf4f423a0891a9..98054ab2be3fecc5f6a111a11cfe94f1a10419c1 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
@@ -440,7 +440,15 @@ public final class RegionizedPlayerChunkLoader {
@@ -13,7 +13,7 @@ index 0bca3843e8568b37cda6ae312bdf4f423a0891a9..71561ac77e32d7f971c343ad83a268c0
((ChunkSystemChunkHolder)((ChunkSystemServerLevel)this.world).moonrise$getChunkTaskScheduler().chunkHolderManager
.getChunkHolder(chunkX, chunkZ).vanillaChunkHolder).moonrise$removeReceivedChunk(this.player);
- this.player.connection.send(new ClientboundForgetLevelChunkPacket(new ChunkPos(chunkX, chunkZ)));
+ // Leaf start - Async chunk send
+ // Leaf start - Async chunk sending
+ if (org.dreeam.leaf.config.modules.async.AsyncChunkSend.enabled) {
+ org.dreeam.leaf.async.chunk.AsyncChunkSend.POOL.execute(
+ () -> this.player.connection.send(new ClientboundForgetLevelChunkPacket(new ChunkPos(chunkX, chunkZ)))
@@ -21,19 +21,19 @@ index 0bca3843e8568b37cda6ae312bdf4f423a0891a9..71561ac77e32d7f971c343ad83a268c0
+ } else {
+ this.player.connection.send(new ClientboundForgetLevelChunkPacket(new ChunkPos(chunkX, chunkZ)));
+ }
+ // Leaf end - Async chunk send
+ // Leaf end - Async chunk sending
// Paper start - PlayerChunkUnloadEvent
if (io.papermc.paper.event.packet.PlayerChunkUnloadEvent.getHandlerList().getRegisteredListeners().length > 0) {
new io.papermc.paper.event.packet.PlayerChunkUnloadEvent(player.getBukkitEntity().getWorld().getChunkAt(new ChunkPos(chunkX, chunkZ).longKey), player.getBukkitEntity()).callEvent();
diff --git a/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java b/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
index 9f6d7c5dc0e591488a8a3763d8a1f1b3671d5299..6123afd9c27f1f9a954b173413e61bfb276b0f0a 100644
index 9f6d7c5dc0e591488a8a3763d8a1f1b3671d5299..8af4c964ce67373f9b911ce13164f48c29a07d85 100644
--- a/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
+++ b/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
@@ -75,6 +75,45 @@ public class ClientboundLevelChunkPacketData {
@@ -75,6 +75,52 @@ public class ClientboundLevelChunkPacketData {
}
}
+ // Leaf start - Async chunk send
+ // Leaf start - Async chunk sending
+ public ClientboundLevelChunkPacketData(LevelChunk levelChunk, io.papermc.paper.antixray.ChunkPacketInfo<net.minecraft.world.level.block.state.BlockState> chunkPacketInfo, BlockEntity[] blockEntities, Map<Heightmap.Types, long[]> heightmaps) {
+ this.heightmaps = heightmaps;
+
@@ -77,7 +77,7 @@ index 9f6d7c5dc0e591488a8a3763d8a1f1b3671d5299..6123afd9c27f1f9a954b173413e61bfb
+ this.blockEntitiesData.add(ClientboundLevelChunkPacketData.BlockEntityInfo.create(blockEntity));
+ }
+ }
+ // Leaf end - Async chunk send
+ // Leaf end - Async chunk sending
+
public ClientboundLevelChunkPacketData(RegistryFriendlyByteBuf buffer, int x, int z) {
this.heightmaps = HEIGHTMAPS_STREAM_CODEC.decode(buffer);
@@ -91,14 +91,14 @@ index 9f6d7c5dc0e591488a8a3763d8a1f1b3671d5299..6123afd9c27f1f9a954b173413e61bfb
throw new IllegalStateException("Didn't fill chunk buffer: expected " + buffer.capacity() + " bytes, got " + buffer.writerIndex());
}
diff --git a/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java b/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
index 8578d1f78ddd1bb75f3230f04bfaa35af9f5f822..4f54c4c8e49c1e0352ab2c5c23277b4103504c55 100644
index 8578d1f78ddd1bb75f3230f04bfaa35af9f5f822..d8e938abf5123b092cec80feb6468e3d91ae823e 100644
--- a/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
+++ b/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
@@ -44,6 +44,17 @@ public class ClientboundLevelChunkWithLightPacket implements Packet<ClientGamePa
this.lightData = new ClientboundLightUpdatePacketData(pos, lightEngine, skyLight, blockLight);
chunk.getLevel().chunkPacketBlockController.modifyBlocks(this, chunkPacketInfo); // Paper - Anti-Xray - Modify blocks
}
+ // Leaf start - Async chunk send
+ // Leaf start - Async chunk sending
+ public ClientboundLevelChunkWithLightPacket(LevelChunk chunk, LevelLightEngine lightEngine, @Nullable BitSet skyLight, @Nullable BitSet blockLight, boolean modifyBlocks, net.minecraft.world.level.block.entity.BlockEntity[] blockEntities, java.util.Map<net.minecraft.world.level.levelgen.Heightmap.Types, long[]> heightmaps) {
+ ChunkPos pos = chunk.getPos();
+ this.x = pos.x;
@@ -108,12 +108,12 @@ index 8578d1f78ddd1bb75f3230f04bfaa35af9f5f822..4f54c4c8e49c1e0352ab2c5c23277b41
+ this.lightData = new ClientboundLightUpdatePacketData(pos, lightEngine, skyLight, blockLight);
+ chunk.getLevel().chunkPacketBlockController.modifyBlocks(this, chunkPacketInfo); // Paper - Anti-Xray - Modify blocks
+ }
+ // Leaf end - Async chunk send
+ // Leaf end - Async chunk sending
private ClientboundLevelChunkWithLightPacket(RegistryFriendlyByteBuf buffer) {
this.x = buffer.readInt();
diff --git a/net/minecraft/server/network/PlayerChunkSender.java b/net/minecraft/server/network/PlayerChunkSender.java
index 0376a10ee0544b13e8fd629a7b13f78811e57a30..638d622992b8bee993c48c170bba8ab9f0f534e6 100644
index 0376a10ee0544b13e8fd629a7b13f78811e57a30..aa6b900347635857b84460fa8435b81f794f0747 100644
--- a/net/minecraft/server/network/PlayerChunkSender.java
+++ b/net/minecraft/server/network/PlayerChunkSender.java
@@ -64,13 +64,29 @@ public class PlayerChunkSender {
@@ -121,7 +121,7 @@ index 0376a10ee0544b13e8fd629a7b13f78811e57a30..638d622992b8bee993c48c170bba8ab9
ServerGamePacketListenerImpl serverGamePacketListenerImpl = player.connection;
this.unacknowledgedBatches++;
- serverGamePacketListenerImpl.send(ClientboundChunkBatchStartPacket.INSTANCE);
+ // Leaf start - Async chunk send
+ // Leaf start - Async chunk sending
+ if (org.dreeam.leaf.config.modules.async.AsyncChunkSend.enabled) {
+ org.dreeam.leaf.async.chunk.AsyncChunkSend.POOL.execute(
+ () -> serverGamePacketListenerImpl.send(ClientboundChunkBatchStartPacket.INSTANCE)
@@ -129,14 +129,14 @@ index 0376a10ee0544b13e8fd629a7b13f78811e57a30..638d622992b8bee993c48c170bba8ab9
+ } else {
+ serverGamePacketListenerImpl.send(ClientboundChunkBatchStartPacket.INSTANCE);
+ }
+ // Leaf end - Async chunk send
+ // Leaf end - Async chunk sending
for (LevelChunk levelChunk : list) {
sendChunk(serverGamePacketListenerImpl, serverLevel, levelChunk);
}
- serverGamePacketListenerImpl.send(new ClientboundChunkBatchFinishedPacket(list.size()));
+ // Leaf start - Async chunk send
+ // Leaf start - Async chunk sending
+ if (org.dreeam.leaf.config.modules.async.AsyncChunkSend.enabled) {
+ org.dreeam.leaf.async.chunk.AsyncChunkSend.POOL.execute(
+ () -> serverGamePacketListenerImpl.send(new ClientboundChunkBatchFinishedPacket(list.size()))
@@ -144,7 +144,7 @@ index 0376a10ee0544b13e8fd629a7b13f78811e57a30..638d622992b8bee993c48c170bba8ab9
+ } else {
+ serverGamePacketListenerImpl.send(new ClientboundChunkBatchFinishedPacket(list.size()));
+ }
+ // Leaf end - Async chunk send
+ // Leaf end - Async chunk sending
this.batchQuota = this.batchQuota - list.size();
}
}
@@ -153,7 +153,7 @@ index 0376a10ee0544b13e8fd629a7b13f78811e57a30..638d622992b8bee993c48c170bba8ab9
public static void sendChunk(ServerGamePacketListenerImpl packetListener, ServerLevel level, LevelChunk chunk) {
final boolean shouldModify = level.chunkPacketBlockController.shouldModify(packetListener.player, chunk);
- packetListener.send(new ClientboundLevelChunkWithLightPacket(chunk, level.getLightEngine(), null, null, shouldModify));
+ // Leaf start - Async chunk send
+ // Leaf start - Async chunk sending
+ if (org.dreeam.leaf.config.modules.async.AsyncChunkSend.enabled) {
+ var blockEntities = chunk.blockEntities.values().toArray(new net.minecraft.world.level.block.entity.BlockEntity[0]);
+ java.util.Map<net.minecraft.world.level.levelgen.Heightmap.Types, long[]> heightmaps = new java.util.concurrent.ConcurrentHashMap<>();
@@ -169,12 +169,12 @@ index 0376a10ee0544b13e8fd629a7b13f78811e57a30..638d622992b8bee993c48c170bba8ab9
+ } else {
+ packetListener.send(new ClientboundLevelChunkWithLightPacket(chunk, level.getLightEngine(), null, null, shouldModify));
+ }
+ // Leaf end - Async chunk send
+ // Leaf end - Async chunk sending
// Paper end - Anti-Xray
// Paper start - PlayerChunkLoadEvent
if (io.papermc.paper.event.packet.PlayerChunkLoadEvent.getHandlerList().getRegisteredListeners().length > 0) {
diff --git a/net/minecraft/world/level/chunk/LevelChunkSection.java b/net/minecraft/world/level/chunk/LevelChunkSection.java
index 36c033b0ee63dfc273d721fb4b614733e8fdef19..1cc33a038060aaf5258ee4f1deb19b4a1be59a29 100644
index 36c033b0ee63dfc273d721fb4b614733e8fdef19..4d06df242ab73411bdefc4770e131b27a6ea668a 100644
--- a/net/minecraft/world/level/chunk/LevelChunkSection.java
+++ b/net/minecraft/world/level/chunk/LevelChunkSection.java
@@ -18,7 +18,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
@@ -182,7 +182,7 @@ index 36c033b0ee63dfc273d721fb4b614733e8fdef19..1cc33a038060aaf5258ee4f1deb19b4a
public static final int SECTION_SIZE = 4096;
public static final int BIOME_CONTAINER_BITS = 2;
- short nonEmptyBlockCount; // Paper - package private
+ volatile short nonEmptyBlockCount; // Paper - package private // Leaf - Async chunk send - volatile
+ volatile short nonEmptyBlockCount; // Paper - package private // Leaf - Async chunk sending - volatile
private short tickingBlockCount;
private short tickingFluidCount;
private boolean isRandomlyTickingBlocksStatus; // Leaf - Cache random tick block status

View File

@@ -1,11 +1,11 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <mc@jvavav.com>
Date: Fri, 2 May 2025 18:22:24 -0700
Subject: [PATCH] Async chunk send
Subject: [PATCH] Async chunk sending
diff --git a/src/main/java/io/papermc/paper/antixray/ChunkPacketBlockControllerAntiXray.java b/src/main/java/io/papermc/paper/antixray/ChunkPacketBlockControllerAntiXray.java
index ca24f4cd7a50f0156d84e263c60f841cca95c669..7e15038e8fceab1e97c2245c2e9111deed6455fb 100644
index ca24f4cd7a50f0156d84e263c60f841cca95c669..e98a7edc4001d020d238a44a96fda00f389234eb 100644
--- a/src/main/java/io/papermc/paper/antixray/ChunkPacketBlockControllerAntiXray.java
+++ b/src/main/java/io/papermc/paper/antixray/ChunkPacketBlockControllerAntiXray.java
@@ -185,7 +185,7 @@ public final class ChunkPacketBlockControllerAntiXray extends ChunkPacketBlockCo
@@ -13,7 +13,7 @@ index ca24f4cd7a50f0156d84e263c60f841cca95c669..7e15038e8fceab1e97c2245c2e9111de
}
- if (!Bukkit.isPrimaryThread()) {
+ if (!Bukkit.isPrimaryThread() && !(Thread.currentThread() instanceof org.dreeam.leaf.async.chunk.AsyncChunkSendThread)) { // Leaf - Async chunk send
+ if (!Bukkit.isPrimaryThread() && !(Thread.currentThread() instanceof org.dreeam.leaf.async.chunk.AsyncChunkSendThread)) { // Leaf - Async chunk sending
// Plugins?
MinecraftServer.getServer().scheduleOnMain(() -> modifyBlocks(chunkPacket, chunkPacketInfo));
return;