Teleporting - load chunks from the player

Discussion in 'Plugin Development' started by matejdro, Jun 4, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    matejdro

    When teleporting via notch's nether portals, it appears that first loaded chunk is chunk, where you are standing and then load chunks around you. So you can start doing stuff instantly.

    But when using player.teleport() method, it will start loading chunks from one side of the map. So you have to wait until "chunk loading line" comes to your chunk.

    Is there a way to teleport players using notch's nether teleport, so players won't have to wait after teleporting?

    P.S.: I'm talking about loading in client (where you are "jumping" in midair waiting for client to load all chunks).
     

    Attached Files:

  2. There might be a way to force the client to load a chunk after a teleport event and I'm guessing you'd have to get the server handle but I'm not too sure on how to do that.

    I think I've found a way to do this.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 16, 2016
  3. Offline

    matejdro

    It's not just forcing a client to load specific chunk, but It's "chunk loading style". When teleporting to notch's nether, chunks will load from player, but when using player.teleport(), it will load chunks from the side of the map.
     
  4. What you want to do is register an onPlayerTeleport event and then get CraftBukkits server handle to manually load chunks. I'd suggest loading the one immediately by the player and then the rest of the chunks should load in-time.
    PHP:
    public void onPlayerTeleport(PlayerTeleportEvent event){
        
    Player p event.getPlayer();
        
    CraftWorld cw = (CraftWorld)player.getWorld();
        
    cw.loadChunk(player.getX(), player.getZ());
    }
     
  5. Offline

    Shamebot

    Why cast to CraftWorld?
     
  6. Offline

    matejdro

    this will load chunk on server, which does not change much, since chunks with portals (I'm doing this for PortalStick) are already always loaded. Problem is loading of chunk on client.

    I had a look on Map Chunk packet (one that appears to send map data to player) and it seems super complicated.
     
  7. Offline

    Shamebot

    I'm not sure if it would help, since that's probably the packet sent when a chunk is loaded.
     
  8. Offline

    matejdro

    chunk is already loaded, but It's not sent to client.
     
  9. Offline

    Shamebot

    Packet51MapCunk doesn't look that complicated, the constructor takes the two locations and the world, you then can send it this way:
    Code:
    ((CraftPlayer)player).getHandle().netServerHandler.sendPacket(packet);
     
Thread Status:
Not open for further replies.

Share This Page