Fixed double chest inventory desync issues, closes #2261 (#2279)

chest pairing really needs rewriting... this code really sucks
This commit is contained in:
Dylan K. Taylor 2018-07-05 17:42:30 +01:00 committed by GitHub
parent 58f0ad3e3e
commit 5dbb0d177e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -64,7 +64,12 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
}
public function setItem(int $index, Item $item, bool $send = true) : bool{
return $index < $this->left->getSize() ? $this->left->setItem($index, $item, $send) : $this->right->setItem($index - $this->left->getSize(), $item, $send);
$old = $this->getItem($index);
if($index < $this->left->getSize() ? $this->left->setItem($index, $item, $send) : $this->right->setItem($index - $this->left->getSize(), $item, $send)){
$this->onSlotChange($index, $old, $send);
return true;
}
return false;
}
public function getContents(bool $includeEmpty = false) : array{

View File

@ -113,10 +113,14 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{
$pair->checkPairing();
}
if($this->doubleInventory === null){
if(($pair->x + ($pair->z << 15)) > ($this->x + ($this->z << 15))){ //Order them correctly
$this->doubleInventory = new DoubleChestInventory($pair, $this);
if($pair->doubleInventory !== null){
$this->doubleInventory = $pair->doubleInventory;
}else{
$this->doubleInventory = new DoubleChestInventory($this, $pair);
if(($pair->x + ($pair->z << 15)) > ($this->x + ($this->z << 15))){ //Order them correctly
$this->doubleInventory = new DoubleChestInventory($pair, $this);
}else{
$this->doubleInventory = new DoubleChestInventory($this, $pair);
}
}
}
}else{