Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Set rotation of entity

Comments in 'Plugin Development' started by Valeron, Apr 12, 2016.

  1. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    I wanna create setRotation of npc as: play.brokenlens.xyz:2000(sry for adv i can remove)
    I used:
    $entity->setRotation(args...)
    Ignored...
    $player->setRotation(args...) works good
    But entity does not works

    My friend said me that need to use CompoudTag i now that it is nbt. But i cant use nbt i code...

    Sorry for my english

    Can u help me?
  2. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    *in code
  3. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    I did it like:
    $entity->yaw = xxx;
    $entity->setRotation($entity->yaw, $entity->pitch);
    $entity->moveTo($entity->x , y, z);

    And then an entitymoveevent packet to all players nearby.
    Somehow doesnt work for SlapperEntities, but every other entity.
    Valeron likes this.
  4. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Full code:
    PHP:

        
    public function playerMove(PlayerMoveEvent $event){
            if(
    $this->getConfig()->get("rotate") == "true"){
                
    $player $event->getPlayer();
                if(!
    in_array($player->getInventory()->getItemInHand()->getId(), array(Item::BONE))) return;
                
    $entities $player->getLevel()->getNearbyEntities(new AxisAlignedBB($player->getX() - 5$player->getY() - 5$player->getZ() - 5$player->getX() + 5$player->getY() + 5$player->getZ() + 5));
                if(
    count($entities) > 0){
                    foreach(
    $entities as $entity){
                        if(
    $entity instanceof SlapperHuman){
                            
    $entity->setDataFlag(Entity::DATA_NO_AI0false);
                            
    $dist $entity->distance($player);
                            
    $dir $player->subtract($entity);
                            
    $dir $dist <= 0?$dir:$dir->divide($dist);
                           
                            
    // $entity->yaw = rad2deg(atan2(-$dir->getX(), $dir->getZ()));
                            // $entity->pitch = rad2deg(atan(-$dir->getY()));
                           
                            
    $yaw rad2deg(atan2(-$dir->getX(), $dir->getZ()));
                            
    $pitch rad2deg(atan(-$dir->getY()));
                           
                            if(
    $dist <= 5$entity->move($dir->x$dir->y$dir->z);
                            
    $entity->setRotation($entity->yaw$entity->pitch);
                           
                            
    $pk = new MoveEntityPacket();
                            
    $pk->eid $entity->getId();
                            
    $pk->$entity->x;
                            
    $pk->$entity->- ($entity->height 2);
                            
    $pk->$entity->z;
                            
    $pk->yaw $yaw;
                            
    $pk->headYaw $yaw;
                            
    $pk->pitch $pitch;
                            
    $player->dataPacket($pk);
                           
                            
    $pk = new SetEntityMotionPacket();
                            
    $pk->$entity->x;
                            
    $pk->$entity->- ($entity->height 2);
                            
    $pk->$entity->z;
                            
    $player->dataPacket($pk);
                        }
                    }
                }
            }
        }
    KubixQ, Valeron, Ritch and 1 other person like this.
  5. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    U are top coder
  6. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Thanks.. but remember to read and trying to understand this code. Things like if instanceof SlapperHuman are not needed in this!
    Even the config stuff is optional.
    Read through it and concider what to remove. BTW: this moves the entity right into your players position, looking at him. If you run, it actually follows you.
    Valeron and KubixQ like this.
  7. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    I will use if(!$entity instanceof Player){
    Becouse i cant enable SlapperHuman class.
  8. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
  9. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Where is axisAlignet class?
    I cant find
  10. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Thanks
  11. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
  12. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Damn!! It is not setRotation. It is moving ....
    I gonna setRotation of Head
  13. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    It is moving as Lifeboat
  14. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    And... Set rotation does not works. Only move
  15. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    I said it, and u didnt hear
  16. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Oh sorry my fault.
    Im noob
  17. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Damn!!! I wanna that npc dont move!!
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Stop spamming...
    thebigsmileXD and xBeastMode like this.
  19. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Damn dude, this is not a public chat to be spamming like that.
    thebigsmileXD likes this.

Share This Page

Advertisement