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

Solved String tag api 4.0.0

Discussion in 'Development' started by FresherGAMING, Feb 15, 2022.

  1. FresherGAMING

    FresherGAMING Spider Jockey

    Messages:
    42
    GitHub:
    FresherGAMING
    I'm kinda confused with string tag in api 4.0.0
    in api 3.0.0, I set the tag like this
    PHP:
    $item->setNamedTagEntry(new StringTag("Test""Test2"));
    And I check the tag like this
    PHP:
    if($item->getNamedTagEntry()->hasTag("Test") && $item->getNamedTagEntry()->getStringTag("Test") == "Test2"){

    }
    Now, how to set and get string tag like above in api 4.0.0 ?

    My try :
    PHP:
    //set tag
    $item->setNamedTag(new StringTag("Test""Test2"));

    //get tag
    if($item->getNamedTag()->hasNamedTag("Test") && $item->getNamedTag()->getString("Test") == "Test2"){
    }
     
    Last edited: Feb 15, 2022
  2. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    PHP:
    // setting nbt
    $item->getNamedTag()->setString('test''testnbt');

    // getting nbt
    $item->getNamedTag()->getTag('test'); // returns 'testnbt'
     
    FresherGAMING likes this.
  3. FresherGAMING

    FresherGAMING Spider Jockey

    Messages:
    42
    GitHub:
    FresherGAMING
    Thank you
     
    minijaham 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.