Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Last active May 13, 2020 15:23
Show Gist options
  • Save PJZ9n/75d8de45a8bfa3cd306bf850e4f4ffd7 to your computer and use it in GitHub Desktop.
Save PJZ9n/75d8de45a8bfa3cd306bf850e4f4ffd7 to your computer and use it in GitHub Desktop.
NBT
<?php
declare(strict_types=1);
/** @var \pocketmine\item\Item $item */
$namedtag = $item->getNamedTag();
//セットするタグ
$setTag = new \pocketmine\nbt\tag\CompoundTag("プラグイン名", [
new \pocketmine\nbt\tag\StringTag("キー1", "値aaaabbbb"),
]);
//セットする
$namedtag->setTag($setTag);
//アイテムからCompoundTagを取得
$getTag = $namedtag->getCompoundTag("プラグイン名");
//取得
$value = $getTag->getString("キー1", "存在しなかったときの値(任意)");
var_dump($value);//値aaaabbbb になるはず
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment