PocketMine-MP 5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
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
26use pocketmine\block\tile\ShulkerBox as TileShulkerBox;
28use pocketmine\block\utils\AnyFacingTrait;
29use pocketmine\block\utils\SupportType;
35
36class ShulkerBox extends Opaque implements AnyFacing{
37 use AnyFacingTrait;
38
39 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
40 //NOOP - we don't read or write facing here, because the tile persists it
41 }
42
43 public function writeStateToWorld() : void{
44 parent::writeStateToWorld();
45 $shulker = $this->position->getWorld()->getTile($this->position);
46 if($shulker instanceof TileShulkerBox){
47 $shulker->setFacing($this->facing);
48 }
49 }
50
51 public function readStateFromWorld() : Block{
52 parent::readStateFromWorld();
53 $shulker = $this->position->getWorld()->getTile($this->position);
54 if($shulker instanceof TileShulkerBox){
55 $this->facing = $shulker->getFacing();
56 }
57
58 return $this;
59 }
60
61 public function getMaxStackSize() : int{
62 return 1;
63 }
64
65 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
66 $this->facing = $face;
67
68 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
69 }
70
71 private function addDataFromTile(TileShulkerBox $tile, Item $item) : void{
72 $shulkerNBT = $tile->getCleanedNBT();
73 if($shulkerNBT !== null){
74 $item->setNamedTag($shulkerNBT);
75 }
76 if($tile->hasName()){
77 $item->setCustomName($tile->getName());
78 }
79 }
80
81 public function getDropsForCompatibleTool(Item $item) : array{
82 $drop = $this->asItem();
83 if(($tile = $this->position->getWorld()->getTile($this->position)) instanceof TileShulkerBox){
84 $this->addDataFromTile($tile, $drop);
85 }
86 return [$drop];
87 }
88
89 public function getPickedItem(bool $addUserData = false) : Item{
90 $result = parent::getPickedItem($addUserData);
91 if($addUserData && ($tile = $this->position->getWorld()->getTile($this->position)) instanceof TileShulkerBox){
92 $this->addDataFromTile($tile, $result);
93 }
94 return $result;
95 }
96
97 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
98 if($player instanceof Player){
99
100 $shulker = $this->position->getWorld()->getTile($this->position);
101 if($shulker instanceof TileShulkerBox){
102 if(
103 $this->getSide($this->facing)->isSolid() ||
104 !$shulker->canOpenWith($item->getCustomName())
105 ){
106 return true;
107 }
108
109 $player->setCurrentWindow($shulker->getInventory());
110 }
111 }
112
113 return true;
114 }
115
116 public function getSupportType(int $facing) : SupportType{
117 return SupportType::NONE;
118 }
119}
getDropsForCompatibleTool(Item $item)
describeBlockOnlyState(RuntimeDataDescriber $w)
getPickedItem(bool $addUserData=false)
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
setNamedTag(CompoundTag $tag)
Definition Item.php:266