PocketMine-MP 5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
EnderChest.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
27use pocketmine\block\tile\EnderChest as TileEnderChest;
29use pocketmine\block\utils\AnimatedContainerLikeTrait;
30use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
32use pocketmine\block\utils\MenuAccessorTrait;
33use pocketmine\block\utils\SupportType;
44
46 use AnimatedContainerLikeTrait {
47 onViewerAdded as private traitOnViewerAdded;
48 onViewerRemoved as private traitOnViewerRemoved;
49 }
50 use MenuAccessorTrait;
51 use FacesOppositePlacingPlayerTrait;
52
53 public function getLightLevel() : int{
54 return 7;
55 }
56
57 protected function recalculateCollisionBoxes() : array{
58 //these are slightly bigger than in PC
59 return [AxisAlignedBB::one()->contractedCopy(0.025, 0, 0.025)->trimmedCopy(Facing::UP, 0.05)];
60 }
61
62 public function getSupportType(Facing $facing) : SupportType{
63 return SupportType::NONE;
64 }
65
66 public function isOpeningObstructed() : bool{
67 return !$this->getSide(Facing::UP)->isTransparent();
68 }
69
70 protected function newMenu(Player $player, Position $position) : BlockInventoryWindow{
71 return new BlockInventoryWindow($player, $player->getEnderInventory(), $position);
72 }
73
74 public function getDropsForCompatibleTool(Item $item) : array{
75 return [
76 VanillaBlocks::OBSIDIAN()->asItem()->setCount(8)
77 ];
78 }
79
80 public function isAffectedBySilkTouch() : bool{
81 return true;
82 }
83
84 protected function getViewerCount() : int{
85 $enderChest = $this->position->getWorld()->getTile($this->position);
86 if(!$enderChest instanceof TileEnderChest){
87 return 0;
88 }
89 return $enderChest->getViewerCount();
90 }
91
92 private function updateViewerCount(int $amount) : void{
93 $enderChest = $this->position->getWorld()->getTile($this->position);
94 if($enderChest instanceof TileEnderChest){
95 $enderChest->setViewerCount($enderChest->getViewerCount() + $amount);
96 }
97 }
98
99 protected function getOpenSound() : Sound{
100 return new EnderChestOpenSound();
101 }
102
103 protected function getCloseSound() : Sound{
104 return new EnderChestCloseSound();
105 }
106
107 protected function playAnimationVisual(Position $position, bool $isOpen) : void{
108 //event ID is always 1 for a chest
109 //TODO: we probably shouldn't be sending a packet directly here, but it doesn't fit anywhere into existing systems
110 $position->getWorld()->broadcastPacketToViewers($position, BlockEventPacket::create(BlockPosition::fromVector3($position), 1, $isOpen ? 1 : 0));
111 }
112
113 public function onViewerAdded() : void{
114 $this->updateViewerCount(1);
115 $this->traitOnViewerAdded();
116 }
117
118 public function onViewerRemoved() : void{
119 $this->traitOnViewerRemoved();
120 $this->updateViewerCount(-1);
121 }
122}
getDropsForCompatibleTool(Item $item)
getSupportType(Facing $facing)