Topic category: User side tutorials
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")
I want to set a zombie's CanPickUpLoot data to be always true
Well, given my example... Instead of just grabbing a CompoundTag of all NBT data, writing to one, then applying it back to an entity using HurtTime for example, you can literally just do:
if (entity instanceof LivingEntity live) {
live.hurtTime = 0;
}
It's an incredibly easy-to-miss feature, but if you Select Window > Show workspace file browser (or select the tiny little arrows thats to the very leftmost of the screen, just above the "WORKSPACE" title), you can see the list of libraries that MCreator uses. Search for something like LivingEntity.java and you'll see everything that it does
Also, to answer TacoGamings question, this might differ in minecraft versions, but you should be able to just do the following:
if (entity instanceof Mob mob) {_mob.setCanPickUpLoot(true);}