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