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