Inventory: Fixed crash when breaking right half of a double chest while open

This commit is contained in:
Dylan K. Taylor 2018-01-27 10:56:03 +00:00
parent de0741f727
commit 3e35bc38e2
2 changed files with 13 additions and 11 deletions

View File

@ -67,26 +67,28 @@ class ChestInventory extends ContainerInventory{
parent::onOpen($who);
if(count($this->getViewers()) === 1 and ($level = $this->getHolder()->getLevel()) instanceof Level){
$this->broadcastBlockEventPacket($this->getHolder(), true);
$this->broadcastBlockEventPacket(true);
$level->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_CHEST_OPEN);
}
}
public function onClose(Player $who) : void{
if(count($this->getViewers()) === 1 and ($level = $this->getHolder()->getLevel()) instanceof Level){
$this->broadcastBlockEventPacket($this->getHolder(), false);
$this->broadcastBlockEventPacket(false);
$level->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_CHEST_CLOSED);
}
parent::onClose($who);
}
protected function broadcastBlockEventPacket(Vector3 $vector, bool $isOpen) : void{
protected function broadcastBlockEventPacket(bool $isOpen) : void{
$holder = $this->getHolder();
$pk = new BlockEventPacket();
$pk->x = (int) $vector->x;
$pk->y = (int) $vector->y;
$pk->z = (int) $vector->z;
$pk->x = (int) $holder->x;
$pk->y = (int) $holder->y;
$pk->z = (int) $holder->z;
$pk->eventType = 1; //it's always 1 for a chest
$pk->eventData = $isOpen ? 1 : 0;
$this->getHolder()->getLevel()->addChunkPacket($this->getHolder()->getX() >> 4, $this->getHolder()->getZ() >> 4, $pk);
$holder->getLevel()->addChunkPacket($holder->getX() >> 4, $holder->getZ() >> 4, $pk);
}
}

View File

@ -101,14 +101,14 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
public function onOpen(Player $who) : void{
parent::onOpen($who);
if(count($this->getViewers()) === 1){
$this->broadcastBlockEventPacket($this->right->getHolder(), true);
if(count($this->getViewers()) === 1 and $this->right->getHolder()->isValid()){
$this->right->broadcastBlockEventPacket(true);
}
}
public function onClose(Player $who) : void{
if(count($this->getViewers()) === 1){
$this->broadcastBlockEventPacket($this->right->getHolder(), false);
if(count($this->getViewers()) === 1 and $this->right->getHolder()->isValid()){
$this->right->broadcastBlockEventPacket(false);
}
parent::onClose($who);
}