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

Entity not updating

Discussion in 'Development' started by Smarticles101, Apr 17, 2017.

  1. Smarticles101

    Smarticles101 Silverfish

    Messages:
    22
    GitHub:
    Smarticles101
    I am working on a plugin that requires moving npcs. However, I can't seem to get the Human I created to update after setting a new movement or rotation. The setRotation method calls the scheduleUpdate method which doesnt seem to update by calling it manually, and the setMovement method calls updateMovement which cant be called manually. Any thoughts?

    I have the following code for now where $watch and $follow are both an instance of Player
    Code:
    public function onPlayerMove(PlayerMoveEvent $event) {
        if (isset($this->clones[$event->getPlayer()->getName()])) {
            $watch = $this->clones[$event->getPlayer()->getName()]["watch"];
            $follow = $this->clones[$event->getPlayer()->getName()]["follow"];
            if ($watch !== null) {
                foreach ($this->clones[$event->getPlayer()->getName()] as $clone) {
                    if ($clone instanceof Human) {
                        $clone->setRotation($event->getPlayer()->getYaw(), $event->getPlayer()->getPitch());
                        // messing with setting rotation for now.
                        // will work on actually watching target player once I find my problem
                        // entity wont update unless I hit them?
                    }
                }
            }
            if ($follow !== null) {
                foreach ($this->clones[$event->getPlayer()->getName()] as $clone) {
                    if ($clone instanceof Human) {
                        $clone->setMotion($event->getPlayer()->getMotion());
                        // entity wont update unless I hit them?
                    }
                }
            }
        }
    }
    
     
    Last edited: Apr 17, 2017
  2. Matthew

    Matthew Baby Zombie

    Messages:
    167
    GitHub:
    matthww
    It will help if you share the code, to make it more understandable.
     
  3. Smarticles101

    Smarticles101 Silverfish

    Messages:
    22
    GitHub:
    Smarticles101
    Of course. I forgot. I edited the main post to include my code
     
  4. Matthew

    Matthew Baby Zombie

    Messages:
    167
    GitHub:
    matthww
  5. Smarticles101

    Smarticles101 Silverfish

    Messages:
    22
    GitHub:
    Smarticles101
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PlayerMoveEvent is only called when a Player (mcpe client entity) moves, not an NPC human entity.
     
    Smarticles101 likes this.
  7. Smarticles101

    Smarticles101 Silverfish

    Messages:
    22
    GitHub:
    Smarticles101
    Do you have any idea of how I can update the entity then? Am I doing something wrong?
     
  8. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    for your NPCs, are you using custom entity classes?
     
  9. Smarticles101

    Smarticles101 Silverfish

    Messages:
    22
    GitHub:
    Smarticles101
    They are just instances of Human. I don't think you will need it, but the full source for the plugin I am making is right here: https://github.com/Smarticles101/Clones
     
  10. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Okay, the issue that you have is that you are not using your own entity class to move the entity with onTick() or move()
     
    Smarticles101 likes this.
  11. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Primus likes this.
  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.