Method to add NBT and initialize variables to entities in 2020.4

Started by kreatorKen on Mon, 08/24/2020 - 20:29

Topic category: User side tutorials

Last seen on 11:22, 5. Oct 2020
Joined Aug 2020
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Method to add NBT and initialize variables to entities in 2020.4
Tue, 08/25/2020 - 11:00 (edited)

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
Last seen on 14:58, 24. Oct 2020
Joined Jun 2015
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
This "tutorial" should have…
Tue, 08/25/2020 - 10:49

This "tutorial" should have been posted in the User Tutorials section.

Last seen on 11:22, 5. Oct 2020
Joined Aug 2020
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Sorry. :( I was thinking…
Tue, 08/25/2020 - 10:58

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.

Last seen on 21:01, 25. Sep 2020
Joined Jul 2017
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
The debug duplications are…
Thu, 08/27/2020 - 02:42

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

Last seen on 11:22, 5. Oct 2020
Joined Aug 2020
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Cheers!
Thu, 08/27/2020 - 09:10

Cheers!

Last seen on 11:22, 5. Oct 2020
Joined Aug 2020
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
What I meant by that is…
Thu, 08/27/2020 - 09:12

What I meant by that is thanks, this is very important to keep in mind!

Last seen on 11:22, 5. Oct 2020
Joined Aug 2020
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Hum. Okay this idea was a…
Sat, 08/29/2020 - 09:13

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