From f64ef50ce3c97bf0b6b4463eee387b502c0fc354 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 19 Jul 2021 18:08:13 +0100 Subject: [PATCH] ShulkerBox: fixed incorrect block-picking behaviour --- src/block/ShulkerBox.php | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/block/ShulkerBox.php b/src/block/ShulkerBox.php index 5ad7f21fb..13b397753 100644 --- a/src/block/ShulkerBox.php +++ b/src/block/ShulkerBox.php @@ -59,19 +59,30 @@ class ShulkerBox extends Opaque{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function asItem() : Item{ - $item = parent::asItem(); - $shulker = $this->pos->getWorld()->getTile($this->pos); - if($shulker instanceof TileShulkerBox){ - $shulkerNBT = $shulker->getCleanedNBT(); - if($shulkerNBT !== null){ - $item->setNamedTag($shulkerNBT); - } - if($shulker->hasName()){ - $item->setCustomName($shulker->getName()); - } + private function addDataFromTile(TileShulkerBox $tile, Item $item) : void{ + $shulkerNBT = $tile->getCleanedNBT(); + if($shulkerNBT !== null){ + $item->setNamedTag($shulkerNBT); } - return $item; + if($tile->hasName()){ + $item->setCustomName($tile->getName()); + } + } + + public function getDropsForCompatibleTool(Item $item) : array{ + $drop = $this->asItem(); + if(($tile = $this->pos->getWorld()->getTile($this->pos)) instanceof TileShulkerBox){ + $this->addDataFromTile($tile, $drop); + } + return [$drop]; + } + + public function getPickedItem(bool $addUserData = false) : Item{ + $result = parent::getPickedItem($addUserData); + if($addUserData && ($tile = $this->pos->getWorld()->getTile($this->pos)) instanceof TileShulkerBox){ + $this->addDataFromTile($tile, $result); + } + return $result; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{