From 61636f44aa1d144c05bd95e3b51d7ca7e416db19 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 28 Dec 2021 23:25:33 -0600 Subject: [PATCH] Simulate Java chunk unloading by sending empty chunks Closes #2725 --- .../level/JavaForgetLevelChunkTranslator.java | 3 ++ .../org/geysermc/geyser/util/ChunkUtils.java | 36 ++++++++++--------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaForgetLevelChunkTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaForgetLevelChunkTranslator.java index 8204ceea5..a9b3f3780 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaForgetLevelChunkTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaForgetLevelChunkTranslator.java @@ -30,6 +30,7 @@ import com.nukkitx.math.vector.Vector3i; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; +import org.geysermc.geyser.util.ChunkUtils; import java.util.Iterator; @@ -60,5 +61,7 @@ public class JavaForgetLevelChunkTranslator extends PacketTranslator> 4; int chunkZ = position.getZ() >> 4; for (int x = -radius; x <= radius; x++) { for (int z = -radius; z <= radius; z++) { - LevelChunkPacket data = new LevelChunkPacket(); - data.setChunkX(chunkX + x); - data.setChunkZ(chunkZ + z); - data.setSubChunksLength(0); - data.setData(EMPTY_CHUNK_DATA); - data.setCachingEnabled(false); - session.sendUpstreamPacket(data); - - if (forceUpdate) { - Vector3i pos = Vector3i.from(chunkX + x << 4, 80, chunkZ + z << 4); - UpdateBlockPacket blockPacket = new UpdateBlockPacket(); - blockPacket.setBlockPosition(pos); - blockPacket.setDataLayer(0); - blockPacket.setRuntimeId(1); - session.sendUpstreamPacket(blockPacket); - } + sendEmptyChunk(session, chunkX + x, chunkZ + z, forceUpdate); } } }