Solved Entity NBT Tags

Discussion in 'Plugin Help/Development/Requests' started by 2008Choco, May 1, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    2008Choco

    I plan on making a plugin that essentially revolves around editing entity NBT data. I thought to myself, "Oh this will be super easy!", until I realized, "Oh wait, I don't know how to edit an entity's NBT tags". Oops.

    So basically, I want to be able to do something like the entitydata command where you can select an entity (I know how to do that part :p), and change an NBT tag that was specified. For example, turn an armour stand invisible by changing the "Invisible:0" tag to "Invisible:1".

    I don't know if this is an easy task, or a hard task, but anything helps :)
     
  2. Offline

    2008Choco

    I'm going to just innocently bump this to the top of the list <3 Thank you
     
  3. Offline

    2008Choco

    I went to bump this, and realized I did it at the exact same time as yesterday afternoon (Totally not 2 minutes late)
     
  4. Offline

    2008Choco

    Still looking for answers on this if it's possible. This is pretty important for the plugin I am currently working on
     
  5. Editing an entity's NBT is done through a DataWatcher field named datawatcher :)P) found in net.minecraft.server.<version>.Entity, to access an entity's NMS version you can use ((CraftEntity)<entity).getHandle(), and using reflect you can access the datawatcher, I could explore NMS a bit and give you a list of values later for the datawatcher so you can use that to modify it.
     
    2008Choco likes this.
  6. Offline

    2008Choco

    @megamichiel
    If you have time available to do that, it would be very very very much appreciated. I won't force you to do it, but I would love if you could to help me understand a bit more. I think I understand what you're trying to say, but a starting point might help. Thank you for the response :)
     
  7. @2008Choco
    The datawatcher holds all NBT values for the entity, like the entity's custom name etc., by invoking the method DataWatcher#watch(<position>, <object>) you can modify those things, here's a list of what the positions resemble and what kind of field they are:

    0: Holds a couple of things: Sneaking, Sprinting and invisibility
    1: Air ticks (short value), can be cast from a number using (short) <number>
    2: Custom name (String value)
    3: Custom name visible (byte value), byte 1 is true, byte 0 is false
    4: Boolean byte value(byte 1 or 0), if set to true the entity doesn't make any sounds
    5: Nothing, apperantly
    6: Entity health (Float value)
    7: Integer value: Active potion effects, pretty complicated, calculated by the static method net.minecraft.server.<version>.PotionBrewer#a(Collection<MobEffect>);
    8: Boolean byte value(byte 1 or 0), tells if all active potion effects are ambient(not provided by a beacon), I'm not sure where this is used for.
    9: Couldn't find
    10: On player: displayed skin parts, on armor stand: settings, on item: the itemstack, on wither skull: boolean byte, true if charged
    11: Armor stand's head position, in Vector3f which can be found in the nms package
    12: byte value -> If the entity is a zombie, it can be set to true (byte 1) or false (byte 0). If the entity is an animal or a villager, it's its age. It's max is byte 1 and min -1, if it's -1 it's a baby.
    13: Boolean byte value(byte 1 or 0), if set to true and the entity is a zombie, it becomes a villager zombie, if it's a skeleton it becomes a wither skeleton.
    16: Boolean byte value(byte 1 or 0), specificly for bat, if set to true the bat will be shown as flying, if 0 sitting, other mobs also have something with it but those are more complicated to fully explain
    17: Boolean byte value, sets creeper powered or not
    18: Boolean byte value, sets creeper ignited or enderman angry

    There's a lot more on each separate entity, but some of them, like 0, are hard to explain or they have the method within the entity's class so you can just use that.
     
    2008Choco likes this.
  8. Offline

    2008Choco

    @megamichiel Absolutely fantastic <3 Thank you so much. This helps a lot. I'll be sure to work with this later tonight.

    I appreciate it :)
     
Thread Status:
Not open for further replies.

Share This Page