Skip to content

Commit

Permalink
Send forget packet to avoid invisible chunk sections (#3005)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirYwell authored Nov 23, 2024
1 parent 2158981 commit c4267b3
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.minecraft.core.Holder;
import net.minecraft.core.IdMap;
import net.minecraft.core.Registry;
import net.minecraft.network.protocol.game.ClientboundForgetLevelChunkPacket;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder;
Expand Down Expand Up @@ -335,7 +336,6 @@ public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int
if (chunkHolder == null) {
return;
}
ChunkPos coordIntPair = new ChunkPos(chunkX, chunkZ);
LevelChunk levelChunk;
if (PaperLib.isPaper()) {
// getChunkAtIfLoadedImmediately is paper only
Expand All @@ -353,6 +353,10 @@ public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int
}
MinecraftServer.getServer().execute(() -> {
try {
ChunkPos pos = levelChunk.getPos();
// NOTE: the ClientboundForgetLevelChunkPacket packet is required on 1.21.3
// as the client won't update empty -> non-empty sections properly otherwise
ClientboundForgetLevelChunkPacket forget = new ClientboundForgetLevelChunkPacket(pos);
ClientboundLevelChunkWithLightPacket packet;
if (PaperLib.isPaper()) {
packet = new ClientboundLevelChunkWithLightPacket(
Expand All @@ -371,7 +375,10 @@ public static void sendChunk(IntPair pair, ServerLevel nmsWorld, int chunkX, int
null
);
}
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet));
nearbyPlayers(nmsWorld, pos).forEach(p -> {
p.connection.send(forget);
p.connection.send(packet);
});
} finally {
NMSAdapter.endChunkPacketSend(nmsWorld.getWorld().getName(), pair, lockHolder);
}
Expand Down

0 comments on commit c4267b3

Please sign in to comment.