public BiomeMeta a(EnumCreatureType enumcreaturetype, int i, int j, int k) { List list = this.L().getMobsFor(enumcreaturetype, i, j, k); return list != null && !list.isEmpty() ? (BiomeMeta) WeightedRandom.a(this.random, (Collection) list) : null; }
/** only spawns creatures allowed by the chunkProvider */ public SpawnListEntry spawnRandomCreature( EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4) { List var5 = this.getChunkProvider().getPossibleCreatures(par1EnumCreatureType, par2, par3, par4); return var5 != null && !var5.isEmpty() ? (SpawnListEntry) WeightedRandom.getRandomItem(this.rand, var5) : null; }
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); }
/** * Create a list of random EnchantmentData (enchantments) that can be added together to the * ItemStack, the 3rd parameter is the total enchantability level. */ public static List buildEnchantmentList(Random par0Random, ItemStack par1ItemStack, int par2) { Item var3 = par1ItemStack.getItem(); int var4 = var3.getItemEnchantability(); if (var4 <= 0) { return null; } else { var4 /= 2; var4 = 1 + par0Random.nextInt((var4 >> 1) + 1) + par0Random.nextInt((var4 >> 1) + 1); int var5 = var4 + par2; float var6 = (par0Random.nextFloat() + par0Random.nextFloat() - 1.0F) * 0.15F; int var7 = (int) ((float) var5 * (1.0F + var6) + 0.5F); if (var7 < 1) { var7 = 1; } ArrayList var8 = null; Map var9 = mapEnchantmentData(var7, par1ItemStack); if (var9 != null && !var9.isEmpty()) { EnchantmentData var10 = (EnchantmentData) WeightedRandom.getRandomItem(par0Random, var9.values()); if (var10 != null) { var8 = new ArrayList(); var8.add(var10); for (int var11 = var7; par0Random.nextInt(50) <= var11; var11 >>= 1) { Iterator var12 = var9.keySet().iterator(); while (var12.hasNext()) { Integer var13 = (Integer) var12.next(); boolean var14 = true; Iterator var15 = var8.iterator(); while (true) { if (var15.hasNext()) { EnchantmentData var16 = (EnchantmentData) var15.next(); if (var16.enchantmentobj.canApplyTogether( Enchantment.enchantmentsList[var13.intValue()])) { continue; } var14 = false; } if (!var14) { var12.remove(); } break; } } if (!var9.isEmpty()) { EnchantmentData var17 = (EnchantmentData) WeightedRandom.getRandomItem(par0Random, var9.values()); var8.add(var17); } } } } return var8; } }
public static List b(Random random, ItemStack itemstack, int i) { Item item = itemstack.getItem(); int j = item.c(); if (j <= 0) { return null; } else { j /= 2; j = 1 + random.nextInt((j >> 1) + 1) + random.nextInt((j >> 1) + 1); int k = j + i; float f = (random.nextFloat() + random.nextFloat() - 1.0F) * 0.15F; int l = (int) ((float) k * (1.0F + f) + 0.5F); if (l < 1) { l = 1; } ArrayList arraylist = null; Map map = b(l, itemstack); if (map != null && !map.isEmpty()) { EnchantmentInstance enchantmentinstance = (EnchantmentInstance) WeightedRandom.a(random, map.values()); if (enchantmentinstance != null) { arraylist = new ArrayList(); arraylist.add(enchantmentinstance); for (int i1 = l; random.nextInt(50) <= i1; i1 >>= 1) { Iterator iterator = map.keySet().iterator(); while (iterator.hasNext()) { Integer integer = (Integer) iterator.next(); boolean flag = true; Iterator iterator1 = arraylist.iterator(); while (true) { if (iterator1.hasNext()) { EnchantmentInstance enchantmentinstance1 = (EnchantmentInstance) iterator1.next(); if (enchantmentinstance1.enchantment.a(Enchantment.byId[integer.intValue()])) { continue; } flag = false; } if (!flag) { iterator.remove(); } break; } } if (!map.isEmpty()) { EnchantmentInstance enchantmentinstance2 = (EnchantmentInstance) WeightedRandom.a(random, map.values()); arraylist.add(enchantmentinstance2); } } } } return arraylist; } }
/** 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++; } } }