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

Solved Entity->teleport() is not working

Discussion in 'Development' started by CortexPE, Feb 24, 2018.

  1. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    I'm working on two plugins that are supposedly needing an entity to follow a player... (on move)

    So the straightforward way to achieve that would be on PlayerMoveEvent, teleport an entity dedicated for a player to the player's position... well for some odd reason, that doesn't work. pseudocode is as follows...
    PHP:
    public function onMove(PlayerMoveEvent $ev){
         if(isset(
    $this->plugin->follow[$ev->getPlayer()->getId()])){
           
    $follower $this->plugin->follow[$ev->getPlayer()->getId()];
           if(
    $follower instanceof FollowerEntity){
                
    $follower->teleport($ev->getPlayer());
           }
       }
    }
    But it does work when I use this <see code below>, with one catch, it can't transfer between worlds
    PHP:
    $follower->$player->x;
    $follower->$player->y;
    $follower->$player->z;
    It returns the correct position (in any means of displaying data) when Entity->asVector3() is used but it doesn't seem to work when viewed client-side as the entity doesn't move an inch.

    This might be a PMMP issue as I've tried this with only two plugins... DevTools and the plugin that's supposed to teleport a 'follower entity' around...
     
  2. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Maybe set the world the player is to be same with the folowers?
     
  3. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    tried that too but that doesn't work.
     
  4. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    This code also reproduces the bug:
    PHP:
    public function onAttack(EntityDamageEvent $event){
       if(!(
    $event instanceof EntityDamageByEntityEvent)){
          return;
       }
       if(
    $event->getDamager() instanceof Player){
          
    var_dump($event->getEntity()->asVector3());
          
    $event->getEntity()->teleport($event->getDamager());
          
    var_dump($event->getEntity()->asVector3());
       }
    }
    I'm not sure what is causing this yet.
     
    CortexPE likes this.
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    You may look at BlockPets' code. There is not any problem like that...
     
  6. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
  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.