Solved PacketPlayOutRespawn client behavior question

Discussion in 'Spigot Plugin Development' started by TeamBergerhealer, Feb 8, 2020.

  1. TeamBergerhealer

    Supporter

    As part of tracking what entities a client sees, I listen for the respawn packet to know when the client resets chunks/entities when moving between worlds. I noticed that two such packets were fired when moving between worlds, so I got curious.

    I noticed this code:
    Code (Java):
            // Force the client to refresh their chunk cache
            if (fromWorld.getEnvironment() == worldserver.getWorld().getEnvironment()) {
                entityplayer1.playerConnection.sendPacket(new PacketPlayOutRespawn(worldserver.worldProvider.getDimensionManager().getDimensionID() >= 0 ? DimensionManager.NETHER : DimensionManager.OVERWORLD, WorldData.c(worldserver.getWorldData().getSeed()), worldserver.getWorldData().getType(), entityplayer.playerInteractManager.getGameMode()));
            }

            WorldData worlddata = worldserver.getWorldData();

            entityplayer1.playerConnection.sendPacket(new PacketPlayOutRespawn(worldserver.worldProvider.getDimensionManager().getType(),  WorldData.c(worldserver.getWorldData().getSeed()), worldserver.getWorldData().getType(), entityplayer1.playerInteractManager.getGameMode()));
    Do I interpret this correctly that, when moving to another world of the same environment type, another respawn packet is sent to change the environment? Do clients only reset their loaded chunks/entities when the world environment / type changes, or does it reset for every respawn packet?
     
  2. See wiki.vg:
    I’m not 100% certain on this but I’m pretty sure this guard didn’t exist in 1.8, which caused some strange issues with things like PlayerDeathEvent and preventing players from dying.

    -1 is the nether so basically the first packet is supposed to send them to the nether if that isn’t their target dimension and then after that send to back to the actual dimension. So I’d say yeah, its only meant to be there to change the dimension to a different one first.

    My guess is only when the dimension changes based on how there could be issues if you don’t change the dimension, but I can’t be sure.
     
    • Informative Informative x 1
  3. TeamBergerhealer

    Supporter