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

Started by RedWirePlatinum on

Topic category: User side tutorials

Active 9 hours ago
Joined May 2022
Points:
693

User statistics:

  • Modifications: 1
  • Forum topics: 43
  • Wiki pages: 0
  • MCreator plugins: 2
  • Comments: 138
[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
Active 9 hours ago
Joined May 2022
Points:
693

User statistics:

  • Modifications: 1
  • Forum topics: 43
  • Wiki pages: 0
  • MCreator plugins: 2
  • Comments: 138
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.

Active 4 days ago
Joined Mar 2023
Points:
179

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 8
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?

Active 10 months ago
Joined Nov 2020
Points:
568

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 7
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.

Active 4 days ago
Joined Mar 2023
Points:
179

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 8
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

Active 10 months ago
Joined Nov 2020
Points:
568

User statistics:

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

I should have specified, a lodestone compass

Active 4 days ago
Joined Mar 2023
Points:
179

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 8
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.

Active 4 days ago
Joined Mar 2023
Points:
179

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 8
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

Active 19 hours ago
Joined Jan 2024
Points:
147

User statistics:

  • Modifications: 1
  • Forum topics: 2
  • Wiki pages: 0
  • MCreator plugins: 1
  • Comments: 59
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

Active 2 months ago
Joined Jan 2023
Points:
289

User statistics:

  • Modifications: 0
  • Forum topics: 11
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 68
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?

 

Active 2 months ago
Joined Jan 2023
Points:
289

User statistics:

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

What do I put as "entity"?

Active 5 months ago
Joined Oct 2023
Points:
99

User statistics:

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

Unrelated but certified W profile picture

Active 7 months ago
Joined Jul 2024
Points:
32

User statistics:

  • Modifications: 0
  • Forum topics: 0
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 1
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.