diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 371a7d787..1a32eeaca 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -196,6 +196,7 @@ use pocketmine\plugin\Plugin; use pocketmine\resourcepacks\ResourcePack; use pocketmine\tile\ItemFrame; use pocketmine\tile\Spawnable; +use pocketmine\tile\Tile; use pocketmine\utils\TextFormat; use pocketmine\utils\UUID; @@ -2388,7 +2389,19 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ - return false; //TODO + $tile = $this->getLevel()->getTile($this->temporalVector->setComponents($packet->tileX, $packet->tileY, $packet->tileZ)); + if($tile instanceof Tile){ //TODO: check if the held item matches the target tile + $nbt = $tile->getCleanedNBT(); + if($nbt instanceof CompoundTag){ + $item = $this->inventory->getItemInHand(); + $item->setCustomBlockData($nbt); + $item->setLore(["+(DATA)"]); + $this->inventory->setItemInHand($item); + } + + return true; + } + return false; } public function handleUseItem(UseItemPacket $packet) : bool{ diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 356466d68..7e793d55e 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -660,6 +660,35 @@ class Item implements ItemIds, \JsonSerializable{ return $this; } + public function getLore() : array{ + $tag = $this->getNamedTagEntry("display"); + if($tag instanceof CompoundTag and isset($tag->Lore) and $tag->Lore instanceof ListTag){ + $lines = []; + foreach($tag->Lore->getValue() as $line){ + $lines[] = $line->getValue(); + } + + return $lines; + } + + return []; + } + + public function setLore(array $lines){ + $tag = $this->getNamedTag(); + if(!isset($tag->display)){ + $tag->display = new CompoundTag("display", []); + } + $tag->display->Lore = new ListTag("Lore"); + $tag->display->Lore->setTagType(NBT::TAG_String); + $count = 0; + foreach($lines as $line){ + $tag->display->Lore[$count++] = new StringTag("", $line); + } + + $this->setNamedTag($tag); + } + /** * @param $name * @return Tag|null diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index 51c3ca9d8..6f81bbad3 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -148,6 +148,17 @@ abstract class Tile extends Position{ $this->namedtag->z = new IntTag("z", $this->z); } + public function getCleanedNBT(){ + $this->saveNBT(); + $tag = clone $this->namedtag; + unset($tag->x, $tag->y, $tag->z, $tag->id); + if($tag->getCount() > 0){ + return $tag; + }else{ + return null; + } + } + /** * @return \pocketmine\block\Block */