Merge branch 'master' into mcpe-0.11

This commit is contained in:
Shoghi Cervantes
2015-03-17 19:12:03 +01:00
38 changed files with 482 additions and 228 deletions

View File

@ -115,7 +115,9 @@ abstract class BaseInventory implements Inventory{
$this->clear($i);
}
}else{
$this->setItem($i, $items[$i]);
if (!$this->setItem($i, $items[$i])){
$this->clear($i);
}
}
}
}

View File

@ -37,7 +37,8 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
public function __construct(Chest $left, Chest $right){
$this->left = $left->getRealInventory();
$this->right = $right->getRealInventory();
BaseInventory::__construct($this, InventoryType::get(InventoryType::DOUBLE_CHEST));
$items = array_merge($this->left->getContents(), $this->right->getContents());
BaseInventory::__construct($this, InventoryType::get(InventoryType::DOUBLE_CHEST), $items);
}
public function getInventory(){
@ -77,13 +78,19 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
$items = array_slice($items, 0, $this->size, true);
}
parent::setContents($items);
$leftItems = array_slice($items, 0, $this->left->getSize(), true);
$this->left->setContents($leftItems);
if(count($items) > $this->left->getSize()){
$rightItems = array_slice($items, $this->left->getSize() - 1, $this->right->getSize(), true);
$this->right->setContents($rightItems);
for($i = 0; $i < $this->size; ++$i){
if(!isset($items[$i])){
if ($i < $this->left->size){
if(isset($this->left->slots[$i])){
$this->clear($i);
}
}elseif(isset($this->right->slots[$i - $this->left->size])){
$this->clear($i);
}
}elseif(!$this->setItem($i, $items[$i])){
$this->clear($i);
}
}
}

View File

@ -25,6 +25,7 @@ use pocketmine\entity\Human;
use pocketmine\event\entity\EntityArmorChangeEvent;
use pocketmine\event\entity\EntityInventoryChangeEvent;
use pocketmine\event\player\PlayerItemHeldEvent;
use pocketmine\item\Armor;
use pocketmine\item\Item;
use pocketmine\network\protocol\ContainerSetContentPacket;
use pocketmine\network\protocol\ContainerSetSlotPacket;
@ -297,6 +298,15 @@ class PlayerInventory extends BaseInventory{
return $armor;
}
public function getArmorPoints(){
$points = 0;
foreach($this->getArmorContents() as $i){
if($i instanceof Armor){
$points += $i->getArmorPoints();
}
}
return $points;
}
public function clearAll(){
$limit = $this->getSize() + 4;
for($index = 0; $index < $limit; ++$index){