/// <summary> /// Called during chunk generation to spawn initial creatures. /// </summary> public static void PerformWorldGenSpawning(World par0World, BiomeGenBase par1BiomeGenBase, int par2, int par3, int par4, int par5, Random par6Random) { List <SpawnListEntry> list = par1BiomeGenBase.GetSpawnableList(CreatureType.Creature); if (list.Count == 0) { return; } while (par6Random.NextDouble() < par1BiomeGenBase.GetSpawningChance()) { SpawnListEntry spawnlistentry = (SpawnListEntry)WeightedRandom.GetRandomItem(par0World.Rand, list); int i = spawnlistentry.MinGroupCount + par6Random.Next((1 + spawnlistentry.MaxGroupCount) - spawnlistentry.MinGroupCount); int j = par2 + par6Random.Next(par4); int k = par3 + par6Random.Next(par5); int l = j; int i1 = k; int j1 = 0; while (j1 < i) { bool flag = false; for (int k1 = 0; !flag && k1 < 4; k1++) { int l1 = par0World.GetTopSolidOrLiquidBlock(j, k); if (CanCreatureTypeSpawnAtLocation(CreatureType.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)Activator.CreateInstance(spawnlistentry.EntityClass, new object[] { par0World }); } catch (Exception exception) { Console.WriteLine(exception.ToString()); Console.Write(exception.StackTrace); continue; } entityliving.SetLocationAndAngles(f, f1, f2, (float)par6Random.NextDouble() * 360F, 0.0F); par0World.SpawnEntityInWorld(entityliving); CreatureSpecificInit(entityliving, par0World, f, f1, f2); flag = true; } j += par6Random.Next(5) - par6Random.Next(5); for (k += par6Random.Next(5) - par6Random.Next(5); j < par2 || j >= par2 + par4 || k < par3 || k >= par3 + par4; k = (i1 + par6Random.Next(5)) - par6Random.Next(5)) { j = (l + par6Random.Next(5)) - par6Random.Next(5); } } j1++; } } }
/// <summary> /// Create a list of random EnchantmentData (enchantments) that can be added together to the ItemStack, the 3rd /// parameter is the total enchantability level. /// </summary> public static List <EnchantmentData> BuildEnchantmentList(Random par0Random, ItemStack par1ItemStack, int par2) { Item item = par1ItemStack.GetItem(); int i = item.GetItemEnchantability(); if (i <= 0) { return(null); } i = 1 + par0Random.Next((i >> 1) + 1) + par0Random.Next((i >> 1) + 1); int j = i + par2; float f = ((par0Random.NextFloat() + par0Random.NextFloat()) - 1.0F) * 0.25F; int k = (int)((float)j * (1.0F + f) + 0.5F); List <EnchantmentData> arraylist = null; Dictionary <int, EnchantmentData> map = MapEnchantmentData(k, par1ItemStack); if (map != null && map.Count > 0) { EnchantmentData enchantmentdata = (EnchantmentData)WeightedRandom.GetRandomItem(par0Random, map.Values); if (enchantmentdata != null) { arraylist = new List <EnchantmentData>(); arraylist.Add(enchantmentdata); for (int l = k >> 1; par0Random.Next(50) <= l; l >>= 1) { /* * IEnumerator<int> iterator = map.Keys.GetEnumerator(); * * do * { * if (!iterator.MoveNext()) * { * break; * } * * int integer = iterator.Current; * bool flag = true; * IEnumerator<EnchantmentData> iterator1 = arraylist.GetEnumerator(); * * do * { * if (!iterator1.MoveNext()) * { * break; * } * * EnchantmentData enchantmentdata2 = iterator1.Current; * * if (enchantmentdata2.Enchantmentobj.CanApplyTogether(Enchantment.EnchantmentsList[integer])) * { * continue; * } * * flag = false; * break; * } * while (true); * * if (!flag) * { * iterator.Remove(); * } * } * while (true); */ if (map.Count > 0) { EnchantmentData enchantmentdata1 = (EnchantmentData)WeightedRandom.GetRandomItem(par0Random, map.Values); arraylist.Add(enchantmentdata1); } } } } return(arraylist); }
private static void FillTreasureChestWithLoot(Random par0Random, StructurePieceTreasure[] par1ArrayOfStructurePieceTreasure, TileEntityChest par2TileEntityChest, int par3) { for (int i = 0; i < par3; i++) { StructurePieceTreasure structurepiecetreasure = (StructurePieceTreasure)WeightedRandom.GetRandomItem(par0Random, par1ArrayOfStructurePieceTreasure); int j = structurepiecetreasure.MinItemStack + par0Random.Next((structurepiecetreasure.MaxItemStack - structurepiecetreasure.MinItemStack) + 1); if (Item.ItemsList[structurepiecetreasure.ItemID].GetItemStackLimit() >= j) { par2TileEntityChest.SetInventorySlotContents(par0Random.Next(par2TileEntityChest.GetSizeInventory()), new ItemStack(structurepiecetreasure.ItemID, j, structurepiecetreasure.ItemMetadata)); continue; } for (int k = 0; k < j; k++) { par2TileEntityChest.SetInventorySlotContents(par0Random.Next(par2TileEntityChest.GetSizeInventory()), new ItemStack(structurepiecetreasure.ItemID, 1, structurepiecetreasure.ItemMetadata)); } } }