private static SpawnListEntry spawnRandomCreature( World w, EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4) { if (w instanceof FakeWorldServer) { return null; } List list2 = w.getChunkProvider().getPossibleCreatures(par1EnumCreatureType, par2, par3, par4); List list = new ArrayList(); for (Object o : list2) { SpawnListEntry s = (SpawnListEntry) o; String str = (String) (classToStringMapping.get(s.entityClass)); if (EntityLiving.allow(str, w.provider.dimensionId)) { list.add(s); } } if (list == null || list.isEmpty()) { return null; } return (SpawnListEntry) WeightedRandom.getRandomItem(w.rand, list); }
/** Called during chunk generation to spawn initial creatures. */ public static void performWorldGenSpawning( World par0World, BiomeGenBase par1BiomeGenBase, int par2, int par3, int par4, int par5, Random par6Random) { List list = getSpawnableList(par0World, par1BiomeGenBase, EnumCreatureType.creature); if (list.isEmpty()) { return; } while (par6Random.nextFloat() < par1BiomeGenBase.getSpawningChance()) { SpawnListEntry spawnlistentry = (SpawnListEntry) WeightedRandom.getRandomItem(par0World.rand, list); EntityLivingData entitylivingdata = null; int i = spawnlistentry.minGroupCount + par6Random.nextInt( (1 + spawnlistentry.maxGroupCount) - spawnlistentry.minGroupCount); int j = par2 + par6Random.nextInt(par4); int k = par3 + par6Random.nextInt(par5); int l = j; int i1 = k; int j1 = 0; while (j1 < i) { boolean flag = false; for (int k1 = 0; !flag && k1 < 4; k1++) { int l1 = par0World.getTopSolidOrLiquidBlock(j, k); if (canCreatureTypeSpawnAtLocation(EnumCreatureType.creature, par0World, j, l1, k)) { float f = (float) j + 0.5F; float f1 = l1; float f2 = (float) k + 0.5F; EntityLiving entityliving; try { entityliving = (EntityLiving) spawnlistentry .entityClass .getConstructor(new Class[] {net.minecraft.src.World.class}) .newInstance(new Object[] {par0World}); } catch (Exception exception) { exception.printStackTrace(); continue; } entityliving.setLocationAndAngles(f, f1, f2, par6Random.nextFloat() * 360F, 0.0F); par0World.spawnEntityInWorld(entityliving); entitylivingdata = entityliving.onSpawnWithEgg(entitylivingdata); flag = true; } j += par6Random.nextInt(5) - par6Random.nextInt(5); for (k += par6Random.nextInt(5) - par6Random.nextInt(5); j < par2 || j >= par2 + par4 || k < par3 || k >= par3 + par4; k = (i1 + par6Random.nextInt(5)) - par6Random.nextInt(5)) { j = (l + par6Random.nextInt(5)) - par6Random.nextInt(5); } } j1++; } } }