1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Trying to set Item Tag

Discussion in 'Plugin Help' started by Nemo404, Apr 29, 2020.

  1. Nemo404

    Nemo404 Spider Jockey

    Messages:
    39
    GitHub:
    chaostixzix
    Im Trying to make a tag
    PHP:
    $item Item::get(Item::REDSTONE);
    $item->setCustomName($this->plugin->prefix ' Test ' $player->getName());
    $item->setLore([
        
    TextFormat::GOLD TextFormat::BOLD 'Test'
    ]);
    /** @var CompoundTag $nbt */
    $nbt $item->getNamedTag() ?? new CompoundTag("", []);
    $nbt->bh = new StringTag("bh""1000");
    $item->setNamedTag($nbt);
    $player->dropItem($item);
    I got error cannot access dyanmic field bh
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
  3. Nemo404

    Nemo404 Spider Jockey

    Messages:
    39
    GitHub:
    chaostixzix
    I Got This Argument 1 passed to pocketmine\item\Item::setNamedTag() must be an instance of pocketmine\nbt\tag\CompoundTag,
    PHP:
    $item Item::get(Item::REDSTONE);
    $item->setCustomName($this->plugin->prefix ' B ');
    $item->setLore([
        
    TextFormat::GOLD TextFormat::BOLD 'B'
    ]);
    $item->setNamedTag(new StringTag("bh""1000"));
    $item->setNamedTag(new StringTag("B"'s'));
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    You can't override the item's compound tag with a string tag, however adding them to the existing CompoundTag will work:
    PHP:
    $item Item::get(Item::REDSTONE);
    $item->setCustomName($this->plugin->prefix ' B ');
    $item->setLore([
        
    TextFormat::GOLD TextFormat::BOLD 'B'
    ]);
    $item->setNamedTagEntry(new StringTag("bh""1000"));
    $item->setNamedTagEntry(new StringTag("B"'s'));
     
  5. Nemo404

    Nemo404 Spider Jockey

    Messages:
    39
    GitHub:
    chaostixzix
    Ok thanks :D
     
    HimbeersaftLP likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.