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

(cherry picked from commit 1813cdb1a8)
This commit is contained in:
mworzala 2023-12-19 01:18:01 -05:00 committed by Matt Worzala
parent de9dc37aaa
commit ef2b5e03bc
2 changed files with 18 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.TickMonitor;
import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.world.DimensionType;
@ -147,6 +148,20 @@ public class PlayerInit {
instanceContainer.setGenerator(unit -> unit.modifier().fillHeight(0, 40, Block.STONE));
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");
// var chunks = new ArrayList<CompletableFuture<Chunk>>();
// ChunkUtils.forChunksInRange(0, 0, 32, (x, z) -> chunks.add(instanceContainer.loadChunk(x, z)));
// CompletableFuture.runAsync(() -> {
// CompletableFuture.allOf(chunks.toArray(CompletableFuture[]::new)).join();
// System.out.println("load end");
// });
inventory = new Inventory(InventoryType.CHEST_1_ROW, Component.text("Test inventory"));
inventory.setItemStack(3, ItemStack.of(Material.DIAMOND, 34));
}

View File

@ -348,9 +348,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
refreshHealth(); // Heal and send health packet
refreshAbilities(); // Send abilities packet
// Start chunk load
sendPacket(new ChangeGameStatePacket(ChangeGameStatePacket.Reason.LEVEL_CHUNKS_LOAD_START, 0));
return setInstance(spawnInstance);
}
@ -761,6 +758,9 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
if (dimensionChange || firstSpawn) {
this.inventory.update();
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));