private void spawnMob() { // TODO Check how many mobs are in the local area and don't spawn if > configurable amount @SuppressWarnings("unchecked") Iterator<EntityEggInfo> iterator = EntityList.entityEggs.values().iterator(); List<Integer> ids = new ArrayList<Integer>(); while (iterator.hasNext()) { EntityEggInfo entityegginfo = iterator.next(); ids.add(entityegginfo.spawnedID); } // shuffle and pick from IDs Collections.shuffle(ids); int id = ids.get(0); Entity entity = null; entity = EntityList.createEntityByID(id, worldObj); if (entity != null && entity instanceof EntityLivingBase) { EntityLiving entityliving = (EntityLiving) entity; entity.setLocationAndAngles( xCoord + 2 + MathHelper.randomDoubleInRange(0, xLength - 3), yCoord + 1.0, zCoord + 2 + MathHelper.randomDoubleInRange(0, zLength - 3), net.minecraft.util.MathHelper.wrapAngleTo180_float(worldObj.rand.nextFloat() * 360.0f), 0.0f); worldObj.spawnEntityInWorld(entity); entityliving.playLivingSound(); } }
@SuppressWarnings("unchecked") private void pop() { List<EntityLivingBase> ents = worldObj.getEntitiesWithinAABB( EntityLivingBase.class, AxisAlignedBB.getBoundingBox( xCoord + 1.0, yCoord + 1.0, zCoord + 1.0, xCoord + xLength - 1, yCoord + 3.0, zCoord + zLength - 1)); for (EntityLivingBase ent : ents) { if (ent instanceof EntityPlayer) { EntityPlayerMP player = (EntityPlayerMP) ent; if (!player.capabilities.isCreativeMode) { player.playerNetServerHandler.sendPacket( new S12PacketEntityVelocity( player.getEntityId(), 0.0, MathHelper.randomDoubleInRange(0.5, 2), 0.0)); } } else { if (!ent.isDead) { ent.addVelocity(0.0, MathHelper.randomDoubleInRange(0.5, 2), 0); } } } }
private void spawnLightning() { int ran = MathHelper.randomIntInRange(1, 5); for (int i = 0; i < ran; i++) { worldObj.addWeatherEffect( new EntityLightningBolt( worldObj, xCoord + 2 + MathHelper.randomDoubleInRange(0, xLength - 3), yCoord + 1.0, zCoord + 2 + MathHelper.randomDoubleInRange(0, zLength - 3))); } }
@SuppressWarnings("unchecked") private void potion() { List<EntityLivingBase> ents = worldObj.getEntitiesWithinAABB( EntityLivingBase.class, AxisAlignedBB.getBoundingBox( xCoord + 1.0, yCoord + 1.0, zCoord + 1.0, xCoord + xLength - 1, yCoord + 3.0, zCoord + zLength - 1)); if (ents != null && ents.size() > 0) { Potion potion = null; // Try and find a potion, 15 times max for (int i = 0; i < 15; i++) { potion = Potion.potionTypes[worldObj.rand.nextInt(Potion.potionTypes.length)]; if (potion != null) break; } if (potion == null) return; EntityLivingBase ent = ents.get(worldObj.rand.nextInt(ents.size())); ent.addPotionEffect( new PotionEffect(potion.id, MathHelper.randomIntInRange(3, 10), 1, false)); } }
private void spawnItem() { // TODO check how many EntityItem's are in local are and don't spawn if > configurable amount /*OLD METHOD - Spawns any possible item (including ones we don't want such as blocks of portal / non meta items Object[] list = GameData.getItemRegistry().getKeys().toArray(); int rand = worldObj.rand.nextInt(list.length); Item item = (Item)GameData.getItemRegistry().getObject(list[rand]); ItemStack newStack = new ItemStack(item); worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord + 2 + MathHelper.randomDoubleInRange(0, xLength - 3), yCoord + 1.0, zCoord + 2 + MathHelper.randomDoubleInRange(0, zLength - 3), newStack));*/ ItemStack oneItem = ChestGenHooks.getOneItem(ChestGenHooks.DUNGEON_CHEST, worldObj.rand); worldObj.spawnEntityInWorld( new EntityItem( worldObj, xCoord + 2 + MathHelper.randomDoubleInRange(0, xLength - 3), yCoord + 1.0, zCoord + 2 + MathHelper.randomDoubleInRange(0, zLength - 3), oneItem)); }
@Override public void updateEntity() { super.updateEntity(); if (isMaster) { count++; if (count >= delay) { act(); // Reset count = 0; delay = MathHelper.randomIntInRange(ACTIONDELAY_MIN, ACTIONDELAY_MAX); } } }