Skip to content

Commit

Permalink
Minor cleanup of Human->initEntity()
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Aug 8, 2017
1 parent 1d0f0a2 commit b4c2305
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
16 changes: 15 additions & 1 deletion src/pocketmine/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 16 additions & 13 deletions src/pocketmine/entity/Human.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit b4c2305

Please sign in to comment.