50 $world = $this->position->getWorld();
51 $tile = $world->getTile($this->position);
52 if($tile instanceof TileChest){
53 foreach([
false,
true] as $clockwise){
54 $side = Facing::rotateY($this->facing, $clockwise);
55 $c = $this->getSide($side);
57 $pair = $world->getTile($c->position);
58 if($pair instanceof TileChest && !$pair->isPaired()){
59 [$left, $right] = $clockwise ? [$c, $this] : [$this, $c];
62 if(!$ev->isCancelled() && $world->getBlock($this->position)->hasSameTypeId($this) && $world->getBlock($c->position)->hasSameTypeId($c)){
63 $pair->pairWith($tile);
64 $tile->pairWith($pair);
74 if($player instanceof
Player){
76 $chest = $this->position->getWorld()->getTile($this->position);
77 if($chest instanceof TileChest){
79 !$this->getSide(Facing::UP)->isTransparent() ||
80 (($pair = $chest->getPair()) !==
null && !$pair->getBlock()->getSide(Facing::UP)->isTransparent()) ||
81 !$chest->canOpenWith($item->getCustomName())
86 $player->setCurrentWindow($chest->getInventory());