My entity procedure crashes the game

Section

If your procedure crashes the game when the procedure is called in some or all cases, you are probably using one of these procedure blocks (there are other blocks too, the common thing with these blocks is they have a special NULL marking):

Minecraft entity null

These blocks can return an empty value (null), as the entity will not always have an owner, be attacking, or riding another entity.

The cause

If you use such block in a procedure with any action, for example like this (just example, any use without a check shown in the next section is problematic):

Minecraft entity procedure example

In case the "Event/target entity" will not be riding any entity, you will be setting the health of an entity that does not exist to 0 in this case, and this will inevitably lead to a crash.

The solution

Whenever you use such a block, you need to assure the entity you are looking for exists (is not NULL). To do this, you will need to check if your entity is one of the types you expect. The corrected procedure from the example above in case we want the procedure to run for any living entity type would be:

Minecraft entity procedure block proper use for null

Now, we check if the entity "Event/target entity" is riding is of (sub)type EntityLiving (all animals, mobs, ...). The entity that is NULL is not a living entity, so in such case, this procedure will not run, and we will not be setting the health of a non-existent entity to 0 and the game will run happily.



Donate to MCreator

By donating to developers you can speed up development, as with more resources, we can dedicate more time to MCreator. It is a free project made by developers working on it in their free time.