Stop Baby Zombies Example

Oct 3, 2020
Stop Baby Zombies Example
  • This is an example of modify a creature on spawn.
    In this case if a Zombie is spawned, you can either cancel it if its a Baby or Change it to an adult.
    To make this code have the baby's grow up, you need to remove the setCancelled call.
    Both are shown here as an example of possibilities.

    Code (Text):

    //when a creature spawns...
    @EventHandler(priority = EventPriority.LOWEST)
    public void onEntitySpawn(CreatureSpawnEvent event)
    {
          if( event.getEntity().getType() == ZOMBIE )
           {
                Zombie z750 = (Zombie)event.getEntity();

                //Cancel Baby zombies
                if(z750.isBaby())
                        event.setCancelled(true);

               //OR make them grow up.
               if(z750.isBaby())
                       z750.setBaby(false);
         
            }
    }
     
  • Loading...
  • Loading...