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

Solved Add NBT tags to TnT entity

Discussion in 'Development' started by kriskotooBG, Mar 17, 2020.

  1. kriskotooBG

    kriskotooBG Spider Jockey

    Messages:
    46
    GitHub:
    kriskotoobg
    Is adding a custom nbt string tag to an ignited tnt entity possible?

    I need the tnt block to do something special when it explodes, adding an nbt tag, and then checking for that nbt tag when it explodes seems like the best solution...

    I want to be able to add that nbt tag in an EntitySpawn event handler...
    If it is possible, link me the methods required to do so. :)

    (be as technical as you'd like.)


    Thanks in advance!
     
    Last edited: Mar 18, 2020
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP:
    /** @var CompoundTag $nbt */
    $nbt PrimedTNT->namedtag;
     
  3. kriskotooBG

    kriskotooBG Spider Jockey

    Messages:
    46
    GitHub:
    kriskotoobg
    What will that accomplish exactly? get the default NBT of a tnt entity?
    Issue is: i need to do this in the EntitySpawn event, how can i get the entity from that event?
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP:
    $entity $event->getEntity();
     
  5. kriskotooBG

    kriskotooBG Spider Jockey

    Messages:
    46
    GitHub:
    kriskotoobg
    Ok that will give me the NBT... but how do i add a new tag to it? I've never worked with NBT and don't exactly know how it works.... Thanks for the help though!
     
  6. kriskotooBG

    kriskotooBG Spider Jockey

    Messages:
    46
    GitHub:
    kriskotoobg
    Ok, i think i got it.. I looked trough pockemine's NBT classes, and i think
    PHP:
    $event->getEntity()->namedtag->setTag(new StringTag("helloworldtag""Hello World Value"));
    should give it that tag, i cannot figure out how to get its value though...

    //EDIT:

    I figured it out...
    its getTag()
    Thanks for the help! :)
     
    Last edited: Mar 19, 2020
  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.