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

Sign with text

Discussion in 'Development' started by azk_, Mar 26, 2018.

  1. azk_

    azk_ Spider Jockey

    Messages:
    49
    Hello i have a simple question
    How can i give a player sign with text

    I already know this:
    give sho sign 16 {display:{Name:"§6§lPLACE ME!"},BlockEntityTag:{Text1:"CUSTOM TEXT",Text2:"----------------",Text3:"I can have",Text4:"default text!"}}

    But i want to do that with a plugin.
    sorry for bad england
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
    $nbt = new CompoundTag("BlockEntityTag", [
                new 
    ListTag("Text""Msg")
                ]);

              
    $sign ItemFactory::get(Item::SIGN01);
              
    $sign->setNamedTagEntry($nbt);

              
    $sender->getInventory()->addItem($sign);
    //Dont know if it work but try
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    For the custom name ("PLACE ME"), there's a direct API method:
    PHP:
    $item->setCustomName("PLACE ME!");
    For the Block Entity data, since the API methods involved may return null, you'll need to have a check for that.
    PHP:
    $tiledata $item->getCustomBlockData() ?? new CompoundTag();
    $display_tag $tiledata->getCompoundTag("display") ?? new CompoundTag("display");
    The rest is pretty straight-forward:
    PHP:
    $display_tag->setString("Text1""Line 1");
    $display_tag->setString("Text2""Line 2");
    $display_tag->setString("Text3""Line 3");
    $display_tag->setString("Text4""Line 4");

    $item->setCustomBlockData($tiledata);
     
  4. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    to edit the sign using gettile (set text when placeevent)
    PHP:
    $pos = new Vector3(XYZ); //coords
    $sign $level->getTile($pos);
     if(
    $sign instanceof Sign){// check whether sign
    $sign->setText("Text1""Text2""Text3""Text4");   //set text
    $sign->saveNBT(); //save the changes
    }
     
  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.