[TUTORIAL] How to get/set VANILLA NBT data for entities

Started by RedWirePlatinum on

Topic category: User side tutorials

Last seen on 05:43, 18. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[TUTORIAL] How to get/set VANILLA NBT data for entities
Wed, 10/18/2023 - 07:03 (edited)

How to get NBT data:
For this example, we're going to get the NBT data of the target/event entity. With a custom code snippet, put this inside:
CompoundTag nbtdata = entity.saveWithoutId(new CompoundTag());

(If getting data from target entity, source entity or immediate source entity, make sure it is shown under "required dependencies")
To get the value of "HurtTime", use getShort since its a short-type number

nbtdata.getShort("HurtTime")

How to set NBT data:
To set the value of something (such as HurtTime), use this:
nbtdata.putShort("HurtTime", 0);

and then load the new nbtdata onto the entity:
entity.load(nbtdata);


If you want to get a list of values (such as ForgeData) within the nbtdata, you can use the following:
CompoundTag forgedata = nbtdata.get("ForgeData")

Edited by RedWirePlatinum on Wed, 10/18/2023 - 07:03
Last seen on 05:43, 18. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay so I currently don't…
Wed, 10/18/2023 - 07:41

Okay so I currently don't actually know how to get a list of something within the nbt data, but i will try to figure it out.

Last seen on 00:43, 20. Jul 2024
Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
hey this is cool but when…
Thu, 01/04/2024 - 00:15

hey this is cool but when reading it

is there anyway to save the data to an variable or an array or no?

Last seen on 16:48, 21. Apr 2024
Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Any updates on this? I need…
Thu, 01/04/2024 - 02:55

Any updates on this? I need to figure out how to get the location data from a lodestone.

Last seen on 00:43, 20. Jul 2024
Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
leo the xyz is part of the…
Thu, 01/04/2024 - 04:14

leo the xyz is part of the cords not the block

+

a lodestone isn't an entity last i check

Last seen on 16:48, 21. Apr 2024
Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I should have specified, a…
Thu, 01/04/2024 - 12:16

I should have specified, a lodestone compass

Last seen on 00:43, 20. Jul 2024
Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
yea leo you can use defult…
Fri, 01/05/2024 - 00:04

yea leo you can use defult NBT stuff to grab it

+ an item in a inv isn't an entity.

Last seen on 00:43, 20. Jul 2024
Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
also the NBT value name is …
Fri, 01/05/2024 - 00:16

also the NBT value name is "LodestonePos" it contain inside the X, Y and Z cords

Last seen on 14:56, 24. Jul 2024
Joined Jan 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
what needs to be done to get…
Wed, 03/06/2024 - 19:03

what needs to be done to get the tag inside set compound tag(CurrentIdentity)? where exactly should I insert CompoundTag forgedata = nbtdata.get("ForgeData")?

code

Last seen on 20:21, 9. May 2024
Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I need to change the …
Sat, 03/23/2024 - 08:44

I need to change the "friction_modifier" nbt. I don't know what exact type is it or how to write the exact code snippets. anyone to help?

 

Last seen on 20:21, 9. May 2024
Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
What do I put as "entity"?
Sat, 03/23/2024 - 09:11

What do I put as "entity"?

Last seen on 00:59, 22. Jul 2024
Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Unrelated but certified W…
Mon, 07/22/2024 - 00:55

Unrelated but certified W profile picture