1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

World changing loading screen

Discussion in 'Development' started by MalakasPlayzMCPE, Oct 21, 2018.

  1. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    This happened in versions bellow 1.0.0 for sure. I know how to do that with the change dimension packet but the player becomes something like immoble for a weird reason.
    PHP:
        public function onLevelChange(EntityLevelChangeEvent $event) {
           if((
    $player $event->getEntity()) instanceof Player && !$event->isCancelled()){
               
    $packet = new ChangeDimensionPacket();
               
    $packet->dimension 1;
               
    $packet->position $player->asVector3();
               
    $packet->respawn true;
               
    $player->dataPacket($packet);
               
    $this->getScheduler()->scheduleDelayedTask(new UnshowTask1($this$player), 20); //show loading screen for 1 second
           
    }
       }


    class 
    UnshowTask1 extends Task {

        public function 
    __construct(Main $pluginPlayer $player) {
            
    $this->plugin $plugin;
            
    $this->player $player;
        }

        public function 
    onRun(int $currentTick) : void {
            
    $player $this->player;
            
    $pk = new PlayStatusPacket();
            
    $pk->status 3;
            
    $player->dataPacket($pk);
            
    $packet = new ChangeDimensionPacket(); //I tried doing that with a delay but the same thing happened
            
    $packet->dimension 0;
            
    $packet->position $player->asVector3();
            
    $packet->respawn true;
            
    $player->dataPacket($packet);
            
    $this->plugin->getScheduler()->scheduleDelayedTask(new UnshowTask2($player), 10); //show loading screen again for 0.5 seconds
        
    }
    }


    class 
    UnshowTask2 extends Task {

        public function 
    __construct(Player $player) {
            
    $this->player $player;
        }

        public function 
    onRun(int $currentTick) : void {
            
    $pk = new PlayStatusPacket();
            
    $pk->status 3;
            
    $this->player->dataPacket($pk);
        }
    }
    I searched across the forums for a reply to that but I did not find anything that is working. Maybe the $packet->respawn should be false but I am not sure. There are no errors in the console.

    Here is a link to the dimension ids: https://github.com/pmmp/PocketMine-.../mcpe/protocol/types/DimensionIds.php#L28-L30
     
    Last edited: Oct 21, 2018
  2. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Bump!
     
  3. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Wow. It should be a very difficult question to reply. I tried a bit more and I figured out that setting the dimension to 1 or 2 with respawn off works, without sending the packet twice and it worked, but how to change the sky/atmosphere? The featured servers do hatand end the packet once, or at least, that's what it looks like. Will 3 as a dimension case any errors?

    EDIT: The send the packet twice, with dimension 1, but how does the player not crash?
     
    Last edited: Oct 22, 2018
  4. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Okay, I send the packet twice, one in overload and then in nether. In nether it unshows in 10 ticks. Now when I go to a word it is nether but when I come back it is overload.
     
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    I give up. The dimension shows as nether every 2 times I teleport. No errors nor freezes. What I can say for sure now is that I need help.
     
  6. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    As I can see it is a pretty hard thing to do. Would you recommend me any way for fixing the crashes when teleporting to another world? Crashes for windows 10 users, hotbar crash for pocket edition ones.
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Do you spawn fake player entities (eg: for NPCs or floating texts)? They could cause that if you didn't send a PlayerListPacket.
     
  8. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Yes. All my server works with fake player entities because there are easier to use. Also, every 5 seconds which I despawn and spawn some new npcs, if I go to the list I can see them there for like one tick or less.
     
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I removed the PlayerListPacket workaround for a while and had experienced crashes while changing dimensions. I reverted back to the PlayerListPacket workaround and it worked fine after then. You can find the workaround in pmmp's FloatingTextParticle class.
     
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    By the way, $respawn is used when the client dies in a dimension other than the main dimension. Eg: dying in nether and getting teleported to overworld on respawn. For a vanilla impl, you would do something like this:
    PHP:
    $pk->respawn = !$player->isAlive();
     
  11. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    It does not happen every time. I would send you the IP of my server in a dm because here it would be considered as advertising.
    Is that what you are talking about? https://github.com/pmmp/PocketMine-...vel/particle/FloatingTextParticle.php#L96-L99
     
  12. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
  13. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Okay, just came back from school. Correct me if wrong. I have an entity that extends human. I go to that file and I add something like that:
    public function spawnToAll() : void{
    //player list packet, I add the npc
    parent::spawnToAll();
    //remove it from the player list shown in the client
    }

    But why should I do that when pocketmine does itself? https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Human.php#L840

    Are you sure that's what is causing it?

    That's the reason i need the loading screen. Since huge servers like hivemc did not solve that, it means it cannot be fixed that easy or it is impossible to fix without that trick. What they actually do it to prevent it from happening.
     
  14. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Bump again. I feel like I will never do that.
     
  15. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Bump?
     
  16. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Ughh, come on
     
  17. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    Use ChangeDimensionPacket is just decorative ?
     
  18. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Not really. It prevents crashes when changing worlds.
     
  19. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Come on, is it too hard to help me?
     
  20. HBIDamian

    HBIDamian HBIDamian Staff Member

    Messages:
    365
    GitHub:
    HBIDamian
    People will choose to help you in their own time.
    If you’re that rude about it, then you should go looking for help in your trash can.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.