How to add procedures that triggers when specific vanilla mob dies/it's killed

Started by Distru121mods on

Topic category: User side tutorials

Last seen on 12:15, 20. Dec 2022
Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to add procedures that triggers when specific vanilla mob dies/it's killed
Sun, 03/17/2019 - 10:39 (edited)

In this tutorial you will learn how to add a procedure that triggers when a vanilla mob dies/it's killed. I'm not sure if this can be tested if the player killed the entity, or if the entity is damaged, etc...but I think that could be possible.

So, what you are gonna do is create a standard procedure, add what you like, and add to the procedure trigger ENTITY DIES. Then you click next and wait for Mcreator to compile.

Then you must go to the procedure's code (i suggest you to lock the code), and look for this line of code:

_____________________________________________________

    @SubscribeEvent
    public void onEntityDeath(LivingDeathEvent event) {
        if (event != null && event.getEntity() != null) {
            Entity entity = event.getEntity();
            int i = (int) entity.posX;
            int j = (int) entity.posY;
            int k = (int) entity.posZ;
            World world = entity.world;
            java.util.HashMap<String, Object> dependencies = new java.util.HashMap<>();
            dependencies.put("x", i);
            dependencies.put("y", j);
            dependencies.put("z", k);
            dependencies.put("world", world);
            dependencies.put("entity", entity);
            this.executeProcedure(dependencies);
        }
    } 

_____________________________________________________

Now it's all pretty simple: you are going to add the test for the entity that was killed. Like this:

 

Delete this part

_____________________________________________________

    @SubscribeEvent

    public void onEntityDeath(LivingDeathEvent event) {
        if (event != null && event.getEntity() != null) {
            Entity entity = event.getEntity();
            int i = (int) entity.posX;
            int j = (int) entity.posY;
            int k = (int) entity.posZ;
            World world = entity.world;
            java.util.HashMap<String, Object> dependencies = new java.util.HashMap<>();
            dependencies.put("x", i);
            dependencies.put("y", j);
            dependencies.put("z", k);
            dependencies.put("world", world);
            dependencies.put("entity", entity);
            this.executeProcedure(dependencies);
        }
    }

_____________________________________________________

 

And add this instead

_____________________________________________________

    @SubscribeEvent
    public void onEntityDeath(LivingDeathEvent event) {
        if (event != null && event.getEntity() instanceof VanillaEntityClass) {
            Entity entity = event.getEntity();
            int i = (int) entity.posX;
            int j = (int) entity.posY;
            int k = (int) entity.posZ;
            World world = entity.world;
            java.util.HashMap<String, Object> dependencies = new java.util.HashMap<>();
            dependencies.put("x", i);
            dependencies.put("y", j);
            dependencies.put("z", k);
            dependencies.put("world", world);
            dependencies.put("entity", entity);
            this.executeProcedure(dependencies);
        }
    }

_____________________________________________________

VanillaEntityClass is what you are going to change in order to get a test for a specific entity: EX if I want every zombie I kill to execute the procedure i'll put instanceof EntityZombie and so on(I remember you that the position the procedure will be executed is the actual location of the mob. This is perfect for adding custom drops to vanilla mobs, but unfortunately only for adding them. If you want to replace them you will have to make a code yourself).

 

Don't forget to import the entity that you are gonna use in the imports, else you will get an error!

 

 

So, this is all pretty simple, I can think that there are many possibilities for this for who doesn't know coding so well (I don't really know coding myself, I'm still improving)

 

If you have any questions, just ask in the comments. If you have any suggestions for coding newbies, write them in the comments.

Hope this was helpful!

 

 

Edited by Distru121mods on Sun, 03/17/2019 - 10:39
You can do this without…
Sun, 03/17/2019 - 12:02

You can do this without custom code. In the Logic operations section, there is entity of type procedure block. We will move it to entity section in 1.8.3.

Last seen on 12:15, 20. Dec 2022
Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
:(
Sun, 03/17/2019 - 14:26

:(