mirror of https://github.com/Minestom/Minestom.git
Add UnloadChunkPacket
This commit is contained in:
parent
adb426bcf1
commit
77d1888cbc
|
@ -10,6 +10,7 @@ import net.minestom.server.network.packet.client.play.ClientPlayerPositionPacket
|
|||
import net.minestom.server.network.packet.client.play.ClientSettingsPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
|
||||
import net.minestom.server.network.packet.server.play.UnloadChunkPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import org.jctools.queues.MpscUnboundedXaddArrayQueue;
|
||||
|
@ -35,6 +36,7 @@ final class ClientContext {
|
|||
registerClientPacket(ClientPlayerPositionPacket.class, packet -> handleMovement(packet.position()));
|
||||
|
||||
registerServerPacket(ChunkDataPacket.class, this::handleChunkData);
|
||||
registerServerPacket(UnloadChunkPacket.class, this::handleUnloadChunk);
|
||||
}
|
||||
|
||||
synchronized void process() {
|
||||
|
@ -80,6 +82,11 @@ final class ClientContext {
|
|||
this.visibleChunks.put(index, new Chunk(chunkDataPacket));
|
||||
}
|
||||
|
||||
private void handleUnloadChunk(UnloadChunkPacket unloadChunkPacket) {
|
||||
final long index = ChunkUtils.getChunkIndex(unloadChunkPacket.chunkX(), unloadChunkPacket.chunkZ());
|
||||
this.visibleChunks.remove(index);
|
||||
}
|
||||
|
||||
private <T> void registerClientPacket(Class<T> packetClass, Consumer<T> consumer) {
|
||||
this.clientHandler.put(packetClass, (Consumer<ClientPacket>) consumer);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue