mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-14 07:25:31 +00:00
Fixed Double Chest behavior
This commit is contained in:
parent
50cfeaa393
commit
afaa2cf722
@ -62,7 +62,7 @@ class Chest extends Transparent{
|
||||
3 => 3,
|
||||
];
|
||||
|
||||
$chest = false;
|
||||
$chest = null;
|
||||
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
|
||||
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
@ -130,11 +130,11 @@ class Chest extends Transparent{
|
||||
new Int("z", $this->z)
|
||||
]);
|
||||
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||
$chest = new TileChest($this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
|
||||
$chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
|
||||
}
|
||||
|
||||
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
if($player->isCreative()){
|
||||
return true;
|
||||
}
|
||||
$player->addWindow($chest->getInventory());
|
||||
|
@ -33,10 +33,11 @@ abstract class ContainerInventory extends BaseInventory{
|
||||
$pk->windowid = $who->getWindowId($this);
|
||||
$pk->type = $this->getType()->getNetworkType();
|
||||
$pk->slots = $this->getSize();
|
||||
if($this->holder instanceof Vector3){
|
||||
$pk->x = $this->holder->getX();
|
||||
$pk->y = $this->holder->getY();
|
||||
$pk->z = $this->holder->getZ();
|
||||
$holder = $this->getHolder();
|
||||
if($holder instanceof Vector3){
|
||||
$pk->x = $holder->getX();
|
||||
$pk->y = $holder->getY();
|
||||
$pk->z = $holder->getZ();
|
||||
}else{
|
||||
$pk->x = $pk->y = $pk->z = 0;
|
||||
}
|
||||
|
@ -22,6 +22,10 @@
|
||||
namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\network\protocol\TileEventPacket;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\tile\Chest;
|
||||
|
||||
class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
@ -83,6 +87,37 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
}
|
||||
}
|
||||
|
||||
public function onOpen(Player $who){
|
||||
parent::onOpen($who);
|
||||
|
||||
if(count($this->getViewers()) === 1){
|
||||
$pk = TileEventPacket::getFromPool();
|
||||
$pk->x = $this->right->getHolder()->getX();
|
||||
$pk->y = $this->right->getHolder()->getY();
|
||||
$pk->z = $this->right->getHolder()->getZ();
|
||||
$pk->case1 = 1;
|
||||
$pk->case2 = 2;
|
||||
if(($level = $this->right->getHolder()->getLevel()) instanceof Level){
|
||||
Server::broadcastPacket($level->getUsingChunk($this->right->getHolder()->getX() >> 4, $this->right->getHolder()->getZ() >> 4), $pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function onClose(Player $who){
|
||||
if(count($this->getViewers()) === 1){
|
||||
$pk = TileEventPacket::getFromPool();
|
||||
$pk->x = $this->right->getHolder()->getX();
|
||||
$pk->y = $this->right->getHolder()->getY();
|
||||
$pk->z = $this->right->getHolder()->getZ();
|
||||
$pk->case1 = 1;
|
||||
$pk->case2 = 0;
|
||||
if(($level = $this->right->getHolder()->getLevel()) instanceof Level){
|
||||
Server::broadcastPacket($level->getUsingChunk($this->right->getHolder()->getX() >> 4, $this->right->getHolder()->getZ() >> 4), $pk);
|
||||
}
|
||||
}
|
||||
parent::onClose($who);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ChestInventory
|
||||
*/
|
||||
|
@ -55,8 +55,6 @@ class Chest extends Spawnable implements InventoryHolder, Container{
|
||||
for($i = 0; $i < $this->getSize(); ++$i){
|
||||
$this->inventory->setItem($i, $this->getItem($i));
|
||||
}
|
||||
|
||||
$this->checkPairing();
|
||||
}
|
||||
|
||||
public function close(){
|
||||
@ -158,6 +156,9 @@ class Chest extends Spawnable implements InventoryHolder, Container{
|
||||
* @return ChestInventory|DoubleChestInventory
|
||||
*/
|
||||
public function getInventory(){
|
||||
if($this->isPaired() and $this->doubleInventory === null){
|
||||
$this->checkPairing();
|
||||
}
|
||||
return $this->doubleInventory instanceof DoubleChestInventory ? $this->doubleInventory : $this->inventory;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user