/** Returns whether or not the specified creature type can spawn at the specified location. */ public static boolean canCreatureTypeSpawnAtLocation( EnumCreatureType par0EnumCreatureType, World par1World, int par2, int par3, int par4) { if (par0EnumCreatureType.getCreatureMaterial() == Material.water) { return par1World.getBlockMaterial(par2, par3, par4).isLiquid() && !par1World.isBlockNormalCube(par2, par3 + 1, par4); } else { int i = par1World.getBlockId(par2, par3 - 1, par4); return Block.isNormalCube(i) && i != Block.bedrock.blockID && !par1World.isBlockNormalCube(par2, par3, par4) && !par1World.getBlockMaterial(par2, par3, par4).isLiquid() && !par1World.isBlockNormalCube(par2, par3 + 1, par4); } }
/** * adds all chunks within the spawn radius of the players to eligibleChunksForSpawning. pars: the * world, hostileCreatures, passiveCreatures. returns number of eligible chunks. */ public int findChunksForSpawning( WorldServer par1WorldServer, boolean par2, boolean par3, boolean par4) { if (!par2 && !par3) { return 0; } else { eligibleChunksForSpawning.clear(); int var3; int var6; for (var3 = 0; var3 < par1WorldServer.playerEntities.size(); ++var3) { EntityPlayer var4 = (EntityPlayer) par1WorldServer.playerEntities.get(var3); int var5 = MathHelper.floor_double(var4.posX / 16.0D); var6 = MathHelper.floor_double(var4.posZ / 16.0D); byte var7 = 8; for (int var8 = -var7; var8 <= var7; ++var8) { for (int var9 = -var7; var9 <= var7; ++var9) { boolean var10 = var8 == -var7 || var8 == var7 || var9 == -var7 || var9 == var7; ChunkCoordIntPair var11 = new ChunkCoordIntPair(var8 + var5, var9 + var6); if (!var10) { eligibleChunksForSpawning.put(var11, Boolean.valueOf(false)); } else if (!eligibleChunksForSpawning.containsKey(var11)) { eligibleChunksForSpawning.put(var11, Boolean.valueOf(true)); } } } } var3 = 0; ChunkCoordinates var31 = par1WorldServer.getSpawnPoint(); EnumCreatureType[] var32 = EnumCreatureType.values(); var6 = var32.length; for (int var33 = 0; var33 < var6; ++var33) { EnumCreatureType var34 = var32[var33]; if ((!var34.getPeacefulCreature() || par3) && (var34.getPeacefulCreature() || par2) && par1WorldServer.countEntities(var34.getCreatureClass()) <= var34.getMaxNumberOfCreature() * eligibleChunksForSpawning.size() / 256) { Iterator var35 = eligibleChunksForSpawning.keySet().iterator(); label108: while (var35.hasNext()) { ChunkCoordIntPair var37 = (ChunkCoordIntPair) var35.next(); if (!((Boolean) eligibleChunksForSpawning.get(var37)).booleanValue()) { ChunkPosition var36 = getRandomSpawningPointInChunk(par1WorldServer, var37.chunkXPos, var37.chunkZPos); int var12 = var36.x; int var13 = var36.y; int var14 = var36.z; if (!par1WorldServer.isBlockNormalCube(var12, var13, var14) && par1WorldServer.getBlockMaterial(var12, var13, var14) == var34.getCreatureMaterial()) { int var15 = 0; int var16 = 0; while (var16 < 3) { int var17 = var12; int var18 = var13; int var19 = var14; byte var20 = 6; SpawnListEntry var21 = null; EntityLivingData entitylivingdata = null; int var22 = 0; while (true) { if (var22 < 4) { label101: { var17 += par1WorldServer.rand.nextInt(var20) - par1WorldServer.rand.nextInt(var20); var18 += par1WorldServer.rand.nextInt(1) - par1WorldServer.rand.nextInt(1); var19 += par1WorldServer.rand.nextInt(var20) - par1WorldServer.rand.nextInt(var20); if (canCreatureTypeSpawnAtLocation( var34, par1WorldServer, var17, var18, var19)) { float var23 = (float) var17 + 0.5F; float var24 = (float) var18; float var25 = (float) var19 + 0.5F; if (par1WorldServer.getClosestPlayer( (double) var23, (double) var24, (double) var25, 24.0D) == null) { float var26 = var23 - (float) var31.posX; float var27 = var24 - (float) var31.posY; float var28 = var25 - (float) var31.posZ; float var29 = var26 * var26 + var27 * var27 + var28 * var28; if (var29 >= 576.0F) { if (var21 == null) { var21 = spawnRandomCreature( par1WorldServer, var34, var17, var18, var19); if (var21 == null) { break label101; } } EntityLiving var38; try { var38 = (EntityLiving) var21 .entityClass .getConstructor(new Class[] {World.class}) .newInstance(new Object[] {par1WorldServer}); } catch (Exception var30) { var30.printStackTrace(); return var3; } var38.setLocationAndAngles( (double) var23, (double) var24, (double) var25, par1WorldServer.rand.nextFloat() * 360.0F, 0.0F); if (var38.getCanSpawnHere()) { ++var15; par1WorldServer.spawnEntityInWorld(var38); entitylivingdata = var38.onSpawnWithEgg(entitylivingdata); if (var15 >= var38.getMaxSpawnedInChunk()) { continue label108; } } var3 += var15; } } } ++var22; continue; } } ++var16; break; } } } } } } } return var3; } }