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

Started by RedWirePlatinum on

Topic category: User side tutorials

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
Joined Apr 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I want to set a zombie's…
Sat, 01/03/2026 - 08:51

I want to set a zombie's CanPickUpLoot data to be always true