public void setAgeProps(Ageable a, ISpawnableEntity data) { if (data.getAge(a) == -2) { a.setBaby(); } else if (data.getAge(a) == -1) { a.setAdult(); } else { a.setAge(data.getAge(a)); } }
public Skeleton makeJockey(Spider spider, ISpawnableEntity data) { spider.setPassenger(null); Location spiderLoc = spider.getLocation(); LivingEntity skele = (LivingEntity) spiderLoc.getWorld().spawn(spiderLoc, EntityType.SKELETON.getEntityClass()); assignMobProps(skele, data); setInventory(skele, data.getInventory()); spider.setPassenger(skele); spawner.addSecondaryMob(skele.getUniqueId(), spider.getUniqueId()); return (Skeleton) skele; }
@SuppressWarnings("deprecation") public void assignMobProps(Entity baseEntity, ISpawnableEntity data) { // This needs to be before everything else! if (data.getRider() != null) { addRider(baseEntity, data.getRider()); } Vector v1 = data.getVelocity(baseEntity); Vector v2 = data.getVelocity2(baseEntity); if (v2.getX() == 0 && v2.getY() == 0 && v2.getZ() == 0) { baseEntity.setVelocity(data.getVelocity(baseEntity).clone()); } else { Vector v3 = randomVector(v1, v2); baseEntity.setVelocity(v3.clone()); } baseEntity.setFireTicks(data.getFireTicks(baseEntity)); if (baseEntity instanceof LivingEntity) { LivingEntity entity = (LivingEntity) baseEntity; setBasicProps(entity, data); if (data.showCustomName()) { setCustomName(entity, data); } if (entity instanceof Ageable) { Ageable a = (Ageable) entity; setAgeProps(a, data); } if (entity instanceof Animals) { Animals animal = (Animals) entity; // Setting animal specific properties if (animal instanceof Pig) { Pig p = (Pig) animal; p.setSaddle(data.isSaddled()); } else if (animal instanceof Sheep) { Sheep s = (Sheep) animal; DyeColor color = DyeColor.valueOf(data.getColor()); s.setColor(color); } else if (animal instanceof Wolf) { Wolf w = (Wolf) animal; w.setAngry(data.isAngry()); w.setTamed(data.isTamed()); if (data.isTamed()) { ArrayList<Player> nearPlayers = getNearbyPlayers(w.getLocation(), 16); int index = (int) Math.round(Math.rint(nearPlayers.size() - 1)); if (nearPlayers != null) { w.setOwner(nearPlayers.get(index)); } w.setSitting(data.isSitting()); } } else if (animal instanceof Ocelot) { Ocelot o = (Ocelot) animal; o.setTamed(data.isTamed()); if (data.isTamed()) { Ocelot.Type catType = Ocelot.Type.valueOf(data.getCatType()); o.setCatType(catType); ArrayList<Player> nearPlayers = getNearbyPlayers(o.getLocation(), 16); int index = (int) Math.round(Math.rint(nearPlayers.size() - 1)); if (nearPlayers != null) { o.setOwner(nearPlayers.get(index)); } o.setSitting(data.isSitting()); } } } else if (entity instanceof Villager) { Villager v = (Villager) entity; v.setAge(data.getAge(baseEntity)); v.setProfession(data.getProfession()); } else if (entity instanceof Monster) { Monster monster = (Monster) entity; // Setting monster specific properties. if (monster instanceof Enderman) { Enderman e = (Enderman) monster; e.setCarriedMaterial(data.getEndermanBlock()); } else if (monster instanceof Creeper) { Creeper c = (Creeper) monster; c.setPowered(data.isCharged()); } else if (monster instanceof PigZombie) { PigZombie p = (PigZombie) monster; if (data.isAngry()) { p.setAngry(true); } p.setBaby((data.getAge(baseEntity) < -1) ? true : false); } else if (monster instanceof Spider) { Spider s = (Spider) monster; if (data.isJockey()) { makeJockey(s, data); } } else if (monster instanceof Zombie) { Zombie z = (Zombie) monster; boolean isVillager = false; if (data.hasProp("zombie")) { isVillager = (Boolean) (data.getProp("zombie")); } z.setBaby((data.getAge(baseEntity) < -1) ? true : false); z.setVillager(isVillager); } else if (monster instanceof Skeleton) { Skeleton sk = (Skeleton) monster; SkeletonType skType = SkeletonType.NORMAL; if (data.hasProp("wither")) { skType = ((Boolean) (data.getProp("wither")) == true) ? SkeletonType.WITHER : SkeletonType.NORMAL; } sk.setSkeletonType(skType); } } else if (entity instanceof Golem) { Golem golem = (Golem) entity; if (golem instanceof IronGolem) { IronGolem i = (IronGolem) golem; if (data.isAngry()) { ArrayList<Player> nearPlayers = getNearbyPlayers(i.getLocation(), 16); int index = (int) Math.round(Math.rint(nearPlayers.size() - 1)); if (nearPlayers != null) { i.setPlayerCreated(false); i.damage(0, nearPlayers.get(index)); i.setTarget(nearPlayers.get(index)); } } } // Some are not classified as animals or monsters } else if (entity instanceof Slime) { Slime s = (Slime) entity; s.setSize(data.getSlimeSize()); } else if (entity instanceof MagmaCube) { MagmaCube m = (MagmaCube) entity; m.setSize(data.getSlimeSize()); } } else if (baseEntity instanceof Projectile) { Projectile pro = (Projectile) baseEntity; // Eventually add explosive arrows and such :D if (pro instanceof Fireball) { Fireball f = (Fireball) pro; setExplosiveProps(f, data); f.setVelocity(new Vector(0, 0, 0)); f.setDirection(data.getVelocity(baseEntity)); } else if (pro instanceof SmallFireball) { SmallFireball f = (SmallFireball) pro; setExplosiveProps(f, data); f.setVelocity(new Vector(0, 0, 0)); f.setDirection(data.getVelocity(baseEntity)); } } else if (baseEntity instanceof Explosive) { Explosive ex = (Explosive) baseEntity; if (ex instanceof TNTPrimed) { TNTPrimed tnt = (TNTPrimed) ex; setExplosiveProps(tnt, data); tnt.setFuseTicks(data.getFuseTicks(baseEntity)); } } else if (baseEntity instanceof Firework) { Firework f = (Firework) baseEntity; ItemMeta meta = data.getItemType().getItemMeta(); if (meta != null) { if (meta instanceof FireworkMeta) { FireworkMeta fMeta = (FireworkMeta) meta; if (fMeta != null) { f.setFireworkMeta(fMeta); } } } } else if (baseEntity instanceof Minecart) { Minecart m = (Minecart) baseEntity; if (data.hasProp("minecartSpeed")) { m.setMaxSpeed((Double) data.getProp("minecartSpeed")); } } else if (baseEntity instanceof ExperienceOrb) { ExperienceOrb o = (ExperienceOrb) baseEntity; o.setExperience(data.getDroppedExp(baseEntity)); } setNBT(baseEntity, data); }
public void setExplosiveProps(Explosive e, ISpawnableEntity data) { e.setYield(data.getYield(e)); e.setIsIncendiary(data.isIncendiary()); }
public void setBasicProps(LivingEntity entity, ISpawnableEntity data) { setInventory(entity, data.getInventory()); entity.setMaxHealth(data.getMaxHealth()); entity.setMaximumAir(data.getMaxAir()); entity.addPotionEffects(data.getEffectsBukkit()); // Health handling if (data.getHealth(entity) == -2) { entity.setHealth(1); } else if (data.getHealth(entity) == -1) { entity.setHealth(entity.getMaxHealth()); } else { if (data.getHealth(entity) > entity.getMaxHealth()) { entity.setMaxHealth(data.getHealth(entity)); entity.setHealth(data.getHealth(entity)); } else if (data.getHealth(entity) < 0) { entity.setHealth(0); } else { entity.setHealth(data.getHealth(entity)); } } // Air handling if (data.getAir(entity) == -2) { entity.setRemainingAir(0); } else if (data.getAir(entity) == -1) { entity.setRemainingAir(entity.getMaximumAir()); } else { entity.setRemainingAir(data.getAir(entity)); } }
public Location getSpawningLocation( ISpawnableEntity type, boolean reqsBlockBelow, boolean ignoreLight, float height, float width, float length) { // Can it spawn in liquids? boolean spawnInWater = true; // Actual location Location spawnLoc = spawner.getLoc(); // Amount of times tried int tries = 0; // As long as the mob has not been spawned, keep trying while (tries < 128) { tries++; // Getting a random location. if (!spawner.isUsingSpawnArea()) { spawnLoc = randomGenRad(); } else { spawnLoc = randomGenArea(); } // loc is the location of the spawner block // spawnLoc is the location being tested to spawn in if (!isEmpty(spawnLoc, spawnInWater)) { continue; } if (type.getType().equals(EntityType.SQUID) && !(spawnLoc.getBlock().getType().equals(Material.STATIONARY_WATER) || spawnLoc.getBlock().getType().equals(Material.WATER))) { continue; } if (!areaEmpty(spawnLoc, spawnInWater, height, width, length)) { continue; } // Block below if (reqsBlockBelow) { Location blockBelow = new Location( spawnLoc.getWorld(), spawnLoc.getX(), spawnLoc.getY() - 1, spawnLoc.getZ()); if (isEmpty(blockBelow, false)) { continue; } } // Light leveling if (!ignoreLight) { if (!((spawnLoc.getBlock().getLightLevel() <= spawner.getMaxLightLevel()) && (spawnLoc.getBlock().getLightLevel() >= spawner.getMinLightLevel()))) { continue; } } return spawnLoc; } return null; }