From b4c2305c7f851ae14ff591755ad3600c6d111328 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 8 Aug 2017 10:44:11 +0100 Subject: [PATCH] Minor cleanup of Human->initEntity() --- src/pocketmine/Player.php | 16 +++++++++++++++- src/pocketmine/entity/Human.php | 29 ++++++++++++++++------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index fb2760b9528..6ef4d0a80b5 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1758,6 +1758,14 @@ public function canInteract(Vector3 $pos, $maxDistance, $maxDiff = 0.5){ return ($dot1 - $dot) >= -$maxDiff; } + protected function initHumanData(){ + //No need to do anything here, this data will be set from the login. + } + + protected function initEntity(){ + parent::initEntity(); + $this->addDefaultWindows(); + } protected function processLogin(){ @@ -3812,6 +3820,12 @@ public function teleportImmediate(Vector3 $pos, float $yaw = null, float $pitch return $this->teleport($pos, $yaw, $pitch); } + protected function addDefaultWindows(){ + $this->addWindow($this->getInventory(), ContainerIds::INVENTORY); + + //TODO: more windows + } + /** * @param Inventory $inventory * @@ -3841,7 +3855,7 @@ public function addWindow(Inventory $inventory, int $forceId = null) : int{ if($forceId === null){ $this->windowCnt = $cnt = max(ContainerIds::FIRST, ++$this->windowCnt % ContainerIds::LAST); }else{ - $cnt = (int) $forceId; + $cnt = $forceId; } $this->windowIndex[$cnt] = $inventory; $this->windows->attach($inventory, $cnt); diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 231dff00e13..68db995337e 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -281,25 +281,28 @@ public function getInventory(){ return $this->inventory; } + /** + * For Human entities which are not players, sets their properties such as nametag, skin and UUID from NBT. + */ + protected function initHumanData(){ + if(isset($this->namedtag->NameTag)){ + $this->setNameTag($this->namedtag["NameTag"]); + } + + if(isset($this->namedtag->Skin) and $this->namedtag->Skin instanceof CompoundTag){ + $this->setSkin($this->namedtag->Skin["Data"], $this->namedtag->Skin["Name"]); + } + + $this->uuid = UUID::fromData((string) $this->getId(), $this->getSkinData(), $this->getNameTag()); + } + protected function initEntity(){ $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false, self::DATA_TYPE_BYTE); $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0], false); $this->inventory = new PlayerInventory($this); - if($this instanceof Player){ - $this->addWindow($this->inventory, 0); - }else{ - if(isset($this->namedtag->NameTag)){ - $this->setNameTag($this->namedtag["NameTag"]); - } - - if(isset($this->namedtag->Skin) and $this->namedtag->Skin instanceof CompoundTag){ - $this->setSkin($this->namedtag->Skin["Data"], $this->namedtag->Skin["Name"]); - } - - $this->uuid = UUID::fromData((string) $this->getId(), $this->getSkinData(), $this->getNameTag()); - } + $this->initHumanData(); if(isset($this->namedtag->Inventory) and $this->namedtag->Inventory instanceof ListTag){ foreach($this->namedtag->Inventory as $item){