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

I created enitiy want it move But it's half enitiy

Discussion in 'Help' started by Furit Cake, Nov 27, 2021.

  1. Furit Cake

    Furit Cake Spider

    Messages:
    11
    //This is my ANPC class
    <?php

    namespace SuperCopy\entity\monster\walking\WearableMonster;

    use SuperCopy\entity\monster\WearableMonster;
    use pocketmine\Player;
    use pocketmine\item\Item;
    use pocketmine\level\Level;
    use pocketmine\utils\UUID;
    use pocketmine\entity\Entity;
    use pocketmine\network\mcpe\protocol\AddPlayerPacket;
    use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
    use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket;
    use pocketmine\network\mcpe\protocol\PlayerListPacket;
    use pocketmine\network\mcpe\protocol\types\PlayerListEntry;

    use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
    use pocketmine\Server;
    use pocketmine\level\Location;
    use pocketmine\network\mcpe\protocol\MovePlayerPacket;
    use pocketmine\network\mcpe\protocol\types\SkinAdapterSingleton;


    class ANPC extends WearableMonster{

    const NETWORK_ID = 63;

    public $width = 0.6;
    public $height = 1.8;
    //public $eyeHeight = 1.62;
    public $Location;

    public static $metadata=array();

    public function getName() : string{

    return "ANPC";
    }

    public function getDrops() : array{

    if($this->rpg === []){
    switch(mt_rand(1, 3)){
    case 1:
    case 2: return [Item::get(367, 0, mt_rand(1, 3))];
    default: return [];
    }
    }else{
    return [];
    }
    }






    public function getUniqueId() : ?UUID{

    return UUID::fromData($this->getId(), $this->namedtag["Skin"]["Data"], $this->rpg["名字"]);
    }

    public function spawnTo(Player $player): void {

    // if(isset($this->hasSpawned[$player->getLoaderId()]) or !isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])) return;

    //$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getName(), $this->namedtag["Skin"]["Name"], $this->namedtag["Skin"]["Data"]);
    $this->Location = new Location((float) $this->x, (float) $this->y+1.67, (float) $this->z, 0.0, 0.0, Server::getInstance()->getLevelByName($this->level->getName()));
    /* if($level===false)
    {
    $level=$player->getLevel();
    }
    if($this->getLevel()!=='' && strtolower($level->getFolderName())!==strtolower($this->level))
    {
    $this->despawnFrom($player);
    //return false;
    }
    */

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



    //var_dump( $this->namedtag["Skin"]["Data"]);


    $skin = SkinAdapterSingleton::get()->toSkinData($player->getSkin());
    $pk = new PlayerListPacket();
    $pk->type = PlayerListPacket::TYPE_ADD;
    $pk->entries = [PlayerListEntry::createAdditionEntry($this->getUniqueId(),$this->getId(), $this->getName(), $skin)];
    $player->dataPacket($pk);
    $pk = new AddPlayerPacket();
    $pk->uuid = $this->getUniqueId();
    $pk->username = $this->getName();
    $pk->entityRuntimeId = $this->getId();
    $pk->position = $this->Location->asVector3();
    $pk->motion = $this->Location->asVector3();
    $pk->yaw = $this->yaw;
    $pk->pitch = $this->pitch;
    $pk->item = ItemStackWrapper::legacy($this->Held);
    $pk->metadata = $this->getDataPropertyManager()->getAll();
    $player->dataPacket($pk);
    $this->sendData($player, [self::DATA_NAMETAG => [self::DATA_TYPE_STRING, $this->getName()]]);//Hack for MCPE 1.2.13: DATA_NAMETAG is useless in AddPlayerPacket, so it has to be sent separately
    $pk = new PlayerListPacket();
    $pk->type = PlayerListPacket::TYPE_REMOVE;
    $pk->entries = [PlayerListEntry::createRemovalEntry( $this->getUniqueId())];
    $player->dataPacket($pk);




    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /*
    $pk = new AddPlayerPacket();
    $pk->uuid = $this->getUniqueId();
    $pk->username = $this->getName();
    $pk->entityUniqueId = $this->getId();
    $pk->entityRuntimeId = $this->getId();
    // $pk->eid = $this->getId();
    $pk->motion= $this->Location->asVector3();
    // var_dump( $pk->motion);
    $pk->position = $this->Location->asVector3();
    //$pk->x = $this->x;
    //$pk->y = $this->y;
    //$pk->z = $this->z;
    //$pk->speedX = 0;
    //$pk->speedY = 0;
    //$pk->speedZ = 0;
    $pk->yaw = $this->yaw;
    $pk->pitch = $this->pitch;
    $pk->item= ItemStackWrapper::legacy($this->Held);
    $pk->headYaw=$this->yaw;
    // var_dump($this->Location->yaw);
    //$pk->item = $this->Held;
    $pk->metadata = self::$metadata;
    $player->dataPacket($pk);

    //$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getName(), $player->getSkin(),$xboxUserId = "",array($player));
    Server::getInstance()->updatePlayerListData($this->getUniqueId(),$this->getId(),$this->getName(),$player->getSkin(),$xboxUserId = "",array($player));
    //
    */
    $Armor = new MobArmorEquipmentPacket();
    $Armor->entityRuntimeId = $this->getId();
    $Armor->head = ItemStackWrapper::legacy($this->Cap);
    $Armor->chest = ItemStackWrapper::legacy($this->Tunic);
    $Armor->legs = ItemStackWrapper::legacy($this->Pants);
    $Armor->feet = ItemStackWrapper::legacy($this->Boots);



    /* $Armor->slots = [
    0 => $this->Cap,
    1 => $this->Tunic,
    2 => $this->Pants,
    3 => $this->Boots
    ];
    */
    $player->dataPacket($Armor);
    // Server::getInstance()->removePlayerListData($this->getUniqueId(),array($player));
    $this->hasSpawned[$player->getLoaderId()] = $player;
    }

    }
     
  2. Furit Cake

    Furit Cake Spider

    Messages:
    11
    And in game, show half the body move , I use var_dump() want get X-Y-Z ,But get data is not error
     
  3. Furit Cake

    Furit Cake Spider

    Messages:
    11
    And if I created other entity like zombie ,The body is normal body in game not half .But use AddPlayerPacket() create is half.
     
  4. Furit Cake

    Furit Cake Spider

    Messages:
    11
    Oh ha ha I fix this ! If someone have some like this, you should get entity Y and set Y+1.6!
     
  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.