@Override public void onSpawn() { if (npc.getBukkitEntity() instanceof Ageable) { Ageable entity = (Ageable) npc.getBukkitEntity(); entity.setAge(age); entity.setAgeLock(locked); ageable = entity; } else ageable = null; }
public List<LivingEntity> spawn(Location location, Player player) { List<LivingEntity> entities = new ArrayList<LivingEntity>(this.num); World world = location.getWorld(); for (int num = 0; num < this.num; num++) { if (spread > 0) { int minX = location.getBlockX() - spread / 2; int minY = location.getBlockY() - spread / 2; int minZ = location.getBlockZ() - spread / 2; int maxX = location.getBlockX() + spread / 2; int maxY = location.getBlockY() + spread / 2; int maxZ = location.getBlockZ() + spread / 2; int tries = spread * 10; boolean found = false; while (tries-- > 0) { int x = minX + RecipeManager.random.nextInt(maxX - minX); int z = minZ + RecipeManager.random.nextInt(maxZ - minZ); int y = 0; for (y = maxY; y >= minY; y--) { if (!Material.getMaterial(world.getBlockTypeIdAt(x, y, z)).isSolid()) { found = true; break; } } if (found) { location.setX(x); location.setY(y); location.setZ(z); break; } } if (!found) { Messages.debug( "Couldn't find suitable location after " + (spread * 10) + " tries, using center."); } location.add(0.5, 0, 0.5); } LivingEntity ent = (LivingEntity) world.spawnEntity(location, type); entities.add(ent); if (!noEffect) { world.playEffect(location, Effect.MOBSPAWNER_FLAMES, 20); } if (name != null) { ent.setCustomName(name); ent.setCustomNameVisible(noHideName); } if (onFire > 0.0f) { ent.setFireTicks((int) Math.ceil(onFire * 20.0)); } if (pickup != null) { ent.setCanPickupItems(pickup); } if (pet && ent instanceof Tameable) { Tameable npc = (Tameable) ent; npc.setOwner(player); npc.setTamed(true); } if (ent instanceof Wolf) { Wolf npc = (Wolf) ent; if (pet) { if (noSit) { npc.setSitting(false); } if (color != null) { npc.setCollarColor(color); } } else if (angry) { npc.setAngry(true); } } if (ent instanceof Ocelot) { Ocelot npc = (Ocelot) ent; if (pet && noSit) { npc.setSitting(false); } if (cat != null) { npc.setCatType(cat); } } if (hp > 0) { ent.setHealth(hp); if (maxHp > 0) { ent.setMaxHealth(maxHp); } } if (ent instanceof Ageable) { Ageable npc = (Ageable) ent; if (baby) { npc.setBaby(); } if (ageLock) { npc.setAgeLock(true); } if (noBreed) { npc.setBreed(false); } } if (saddle && ent instanceof Pig) { Pig npc = (Pig) ent; npc.setSaddle(true); if (mount) { npc.setPassenger(player); } } if (ent instanceof Zombie) { Zombie npc = (Zombie) ent; if (baby) { npc.setBaby(true); } if (zombieVillager) { npc.setVillager(true); } } if (villager != null && ent instanceof Villager) { Villager npc = (Villager) ent; npc.setProfession(villager); } if (poweredCreeper && ent instanceof Creeper) { Creeper npc = (Creeper) ent; npc.setPowered(true); } if (playerIronGolem && ent instanceof IronGolem) { IronGolem npc = (IronGolem) ent; npc.setPlayerCreated(true); // TODO what exacly does this do ? } if (shearedSheep && ent instanceof Sheep) { Sheep npc = (Sheep) ent; npc.setSheared(true); } if (color != null && ent instanceof Colorable) { Colorable npc = (Colorable) ent; npc.setColor(color); } if (skeleton != null && ent instanceof Skeleton) { Skeleton npc = (Skeleton) ent; npc.setSkeletonType(skeleton); } if (target && ent instanceof Creature) { Creature npc = (Creature) ent; npc.setTarget(player); } if (pigAnger > 0 && ent instanceof PigZombie) { PigZombie npc = (PigZombie) ent; npc.setAnger(pigAnger); } if (hit) { ent.damage(0, player); ent.setVelocity(new Vector()); } if (!potions.isEmpty()) { for (PotionEffect effect : potions) { ent.addPotionEffect(effect, true); } } ent.setRemoveWhenFarAway(!noRemove); EntityEquipment eq = ent.getEquipment(); for (int i = 0; i < equip.length; i++) { ItemStack item = equip[i]; if (item == null) { continue; } switch (i) { case 0: eq.setHelmet(item); eq.setHelmetDropChance(drop[i]); break; case 1: eq.setChestplate(item); eq.setChestplateDropChance(drop[i]); break; case 2: eq.setLeggings(item); eq.setLeggingsDropChance(drop[i]); break; case 3: eq.setBoots(item); eq.setBootsDropChance(drop[i]); break; case 4: { if (ent instanceof Enderman) { Enderman npc = (Enderman) ent; npc.setCarriedMaterial(item.getData()); } else { eq.setItemInHand(item); eq.setItemInHandDropChance(drop[i]); } break; } } } } return entities; }
@Override public boolean toggle() { locked = !locked; if (isAgeable()) ageable.setAgeLock(locked); return locked; }