[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 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.

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?

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.

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

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

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.

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

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

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?

 

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"?

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

Joined Jul 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Is it possible to do this…
Sat, 07/27/2024 - 16:25

Is it possible to do this with Block Entities? I can't find an answer anywhere.