Fixed empty chunk when connecting during its generation

This commit is contained in:
themode 2020-11-20 17:13:00 +01:00
parent da4216a51f
commit 7a1a43279a
2 changed files with 12 additions and 12 deletions

View File

@ -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<Player> chunkViewers = getViewers();
if (!chunkViewers.isEmpty()) {
chunkViewers.forEach(player -> {
final PlayerConnection playerConnection = player.getPlayerConnection();
playerConnection.sendPacket(getFreshFullDataPacket());
});
}
PacketUtils.sendGroupedPacket(getViewers(), getFreshFullDataPacket());
}
/**

View File

@ -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);
});
});
}