How can I spawn a baby zombie?

Discussion in 'Plugin Development' started by MrSnare, Nov 21, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    MrSnare

    I am trying to make a baby zombie spawn when a Pig Zombie is killed
    but i don't know how to set the entity to type baby.

    Here is my code so far

    Code:
        public void onZombieDeath(EntityDeathEvent ev){
            Entity baby = ev.getEntity();
            if(baby.getType().getName().equalsIgnoreCase("PigZombie")){
                baby = baby.getWorld().spawnEntity(baby.getLocation(), EntityType.ZOMBIE);
            }
           
        }
     
  2. Offline

    rmh4209

    You have to reference CraftBukkit in order to do this.

    Code:java
    1.  
    2. public static void makeBaby(LivingEntity e)
    3. {
    4. if (e instanceof Zombie)
    5. {
    6. CraftZombie z = (CraftZombie) e;
    7. if (!z.getHandle().isBaby())
    8. z.getHandle().setBaby(true);
    9. }
    10. }
    11.  
     
    gomeow likes this.
  3. Offline

    MrSnare

    Thank you. This worked perfectly
     
  4. Offline

    Malikk

    It would make more sense to check EntityType with the enum, rather than comparing the String names.

    Code:
    entity.getType() == EntityType.ZOMBIE
    
     
  5. Offline

    MrSnare

    Thanks. I was looking for a way to do this but i forgot how.

    Also do you know how to set the PigZombie drop to null? I dont want it dropping flesh,swords or anything else when it died
     
  6. Offline

    Malikk

    Probably listen to EntiyDeath, check if it's a PigZombie, and set the drops to null with the built in method.
     
  7. Offline

    MrSnare

    I don't think there is a built in method to setDrop
     
  8. Offline

    rmh4209

    You have to do "event.getDrops().clear()".
     
  9. Offline

    MrSnare

    Thanks again. I didn't know how to do that :)
     
Thread Status:
Not open for further replies.

Share This Page