Replace one mob with another?

Discussion in 'Plugin Development' started by but2002, Mar 15, 2011.

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

    but2002

    Let's say that on the EntityPrimedEvent, I wanted to replace a creeper with a chicken.

    How would I go about this? I seem a bit confused.
     
  2. Offline

    Infernus

    I think best is to use onCreatureSpawn event, spawn a chicken at the location of the creeper and after that just cancel the event. Correct me if i'm wrong!
     
  3. Offline

    but2002

    Well I was thinking something more along the lines of "Creeper is about to blow!!!" And right as it blows up, instead of doing world damage, a chicken spawns. For humor. :}

    E: Plus, I don't even know how to spawn an entity, much less spawn one at the location of another.
     
  4. Offline

    Infernus

    Good idea, but that would be on explode event or so, also, it will still damage players somehow even if you cancel the event.. But that's a really creative idea.
     
  5. Offline

    but2002

    Hence "ExplosionPrimedEvent" I'm already killing off creepers when that event fires, and that not only prevents them from "exploding" put it prevents players from getting damaged.

    Code:
      public void onExplosionPrimed(ExplosionPrimedEvent event)
           {
                   if (event.getEntity() != null)
                   {
                       if (event.getEntity() instanceof Creeper)
                       {
                           event.getEntity().remove();
                           event.setCancelled(true);
                           return;
                       }
    
                       if (event.getEntity() instanceof Fireball)
                       {
                           event.getEntity().remove();
                           event.setCancelled(true);
                           return;
                       }
    
                   }
                   return;
           }
    I just wanna know how I could replace the entity with a chicken after I remove it.
     
  6. Offline

    Edward Hand

    Code:
    theWorld.spawnCreature(event.getEntity().getLocation(),CreatureType.CHICKEN)
     
  7. Offline

    but2002

    Thank you so much. I got it working! <3
     
Thread Status:
Not open for further replies.

Share This Page