Inventory: Split up armor and player inventory (#1957)

* Inventory: Split up PlayerInventory and armour handling
* Fixed other players don't see armour changes. This bug also exists on master.
This commit is contained in:
Dylan K. Taylor
2018-01-23 20:01:26 +00:00
committed by GitHub
parent 0bf5ab76fb
commit 6543d96910
8 changed files with 198 additions and 235 deletions

View File

@@ -74,7 +74,6 @@ use pocketmine\inventory\BigCraftingGrid;
use pocketmine\inventory\CraftingGrid;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\PlayerCursorInventory;
use pocketmine\inventory\PlayerInventory;
use pocketmine\inventory\transaction\action\InventoryAction;
use pocketmine\inventory\transaction\CraftingTransaction;
use pocketmine\inventory\transaction\InventoryTransaction;
@@ -2077,7 +2076,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->sendData($this);
$this->inventory->sendContents($this);
$this->inventory->sendArmorContents($this);
$this->armorInventory->sendContents($this);
$this->inventory->sendCreativeContents();
$this->inventory->sendHeldItem($this);
@@ -2669,7 +2668,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->sendSettings();
$this->inventory->sendContents($this);
$this->inventory->sendArmorContents($this);
$this->armorInventory->sendContents($this);
$this->spawnToAll();
$this->scheduleUpdate();
@@ -3567,15 +3566,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return false; //never flag players for despawn
}
public function getArmorPoints() : int{
$total = 0;
foreach($this->inventory->getArmorContents() as $item){
$total += $item->getDefensePoints();
}
return $total;
}
protected function applyPostDamageEffects(EntityDamageEvent $source) : void{
parent::applyPostDamageEffects($source);
@@ -3675,6 +3665,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
protected function addDefaultWindows(){
$this->addWindow($this->getInventory(), ContainerIds::INVENTORY, true);
$this->addWindow($this->getArmorInventory(), ContainerIds::ARMOR, true);
$this->cursorInventory = new PlayerCursorInventory($this);
$this->addWindow($this->cursorInventory, ContainerIds::CURSOR, true);
@@ -3811,9 +3803,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
protected function sendAllInventories(){
foreach($this->windowIndex as $id => $inventory){
$inventory->sendContents($this);
if($inventory instanceof PlayerInventory){
$inventory->sendArmorContents($this);
}
}
}