Minor cleanup of Human->initEntity()

This commit is contained in:
Dylan K. Taylor 2017-08-08 10:44:11 +01:00
parent 1d0f0a2999
commit b4c2305c7f
2 changed files with 31 additions and 14 deletions

View File

@ -1758,6 +1758,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return ($dot1 - $dot) >= -$maxDiff; 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(){ protected function processLogin(){
@ -3812,6 +3820,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return $this->teleport($pos, $yaw, $pitch); return $this->teleport($pos, $yaw, $pitch);
} }
protected function addDefaultWindows(){
$this->addWindow($this->getInventory(), ContainerIds::INVENTORY);
//TODO: more windows
}
/** /**
* @param Inventory $inventory * @param Inventory $inventory
* *
@ -3841,7 +3855,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if($forceId === null){ if($forceId === null){
$this->windowCnt = $cnt = max(ContainerIds::FIRST, ++$this->windowCnt % ContainerIds::LAST); $this->windowCnt = $cnt = max(ContainerIds::FIRST, ++$this->windowCnt % ContainerIds::LAST);
}else{ }else{
$cnt = (int) $forceId; $cnt = $forceId;
} }
$this->windowIndex[$cnt] = $inventory; $this->windowIndex[$cnt] = $inventory;
$this->windows->attach($inventory, $cnt); $this->windows->attach($inventory, $cnt);

View File

@ -281,15 +281,10 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
return $this->inventory; return $this->inventory;
} }
protected function initEntity(){ /**
* For Human entities which are not players, sets their properties such as nametag, skin and UUID from NBT.
$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); protected function initHumanData(){
$this->inventory = new PlayerInventory($this);
if($this instanceof Player){
$this->addWindow($this->inventory, 0);
}else{
if(isset($this->namedtag->NameTag)){ if(isset($this->namedtag->NameTag)){
$this->setNameTag($this->namedtag["NameTag"]); $this->setNameTag($this->namedtag["NameTag"]);
} }
@ -301,6 +296,14 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->uuid = UUID::fromData((string) $this->getId(), $this->getSkinData(), $this->getNameTag()); $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);
$this->initHumanData();
if(isset($this->namedtag->Inventory) and $this->namedtag->Inventory instanceof ListTag){ if(isset($this->namedtag->Inventory) and $this->namedtag->Inventory instanceof ListTag){
foreach($this->namedtag->Inventory as $item){ foreach($this->namedtag->Inventory as $item){
if($item["Slot"] >= 0 and $item["Slot"] < 9){ //Hotbar if($item["Slot"] >= 0 and $item["Slot"] < 9){ //Hotbar