Implemented double chest fix, closes #2744, fixes #2493

This commit is contained in:
Shoghi Cervantes 2015-03-17 17:49:10 +01:00
parent ffcdf49912
commit 37bc1273ee
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
3 changed files with 18 additions and 9 deletions

View File

@ -1279,7 +1279,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
if($diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()){
if($this->inAirTicks < 100){
$this->setMotion(new Vector3(0, $expectedVelocity, 0));
}elseif($this->kick("Flying is not enabled on this server"))
}elseif($this->kick("Flying is not enabled on this server")){
return false;
}
}

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);
}
}
}