Stop Baby Zombies Example

Apr 12, 2016
Stop Baby Zombies Example
  • Example - Stopping Baby Zombies from Spawning

    A tutorial on stopping certain mobtypes from spawning (or replacing them)



    This is an example to modify a creature when it is about to spawn.

    In this case, if a zombie is spawned and it is a baby, you can either prevent it from being spawned or make the zombie an adult.

    In this case, we prevent the action. Directly below that we set the zombie as an adult. This is more shown as an example, and you should apply this concept to your invididual case.

    Code (Java):
    //called when a creature spawns.
    @EventHandler
    public void onCreatureSpawn(CreatureSpawnEvent event) {
        //check if the creature spawned is a zombie.
        if (event.getEntity().getType() == EntityType.ZOMBIE) {
            //create a variable to store the zombie.
            Zombie zombie = (Zombie) event.getEntity();

            //check if the zombie is a baby.
            if(zombie.isBaby()) {
                // don't spawn it.
                event.setCancelled(true);
                 // Or you could instead just restore the zombie's maturity with this line.
                zombie.setBaby(false);
            }

        }
    }
  • Loading...
  • Loading...