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

NBT

Comments in 'Plugin Development' started by Creeperface, Aug 12, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    please how and where should i use NBT and what is it? it stores some data? because i can use it when i create new ENtiity or new Tile.

    e.g.
    PHP:
    $nbt = new Compound;
    $nbt->NameTag = new String($args->getOptArg("name"" Untitled\nSlappableHuman"));
    $nbt->Pos = new Enum("Pos", [
    new 
    Double(0$pos->x),
    new 
    Double(1$pos->y),
    new 
    Double(2$pos->z),
    ]);
    $nbt->Motion = new Enum("Motion", [
    new 
    Double(0$args->getOptArg("speedx"0.0)),
    new 
    Double(1$args->getOptArg("speedy"0.0)),
    new 
    Double(2$args->getOptArg("speedz"0.0)),
    ]);
    $nbt->Rotation = new Enum("Rotation", [
    new 
    Float(0$pos->yaw),
    new 
    Float(1$pos->pitch)
    ]);
    $nbt->FallDistance = new Float("FallDistance"0.0);
    $nbt->Fire = new Short("Fire", (int) ($args->getOptArg("burntime"0) * 20));
    $nbt->Air = new Short("Air"0);
    $nbt->OnGround = new Byte("OnGround"1);
    $nbt->Invulnerable = new Byte("Invulnerable"1);
    $nbt->Health = new Short("Health", (int) ($args->getOptArg("health"10) * 2));
    $nbt->Inventory = new Enum("Inventory", [new Compound(false, [
    new 
    Short("id"0),
    new 
    Short("Damage"0),
    new 
    Byte("Count"0),
    new 
    Byte("Slot"9),
    new 
    Byte("TrueSlot"9)
    ])]);
    $nbt->SlapItData = new Compound("SlapItData", [
    new 
    Enum("OnSlapOperation"),
    new 
    Enum("RepeatingOperations"),
    new 
    Byte("Crouched"0),
    new 
    Byte("InAction"0)
    ]);
    what is $nbt->air, $nbt->health etc? i didnt find it in the docs.
    and what is ENUM?
    Last edited: Aug 12, 2015
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    ENUM is text.
  3. TigerHix
    Offline

    TigerHix Active Member

    Joined:
    May 11, 2015
    Posts:
    61
    Minecraft User:
    TigerHix
    Enum is simply a special named tag that has one key corresponds to multiple values, something like TAG_List on PC. Note that it is totally different from the "enum" class type in various OOP programming languages.

    For "Air", "Health", they are NBT names. Take a look at Minecraft Wiki.
  4. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    sure! :D i know thx
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No it isn't. String is text. You're wrong. Don't reply if you don't know that you're saying.

    NBT is originally a format used by MCPC for saving data, especially level data. This includes entity data. PocketMine uses an NBT tag class to contain all these data for entities.

    They aren't documented because they are part of the level format. You can find them from PocketMine source though.
  6. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    I think he meant Config::ENUM.
    Legoboy0215 likes this.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Ooooooo...
    Do not ever trust your teacher at school...
    jojoe77777 likes this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Config::ENUM is a key-less array (list). It isn't text either.

    ENUM is short for enumeration.
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Thanks! I hope you can be my IT teacher :) lol.
    hoyinm14mc and jojoe77777 like this.
  10. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    And what is compound?
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Something like an object in PHP/JavaScript, or a Map<String, Object> in Java (with the value class being anything).
    iksaku likes this.
  12. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    and when i set ItemTag
    PHP:
    $nbt= new Compound;
    $nbt->soulbound = new Byte(""1);
    $item->setCompoundTag($nbt);
    so how can i get it?
    e.g
    PHP:
    if($item->getNamedTag()->soulbound 0){}
    ?
  13. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    or
    PHP:
    if($item->getNamedTagEntry("soulbound") > 0){}
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    As I said, override the item class and read the values from the __construct $this context. If you don't know how to do it, learn PHP.
    iksaku likes this.
  15. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    But it shoul work with NBT too right?
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Not guaranteed. It is best practice to override it completely.
    iksaku and Creeperface like this.
  17. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Hm shoul i use redefines ?
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You should extend the item class, and create an entity from your class instead, like this:
    PHP:
    <?php
    use pocketmine\entity\Item;
    class 
    MyItem extends Item{
      private 
    $soulBound;
      protected function 
    initEntity(){
        
    parent::initEntity();
        
    $this->soulBound = isset($this->namedTag["SoulBound"]) ? $this->namedTag["SoulBound"] : SOUL_BOUND_DEFAULT_VALUE;
      }
      public function 
    saveNBT(){
        
    parent::saveNBT();
        
    $this->namedtag->SoulBound = new Byte("SoulBound"$this->soulBound);
      }
    }
    Also, instead of hooking to events, I recommend you to override functions inside the Item class (if available).

    Note that ($this->namedTag is a pocketmine\nbt\tag\Compound object) $this->namedTag->ValueKey returns a Tag object (one of the classes in the pocketmine\nbt\tag namespace) and $this->namedTag["ValueKey"] returns the value of the tag (unless it is another Compound or an Enum).
    Creeperface and iksaku like this.
  19. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Re-defines doesn't work... You need to "override"
    PEMapModder and Creeperface like this.
  20. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    wait i want to save soulbound value to items in inventory is it possible?

Share This Page

Advertisement