PocketMine-MP 5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
ShulkerBox.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\ShulkerBox as TileShulkerBox;
29use pocketmine\block\utils\AnimatedContainerLikeTrait;
31use pocketmine\block\utils\AnyFacingTrait;
33use pocketmine\block\utils\ContainerTrait;
34use pocketmine\block\utils\SupportType;
49
51 use AnimatedContainerLikeTrait;
52 use AnyFacingTrait;
53 use ContainerTrait;
54
55 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
56 //NOOP - we don't read or write facing here, because the tile persists it
57 }
58
59 public function writeStateToWorld() : void{
60 parent::writeStateToWorld();
61 $shulker = $this->position->getWorld()->getTile($this->position);
62 if($shulker instanceof TileShulkerBox){
63 $shulker->setFacing($this->facing);
64 }
65 }
66
67 public function readStateFromWorld() : Block{
68 parent::readStateFromWorld();
69 $shulker = $this->position->getWorld()->getTile($this->position);
70 if($shulker instanceof TileShulkerBox){
71 $this->facing = $shulker->getFacing();
72 }
73
74 return $this;
75 }
76
77 public function getMaxStackSize() : int{
78 return 1;
79 }
80
81 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{
82 $this->facing = $face;
83
84 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
85 }
86
87 private function addDataFromTile(TileShulkerBox $tile, Item $item) : void{
88 $shulkerNBT = $tile->getCleanedNBT();
89 if($shulkerNBT !== null){
90 $item->setNamedTag($shulkerNBT);
91 }
92 if($tile->hasName()){
93 $item->setCustomName($tile->getName());
94 }
95 }
96
97 public function getDropsForCompatibleTool(Item $item) : array{
98 $drop = $this->asItem();
99 if(($tile = $this->position->getWorld()->getTile($this->position)) instanceof TileShulkerBox){
100 $this->addDataFromTile($tile, $drop);
101 }
102 return [$drop];
103 }
104
105 public function getPickedItem(bool $addUserData = false) : Item{
106 $result = parent::getPickedItem($addUserData);
107 if($addUserData && ($tile = $this->position->getWorld()->getTile($this->position)) instanceof TileShulkerBox){
108 $this->addDataFromTile($tile, $result);
109 }
110 return $result;
111 }
112
113 public function isOpeningObstructed() : bool{
114 return $this->getSide($this->facing)->isSolid();
115 }
116
117 protected function newMenu(Player $player, Inventory $inventory, Position $position) : InventoryWindow{
118 return new BlockInventoryWindow($player, $inventory, $position);
119 }
120
121 public function getSupportType(Facing $facing) : SupportType{
122 return SupportType::NONE;
123 }
124
125 protected function getOpenSound() : Sound{
126 return new ShulkerBoxOpenSound();
127 }
128
129 protected function getCloseSound() : Sound{
130 return new ShulkerBoxCloseSound();
131 }
132
133 protected function playAnimationVisual(Position $position, bool $isOpen) : void{
134 //event ID is always 1 for a chest
135 //TODO: we probably shouldn't be sending a packet directly here, but it doesn't fit anywhere into existing systems
136 $position->getWorld()->broadcastPacketToViewers($position, BlockEventPacket::create(BlockPosition::fromVector3($position), 1, $isOpen ? 1 : 0));
137 }
138}
getDropsForCompatibleTool(Item $item)
getSupportType(Facing $facing)
describeBlockOnlyState(RuntimeDataDescriber $w)
getPickedItem(bool $addUserData=false)
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player=null)
setNamedTag(CompoundTag $tag)
Definition Item.php:268