From 7a1a43279a5ab8c2f5f6b9bacca5210d15236fd6 Mon Sep 17 00:00:00 2001 From: themode Date: Fri, 20 Nov 2020 17:13:00 +0100 Subject: [PATCH] Fixed empty chunk when connecting during its generation --- .../java/net/minestom/server/instance/Chunk.java | 9 ++------- .../server/instance/batch/ChunkBatch.java | 15 ++++++++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/Chunk.java b/src/main/java/net/minestom/server/instance/Chunk.java index 91b046004..ce068d7e5 100644 --- a/src/main/java/net/minestom/server/instance/Chunk.java +++ b/src/main/java/net/minestom/server/instance/Chunk.java @@ -17,6 +17,7 @@ import net.minestom.server.network.packet.server.play.ChunkDataPacket; import net.minestom.server.network.packet.server.play.UpdateLightPacket; import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.utils.MathUtils; +import net.minestom.server.utils.PacketUtils; import net.minestom.server.utils.Position; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.chunk.ChunkCallback; @@ -512,13 +513,7 @@ public abstract class Chunk implements Viewable, DataContainer { * Sends a full {@link ChunkDataPacket} to all chunk viewers. */ public synchronized void sendChunkUpdate() { - final Set chunkViewers = getViewers(); - if (!chunkViewers.isEmpty()) { - chunkViewers.forEach(player -> { - final PlayerConnection playerConnection = player.getPlayerConnection(); - playerConnection.sendPacket(getFreshFullDataPacket()); - }); - } + PacketUtils.sendGroupedPacket(getViewers(), getFreshFullDataPacket()); } /** diff --git a/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java b/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java index 1e7c61567..aed940473 100644 --- a/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java +++ b/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java @@ -127,12 +127,17 @@ public class ChunkBatch implements InstanceBatch { chunkPopulator.populateChunk(this, chunk); } } - - // Safe callback - instance.scheduleNextTick(inst -> { - OptionalCallback.execute(callback, chunk); - }); } + + // Refresh chunk for viewers + this.chunk.sendChunkUpdate(); + + this.instance.refreshLastBlockChangeTime(); + + // Safe callback + instance.scheduleNextTick(inst -> { + OptionalCallback.execute(callback, chunk); + }); }); }