PocketMine-MP 5.31.1 git-c65f740ce5006911c3bac72aa5e6c3707846bd6e
Loading...
Searching...
No Matches
Chest.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
26use pocketmine\block\tile\Chest as TileChest;
27use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
29use pocketmine\block\utils\SupportType;
36
37class Chest extends Transparent implements HorizontalFacing{
38 use FacesOppositePlacingPlayerTrait;
39
40 protected function recalculateCollisionBoxes() : array{
41 //these are slightly bigger than in PC
42 return [AxisAlignedBB::one()->contract(0.025, 0, 0.025)->trim(Facing::UP, 0.05)];
43 }
44
45 public function getSupportType(int $facing) : SupportType{
46 return SupportType::NONE;
47 }
48
49 public function onPostPlace() : void{
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);
56 if($c instanceof Chest && $c->hasSameTypeId($this) && $c->facing === $this->facing){
57 $pair = $world->getTile($c->position);
58 if($pair instanceof TileChest && !$pair->isPaired()){
59 [$left, $right] = $clockwise ? [$c, $this] : [$this, $c];
60 $ev = new ChestPairEvent($left, $right);
61 $ev->call();
62 if(!$ev->isCancelled() && $world->getBlock($this->position)->hasSameTypeId($this) && $world->getBlock($c->position)->hasSameTypeId($c)){
63 $pair->pairWith($tile);
64 $tile->pairWith($pair);
65 break;
66 }
67 }
68 }
69 }
70 }
71 }
72
73 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
74 if($player instanceof Player){
75
76 $chest = $this->position->getWorld()->getTile($this->position);
77 if($chest instanceof TileChest){
78 if(
79 !$this->getSide(Facing::UP)->isTransparent() ||
80 (($pair = $chest->getPair()) !== null && !$pair->getBlock()->getSide(Facing::UP)->isTransparent()) ||
81 !$chest->canOpenWith($item->getCustomName())
82 ){
83 return true;
84 }
85
86 $player->setCurrentWindow($chest->getInventory());
87 }
88 }
89
90 return true;
91 }
92
93 public function getFuelTime() : int{
94 return 300;
95 }
96}
hasSameTypeId(Block $other)
Definition Block.php:187
getSupportType(int $facing)
Definition Chest.php:45
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition Chest.php:73