Started by
kreatorKen
on
Topic category: User side tutorials
Here is a method to effectively add/declare NBT variables to mob entities that works, especially if you are not going to let them naturally spawn.
- Make a new procedure with the trigger set to "When entity joins the world".
- Then add an If-then clause to test for a particular (custom) mob type you want to declare and initialize NBT variables to. i.e. "is [entitiy] subtype of..."
- Inside the Do clause, use as many "Set [entity] NBT to [NBTtag] to [value]" block(s) you want. This makes NBT variables that are localized and retained (as far as I can tell) to each spawned mob type, individually.
- For multiple mobs, just add another If-then statement (BUT do not nest them!) and add the appropriate NBT variables you want to have.
This means you can add properties via NBT tags specific to each spawned mob entity, as desired, and give them timers, levels, etc. For debugging/testing I added a "Send Chat to all Players" block to make sure its working; there is a small bug in which the trigger is called twice, but since you are only going to declare/initialize the variables, it doesn't hurt anything since they are just set twice to the same thing.
Comments and improvements are welcome.
Edited by kreatorKen on Tue, 08/25/2020 - 11:00
This "tutorial" should have been posted in the User Tutorials section.
Sorry. :( I was thinking that but I was not sure this was Help with Modding or a proper tutorial already. One solution is that I make a new topic and link to here in order to prevent duplications. Would that be a viable option? Another would be that ya'll can delete this topic and I will repost it from scratch in the tutorials section. Or, one of the seniors can change the topic for me. That is also fine.
The debug duplications are because the console is receiving two messages: 1 from the server (world) and one from the render client (player)
As you're in single player, both are sent to Your console
Cheers!
What I meant by that is thanks, this is very important to keep in mind!
Hum. Okay this idea was a bit dumb. Sorry. I thought that I tested everything properly, but when you exit and start the game again, it re-populates the world with the entities, so I end up re-initializing my variables - not smart.
Better is to place or call the procedure from "On initial entity spawn".