Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to use namedtag

Comments in 'Plugin Development' started by minebuilder0110, Jan 20, 2016.

  1. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I know I have asked the community about this before, but I didn't quite understand it properly. (It is not your fault, it's just that my knowledge was very small at that time, and I didn't even know what to ask)
    PHP:
    Entity::createEntity("Snowball"$pos->getLevel()->getChunk($pos->>> 4$pos->>> 4), $nbt)->spawnTo($player);
    This is how I have spawned a snowball. I am not sure how to use namedtag on it, and calling it later on so I can verify that it was created by a certain plugin. *Cough* Guns *Cough*
  2. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    If you mean this ?
    PHP:
    $player->setNameTag("Hello !".$player->getName());
  3. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    No. -_- Also, why on player? I am clearly doing it on a snowball.
    PocketKiller and applqpak like this.
  4. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    I know but for example :D
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    He is talking about namedtag, a.k.a. Named Binary Tag, a.k.a. NBT.
    NBT is basically a structure of data about an object in various parts of the game, e.g. objects in a level, objects in an inventory, etc. NBT is used by Minecraft as the universal data saving format (except chunks).

    Therefore, you can store any data you like within an NBT.
    NBT data types include the 4 common integer types, strings, lists and maps. A list is like the java.util.List in Java, and map is like the java.util.Map<String, *> in Java. Using suitable data types and suitable keys in a map, you can store data for a certain object in a level, such as a tile or an entity.
  6. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    To be honest, I didn't even know what NBT really meant... I only knew that it was a way to store data and etc. :oops:
    So is it possible for you to help me out with this one?
    PHP:
    $nbt =new Compound("",["Pos" => new Enum("Pos",[new Double(""$frontPos->x),new Double(""$frontPos->1),new Double(""$frontPos->z)]),"Motion" => new Enum("Motion",[new Double(""$dir->x),new Double(""$dir->y),new Double(""$dir->z)]),"Rotation" => new Enum("Rotation",[new Float(""0),new Float(""0)])]);
    I am not really sure how to add a data in the snowball, and getting it back...
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Look at how Slapper stores commands.
    It is bad practice though. If the data are from a plugin, they should be saved on an independent compound field to avoid collision.
  8. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    It took me a very long time going though Slapper code and doing lots of Trial & Error, but it doesn't really work for me.
    PHP:
    $snowball->namedtag->bullet = new String("bullet""$type""$damage");
    So I guess I found out how to add a bit of data into an entity, but not really sure how get it back. For example, getting the string "bullet", or the "$type" it is currently storing.
  9. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    PHP:
    $snowball->namedtag["bullet"]
    is one way,
    PHP:
    $snowball->namedtag->bullet->getValue()
    is another way.
    Legoboy0215 likes this.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The String constructor only accepts two parameters.
    Legoboy0215 likes this.
  11. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    So... Slapper uses bad practice? How would you connect to Compound tags together?
    PHP:
    $nbt =new Compound(/*BLAH*/);
    Then what?
  12. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I read the source code, and it created lots of different compounds to store the command. He said that putting lots of info into a single compound is a bad practice.
    Okay, I am seriously sorry about asking similar questions over and over, but I just cannot understand. I know you are trying your best to explain this simple NBT thing to this idiot (that's me, just in case anyone misinterprets me). So I would try to make this the last question I will make here:
    What exactly goes in here?
    PHP:
     new String(/*Here*//*and here*/
    and how do you get the data back? (I tried to ask you this many times, but I didn't get the answer, or at least I didn't managed to get what you said there)

    I know I have already requested too much, but it would even better if you give me an example usage on these two.
    Last edited: Jan 24, 2016
  13. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    The first value is basically the "key" for it, like in an array.
    To get the data:
    minebuilder0110 likes this.
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why is it a bad practice to put lots of info into a single compound?
    Of course, the data would be more tidy if you put the info into nested compounds.
    However, in plugins, it is advisable to put data into a same big compound (but different nested compounds inside) to avoid collision. Same reason as why not to use global variables.
    PocketKiller and Legoboy0215 like this.

Share This Page

Advertisement