Started by
Bali
on
Topic category: Help with Minecraft modding (Java Edition)
I'm already able to pick mobs up and place them down with my new modded item, however when I name them with a nametag, and pick them up, their name is lost. I assume the same is true for their current health, altough I haven't tried that yet. So could somebody please tell me how I can make my item spawn a mob with the exact same data as the one i picked up?
you can probably create NBT tags for the item that represent health, name, etc., before you despawn the mob it should set the item NBT to the mob NBT, and before you empty the item you should set the mob NBT to the item NBT
Could you please send me an example? I've never used NBT procedure blocks before.
let's pretend you have a cup and you wanna put a ravager in it cuz funny
set a global trigger to when a player right clicks a mob
if the player is holding a cup and the mob is a ravager, it replaces the cup with a ravager cup, sets the ravager cup's nbt number tag, which is called "health", to the amount of health the ravager has, sets the ravager cup's nbt text tag, which is called "name", to the ravager's custom name, and then despawns the ravager
if the player right clicks the ground with a ravager cup, it spawns a ravager at that location, sets the ravager's actual health bar level to the number in the health tag of the ravager cup, sets the custom name to the custom name tag, and then replaces the ravager cup with a regular empty cup
some important things to know about nbt tags:
- they don't really have an initial value, they kind of just get a value when you set them
- they update regardless of ticks, which means if you tell the nbt variable to update after a certain number of ticks, it'll update instantly regardless of how long you set the time to be, if you want it to be delayed, use the tick update trigger