mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
Added handling for tile picking, added API for setting item lore
worked almost out of the box (some W10 equipment bugs though)
This commit is contained in:
parent
52f2596dc5
commit
3e76c3a6dd
@ -196,6 +196,7 @@ use pocketmine\plugin\Plugin;
|
|||||||
use pocketmine\resourcepacks\ResourcePack;
|
use pocketmine\resourcepacks\ResourcePack;
|
||||||
use pocketmine\tile\ItemFrame;
|
use pocketmine\tile\ItemFrame;
|
||||||
use pocketmine\tile\Spawnable;
|
use pocketmine\tile\Spawnable;
|
||||||
|
use pocketmine\tile\Tile;
|
||||||
use pocketmine\utils\TextFormat;
|
use pocketmine\utils\TextFormat;
|
||||||
use pocketmine\utils\UUID;
|
use pocketmine\utils\UUID;
|
||||||
|
|
||||||
@ -2388,7 +2389,19 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{
|
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{
|
public function handleUseItem(UseItemPacket $packet) : bool{
|
||||||
|
@ -660,6 +660,35 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
return $this;
|
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
|
* @param $name
|
||||||
* @return Tag|null
|
* @return Tag|null
|
||||||
|
@ -148,6 +148,17 @@ abstract class Tile extends Position{
|
|||||||
$this->namedtag->z = new IntTag("z", $this->z);
|
$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
|
* @return \pocketmine\block\Block
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user