fix: send LEVEL_CHUNKS_LOAD_START state on all instance changes, not just first join

This commit is contained in:
mworzala 2023-12-19 08:18:01 +02:00 committed by Matt Worzala
parent 0d21e487d2
commit 1813cdb1a8
2 changed files with 9 additions and 3 deletions

View File

@ -28,6 +28,7 @@ import net.minestom.server.item.metadata.BundleMeta;
import net.minestom.server.monitoring.BenchmarkManager; import net.minestom.server.monitoring.BenchmarkManager;
import net.minestom.server.monitoring.TickMonitor; import net.minestom.server.monitoring.TickMonitor;
import net.minestom.server.utils.MathUtils; import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.world.DimensionType; import net.minestom.server.world.DimensionType;
@ -151,6 +152,11 @@ public class PlayerInit {
instanceContainer.setGenerator(unit -> unit.modifier().fillHeight(0, 40, Block.STONE)); instanceContainer.setGenerator(unit -> unit.modifier().fillHeight(0, 40, Block.STONE));
instanceContainer.setChunkSupplier(LightingChunk::new); instanceContainer.setChunkSupplier(LightingChunk::new);
var i2 = new InstanceContainer(UUID.randomUUID(), DimensionType.OVERWORLD, null, NamespaceID.from("minestom:demo"));
instanceManager.registerInstance(i2);
i2.setGenerator(unit -> unit.modifier().fillHeight(0, 40, Block.GRASS_BLOCK));
i2.setChunkSupplier(LightingChunk::new);
// System.out.println("start"); // System.out.println("start");
// var chunks = new ArrayList<CompletableFuture<Chunk>>(); // var chunks = new ArrayList<CompletableFuture<Chunk>>();
// ChunkUtils.forChunksInRange(0, 0, 32, (x, z) -> chunks.add(instanceContainer.loadChunk(x, z))); // ChunkUtils.forChunksInRange(0, 0, 32, (x, z) -> chunks.add(instanceContainer.loadChunk(x, z)));

View File

@ -349,9 +349,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
refreshHealth(); // Heal and send health packet refreshHealth(); // Heal and send health packet
refreshAbilities(); // Send abilities packet refreshAbilities(); // Send abilities packet
// Start chunk load
sendPacket(new ChangeGameStatePacket(ChangeGameStatePacket.Reason.LEVEL_CHUNKS_LOAD_START, 0));
return setInstance(spawnInstance); return setInstance(spawnInstance);
} }
@ -756,6 +753,9 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
if (dimensionChange || firstSpawn) { if (dimensionChange || firstSpawn) {
this.inventory.update(); this.inventory.update();
sendPacket(new HeldItemChangePacket(heldSlot)); sendPacket(new HeldItemChangePacket(heldSlot));
// Tell the client to leave the loading terrain screen
sendPacket(new ChangeGameStatePacket(ChangeGameStatePacket.Reason.LEVEL_CHUNKS_LOAD_START, 0));
} }
EventDispatcher.call(new PlayerSpawnEvent(this, instance, firstSpawn)); EventDispatcher.call(new PlayerSpawnEvent(this, instance, firstSpawn));