public static void Initialize() { if (m_gameDatabase == null) { XElement node = ContentManager.Get <XElement>("Database"); ContentManager.Dispose("Database"); ModsManager.CombineXml(node, ModsManager.GetEntries(".xdb"), "Guid", "Name"); m_gameDatabase = new GameDatabase(XmlDatabaseSerializer.LoadDatabase(node)); foreach (DatabaseObject explicitNestingChild in GameDatabase.Database.Root.GetExplicitNestingChildren(GameDatabase.EntityTemplateType, directChildrenOnly: false)) { ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.PopulateFromDatabaseObject(explicitNestingChild); m_valueDictionaries.Add(explicitNestingChild.Name, valuesDictionary); } return; } throw new InvalidOperationException("Database already loaded."); }
public override void Initialize() { if (Initialize1 != null) { Initialize1(); return; } int num = 0; Dictionary <int, ClothingData> dictionary = new Dictionary <int, ClothingData>(); IEnumerator <XElement> enumerator = ModsManager.CombineXml(ContentManager.Get <XElement>("Clothes"), ModsManager.GetEntries(".clo"), "Index", "Clothes").Elements().GetEnumerator(); while (enumerator.MoveNext()) { XElement item = enumerator.Current; string newDescription = LanguageControl.GetBlock(string.Format("{0}:{1}", GetType().Name, Index), "Description"); string newDisplayName = LanguageControl.GetBlock(string.Format("{0}:{1}", GetType().Name, Index), "DisplayName"); if (item.Attribute("DisplayName") != null && item.Attribute("Description") != null) { newDisplayName = XmlUtils.GetAttributeValue <string>(item, "DisplayName"); newDescription = XmlUtils.GetAttributeValue <string>(item, "Description"); } ClothingData clothingData = new ClothingData { Index = XmlUtils.GetAttributeValue <int>(item, "Index"), DisplayIndex = num++, DisplayName = newDisplayName, Slot = XmlUtils.GetAttributeValue <ClothingSlot>(item, "Slot"), ArmorProtection = XmlUtils.GetAttributeValue <float>(item, "ArmorProtection"), Sturdiness = XmlUtils.GetAttributeValue <float>(item, "Sturdiness"), Insulation = XmlUtils.GetAttributeValue <float>(item, "Insulation"), MovementSpeedFactor = XmlUtils.GetAttributeValue <float>(item, "MovementSpeedFactor"), SteedMovementSpeedFactor = XmlUtils.GetAttributeValue <float>(item, "SteedMovementSpeedFactor"), DensityModifier = XmlUtils.GetAttributeValue <float>(item, "DensityModifier"), IsOuter = XmlUtils.GetAttributeValue <bool>(item, "IsOuter"), CanBeDyed = XmlUtils.GetAttributeValue <bool>(item, "CanBeDyed"), Layer = XmlUtils.GetAttributeValue <int>(item, "Layer"), PlayerLevelRequired = XmlUtils.GetAttributeValue <int>(item, "PlayerLevelRequired"), Texture = ContentManager.Get <Texture2D>(XmlUtils.GetAttributeValue <string>(item, "TextureName")), ImpactSoundsFolder = XmlUtils.GetAttributeValue <string>(item, "ImpactSoundsFolder"), Description = newDescription }; dictionary.Add(clothingData.Index, clothingData); } m_clothingData = new ClothingData[dictionary.Count]; for (int i = 0; i < dictionary.Count; i++) { m_clothingData[i] = dictionary[i]; } Model playerModel = CharacterSkinsManager.GetPlayerModel(PlayerClass.Male); Matrix[] array = new Matrix[playerModel.Bones.Count]; playerModel.CopyAbsoluteBoneTransformsTo(array); int index = playerModel.FindBone("Hand1").Index; int index2 = playerModel.FindBone("Hand2").Index; array[index] = Matrix.CreateRotationY(0.1f) * array[index]; array[index2] = Matrix.CreateRotationY(-0.1f) * array[index2]; m_innerMesh = new BlockMesh(); foreach (ModelMesh mesh in playerModel.Meshes) { Matrix matrix = array[mesh.ParentBone.Index]; foreach (ModelMeshPart meshPart in mesh.MeshParts) { Color color = Color.White * 0.8f; color.A = byte.MaxValue; m_innerMesh.AppendModelMeshPart(meshPart, matrix, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_innerMesh.AppendModelMeshPart(meshPart, matrix, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, color); } } Model outerClothingModel = CharacterSkinsManager.GetOuterClothingModel(PlayerClass.Male); Matrix[] array2 = new Matrix[outerClothingModel.Bones.Count]; outerClothingModel.CopyAbsoluteBoneTransformsTo(array2); int index3 = outerClothingModel.FindBone("Leg1").Index; int index4 = outerClothingModel.FindBone("Leg2").Index; array2[index3] = Matrix.CreateTranslation(-0.02f, 0f, 0f) * array2[index3]; array2[index4] = Matrix.CreateTranslation(0.02f, 0f, 0f) * array2[index4]; m_outerMesh = new BlockMesh(); foreach (ModelMesh mesh2 in outerClothingModel.Meshes) { Matrix matrix2 = array2[mesh2.ParentBone.Index]; foreach (ModelMeshPart meshPart2 in mesh2.MeshParts) { Color color2 = Color.White * 0.8f; color2.A = byte.MaxValue; m_outerMesh.AppendModelMeshPart(meshPart2, matrix2, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_outerMesh.AppendModelMeshPart(meshPart2, matrix2, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, color2); } } base.Initialize(); }
public static void Initialize() { if (Initialize1 != null) { Initialize1(); return; } XElement source1 = ContentManager.Get <XElement>("CraftingRecipes"); ModsManager.CombineXml(source1, ModsManager.GetEntries(".cr"), "Description", "Result", "Recipes"); IEnumerable <XElement> source2 = source1.Descendants("Recipe"); foreach (XElement item in source2) { CraftingRecipe craftingRecipe = new CraftingRecipe(); string attributeValue = XmlUtils.GetAttributeValue <string>(item, "Result"); string desc = LanguageControl.GetBlock(attributeValue, "CRDescription"); if (item.Attribute("Description") != null) { desc = XmlUtils.GetAttributeValue <string>(item, "Description"); } craftingRecipe.ResultValue = DecodeResult(attributeValue); craftingRecipe.ResultCount = XmlUtils.GetAttributeValue <int>(item, "ResultCount"); string attributeValue2 = XmlUtils.GetAttributeValue(item, "Remains", string.Empty); if (!string.IsNullOrEmpty(attributeValue2)) { craftingRecipe.RemainsValue = DecodeResult(attributeValue2); craftingRecipe.RemainsCount = XmlUtils.GetAttributeValue <int>(item, "RemainsCount"); } craftingRecipe.RequiredHeatLevel = XmlUtils.GetAttributeValue <float>(item, "RequiredHeatLevel"); craftingRecipe.RequiredPlayerLevel = XmlUtils.GetAttributeValue(item, "RequiredPlayerLevel", 1f); craftingRecipe.Description = desc; craftingRecipe.Message = XmlUtils.GetAttributeValue <string>(item, "Message", null); if (craftingRecipe.ResultCount > BlocksManager.Blocks[Terrain.ExtractContents(craftingRecipe.ResultValue)].MaxStacking) { throw new InvalidOperationException($"In recipe for \"{attributeValue}\" ResultCount is larger than max stacking of result block."); } if (craftingRecipe.RemainsValue != 0 && craftingRecipe.RemainsCount > BlocksManager.Blocks[Terrain.ExtractContents(craftingRecipe.RemainsValue)].MaxStacking) { throw new InvalidOperationException($"In Recipe for \"{attributeValue2}\" RemainsCount is larger than max stacking of remains block."); } Dictionary <char, string> dictionary = new Dictionary <char, string>(); foreach (XAttribute item2 in from a in item.Attributes() where a.Name.LocalName.Length == 1 && char.IsLower(a.Name.LocalName[0]) select a) { DecodeIngredient(item2.Value, out string craftingId, out int?data); if (BlocksManager.FindBlocksByCraftingId(craftingId).Length == 0) { throw new InvalidOperationException($"Block with craftingId \"{item2.Value}\" not found."); } if (data.HasValue && (data.Value < 0 || data.Value > 262143)) { throw new InvalidOperationException($"Data in recipe ingredient \"{item2.Value}\" must be between 0 and 0x3FFFF."); } dictionary.Add(item2.Name.LocalName[0], item2.Value); } string[] array = item.Value.Trim().Split(new string[] { "\n" }, StringSplitOptions.None); for (int i = 0; i < array.Length; i++) { int num = array[i].IndexOf('"'); int num2 = array[i].LastIndexOf('"'); if (num < 0 || num2 < 0 || num2 <= num) { throw new InvalidOperationException("Invalid recipe line."); } string text = array[i].Substring(num + 1, num2 - num - 1); for (int j = 0; j < text.Length; j++) { char c = text[j]; if (char.IsLower(c)) { string text2 = dictionary[c]; craftingRecipe.Ingredients[j + i * 3] = text2; } } } m_recipes.Add(craftingRecipe); } Block[] blocks = BlocksManager.Blocks; foreach (Block block in blocks) { m_recipes.AddRange(block.GetProceduralCraftingRecipes()); } m_recipes.Sort(delegate(CraftingRecipe r1, CraftingRecipe r2) { int y = r1.Ingredients.Count((string s) => !string.IsNullOrEmpty(s)); int x = r2.Ingredients.Count((string s) => !string.IsNullOrEmpty(s)); return(Comparer <int> .Default.Compare(x, y)); }); }
public void init() { bool isNewBlock = false; foreach (ModInfo modInfo in ModsManager.LoadedMods) { if (modInfo.Name == "NewBlocks_SC") { isNewBlock = true; is_NewSC = true; } } if (isNewBlock) { XElement item = ModsManager.CombineXml(new XElement("NewBlocks"), ModsManager.GetEntries(".xjdb")); foreach (XElement element in item.Elements()) { foreach (XElement element1 in element.Elements()) { if (!newblockcrafts.ContainsKey(element1.Attribute("DisplayName").Value)) { newblockcrafts.Add(element1.Attribute("DisplayName").Value, element1.Attribute("CraftingId").Value); } } } } int k = 0; values.Add(0); blocks.Add(BlocksManager.Blocks[0]); names.Add("空气"); craftids.Add("空气"); foreach (Block block in BlocksManager.Blocks) { foreach (int cv in block.GetCreativeValues()) { //添加所有方块 if (cv == 0) { continue; } if (values.Contains(cv)) { continue; } string ll = block.GetDisplayName(null, cv); if (XjJeiManager.is_NewSC && ModsManager.customer_Strings.ContainsKey(ll)) { ll = ModsManager.customer_Strings[ll]; } if (string.IsNullOrEmpty(ll)) { continue; } if (block.GetCategory(cv) == "Painted") { continue; } if (isNewBlock) { if (newblockcrafts.TryGetValue(ll, out string namm)) { craftids.Add(namm); } else { craftids.Add(block.CraftingId); } } else { craftids.Add(block.CraftingId); } values.Add(cv); blocks.Add(block); names.Add(ll); k += 1; } } }