PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
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;
28use pocketmine\block\utils\SupportType;
35
36class Chest extends Transparent{
37 use FacesOppositePlacingPlayerTrait;
38
42 protected function recalculateCollisionBoxes() : array{
43 //these are slightly bigger than in PC
44 return [AxisAlignedBB::one()->contract(0.025, 0, 0.025)->trim(Facing::UP, 0.05)];
45 }
46
47 public function getSupportType(int $facing) : SupportType{
48 return SupportType::NONE;
49 }
50
51 public function onPostPlace() : void{
52 $world = $this->position->getWorld();
53 $tile = $world->getTile($this->position);
54 if($tile instanceof TileChest){
55 foreach([false, true] as $clockwise){
56 $side = Facing::rotateY($this->facing, $clockwise);
57 $c = $this->getSide($side);
58 if($c instanceof Chest && $c->hasSameTypeId($this) && $c->facing === $this->facing){
59 $pair = $world->getTile($c->position);
60 if($pair instanceof TileChest && !$pair->isPaired()){
61 [$left, $right] = $clockwise ? [$c, $this] : [$this, $c];
62 $ev = new ChestPairEvent($left, $right);
63 $ev->call();
64 if(!$ev->isCancelled() && $world->getBlock($this->position)->hasSameTypeId($this) && $world->getBlock($c->position)->hasSameTypeId($c)){
65 $pair->pairWith($tile);
66 $tile->pairWith($pair);
67 break;
68 }
69 }
70 }
71 }
72 }
73 }
74
75 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
76 if($player instanceof Player){
77
78 $chest = $this->position->getWorld()->getTile($this->position);
79 if($chest instanceof TileChest){
80 if(
81 !$this->getSide(Facing::UP)->isTransparent() ||
82 (($pair = $chest->getPair()) !== null && !$pair->getBlock()->getSide(Facing::UP)->isTransparent()) ||
83 !$chest->canOpenWith($item->getCustomName())
84 ){
85 return true;
86 }
87
88 $player->setCurrentWindow($chest->getInventory());
89 }
90 }
91
92 return true;
93 }
94
95 public function getFuelTime() : int{
96 return 300;
97 }
98}
hasSameTypeId(Block $other)
Definition Block.php:184
getSupportType(int $facing)
Definition Chest.php:47
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition Chest.php:75