public void DelectBlockInfo(string id, string datas) { var Success = false; foreach (var key in BlockInfoList.Keys) { var s = BlockInfoList[key].RemoveAll ( (List <BlockInfo> blockList) => blockList.Exists ( (BlockInfo blockInfo) => blockInfo.Id == id && Universal.Match(blockInfo.Data, datas) ) ); if (s > 0) { Success = true; } } if (!Success) { Current.Error("Filter Block: \"" + id + "[" + datas + "]\" Not Found", false); } return; }
//Delect public void DelectBlockInfoClass(string blockInfoClass) { if (BlockInfoList.Keys.Contains(blockInfoClass)) { BlockInfoList.Remove(blockInfoClass); } else { Current.Error("Filter Class: \"" + blockInfoClass + "\" Not Found", false); } }
static public Biome GetBiome(string biomeName) { if (_biome.Keys.Contains(biomeName)) { return(_biome[biomeName]); } else { Current.Error("Biome: Biome " + biomeName + " Not Found."); return(null); } }
private static JsonModel RemoveEmptyElement(JsonModel jsonModel) { #region Delect Empty Elements var _el = jsonModel.elements.ToList(); _el.RemoveAll(e => e == null); _el.RemoveAll(e => e.faces == null || !((e.faces.ContainsKey("West") && e.faces["West"] != null) || (e.faces.ContainsKey("East") && e.faces["East"] != null) || (e.faces.ContainsKey("North") && e.faces["North"] != null) || (e.faces.ContainsKey("South") && e.faces["South"] != null) || (e.faces.ContainsKey("Down") && e.faces["Down"] != null) || (e.faces.ContainsKey("Up") && e.faces["Up"] != null))); foreach (var e in _el) { if (!((e.faces.ContainsKey("West") && e.faces["West"] != null) || (e.faces.ContainsKey("East") && e.faces["East"] != null) || (e.faces.ContainsKey("North") && e.faces["North"] != null) || (e.faces.ContainsKey("South") && e.faces["South"] != null) || (e.faces.ContainsKey("Down") && e.faces["Down"] != null) || (e.faces.ContainsKey("Up") && e.faces["Up"] != null))) { Current.Error("Delect failed."); } } jsonModel.elements = _el.ToArray(); return(jsonModel); #endregion }
//Get public BlockInfo GetBlockInfo(string id, string datas, double version) { var blockList = GetBlockList(id, datas); if (blockList == null) { Current.Error("Block Model: " + id + "[" + datas + "] Not Found", false); return(null); } foreach (var model in blockList) { if ((model.VersionFrom <= version && model.VersionFrom > 0) || model.VersionFrom == 0) { if (model.VersionTo > version || model.VersionTo == 0) { return(model); } } } Current.Error("Block Version: " + id + "[" + datas + "] Not Correct", false); return(null); }
static public float temp; static public float rain; //Biome #endregion static void Main(string[] args) { Current.Write("Reading Resources ..."); res = new ResourceList(Application.StartupPath); Current.Write(""); #region File & Options string file; //Current Version = 1.12.2 version = 1.122; #region Get File if (args.Length > 0) { file = args[0]; } else { Current.WriteLine("Input: <file> <mode & filter & biome>"); args = Current.ReadLine().Split(' '); file = args[0]; } if (file == null || !File.Exists(file)) { Current.Error("File Not Found", true, true); } else if (new FileInfo(file).Extension == ".schematic" || new FileInfo(file).Extension == ".nbt") { target = new FileInfo(file).Extension; } else { Current.Error("File Not Supported", true, true); } #endregion #region GetOptions //Set Output Mode #region mode unlimit = args.Contains("unlimit"); smooth = args.Contains("smooth"); nopause = args.Contains("nopause"); log = args.Contains("log"); #endregion //Set Target Version #region version foreach (string reg in args) { if (Regex.Match(reg, "version=.*$").Success) { if (Regex.Match(Regex.Matches(reg, "version=.*$")[0].Value, @"\d*\.\d*").Success) { List <double> v1st = new List <double>(); foreach (Match r in Regex.Matches(Regex.Matches(reg, "version=.*$")[0].Value, @"\d*\.\d*")) { v1st.Add(double.Parse(r.Value)); } v1st.Sort(delegate(double x, double y) { return(y.CompareTo(x)); }); version = v1st[0]; } } } #endregion //Set Target Biome; #region biome temp = 0.8f; rain = 0.4f; var biome = "TheVoid"; foreach (string reg in args) { if (Regex.Match(reg, "(?<=biome=).*$").Success) { var biomeName = Regex.Match(reg, "(?<=biome=).*$").Value; BiomeList.UpdateList(Application.StartupPath + "\\BiomeList"); var cbiome = BiomeList.GetBiome(biomeName); if (cbiome != null) { temp = cbiome.Temperature; rain = cbiome.Rainfall; biome = biomeName; } } } #endregion //Set Process; #region Process var nocompress = false; var hollow = false; var surface = false; var fillflow = false; var fillflow_xyz = new Vector3() { X = 0.0, Y = 0.0, Z = 0.0 }; var fillflow_block = new SimpleBlockInfo(""); var reverse_fillflow = false; nocompress = args.Contains("nocompress"); hollow = args.Contains("hollow"); surface = args.Contains("surface"); foreach (string reg in args) { if (Regex.Match(reg, "(?<=fillflow=).*$").Success) { try { var o = Regex.Match(reg, "(?<=fillflow=).*$").Value; reverse_fillflow = Regex.Match(o, "(reverse|r)(?=\\()").Success; var os = Regex.Match(o, "(?<=\\().*(?=\\))").Value.Split(','); var ob = Regex.Match(o, "(?<=\\)).*$").Value.Trim(); if (os != null && os.Length == 3) { fillflow_xyz.X = double.Parse(Regex.Match(os[0].Trim(), "\\d+(.\\d+)?").Value); fillflow_xyz.Y = double.Parse(Regex.Match(os[1].Trim(), "\\d+(.\\d+)?").Value); fillflow_xyz.Z = double.Parse(Regex.Match(os[2].Trim(), "\\d+(.\\d+)?").Value); } if (ob != null) { fillflow_block = new SimpleBlockInfo(ob); } fillflow = true; } catch { Current.Error("FillFlow Format Error.", true, true); } } } #endregion #endregion #region Filter #region For Classes var filterClasses = new List <string>(); //get filter_classes foreach (string reg in args) { if (Regex.Match(reg, "(?<=filter_classes=).*$").Success) { filterClasses = new List <string>(Regex.Match(reg, "(?<=filter_classes=).*$").Value.Split(';')); } } //remove form list foreach (var c in filterClasses) { res.DelectBlockInfoClass(c); } #endregion #region For Blocks var filterBlocks = ""; var fbs = new List <SimpleBlockInfo>(); //Get filter_blocks foreach (string reg in args) { if (Regex.Match(reg, "(?<=filter_blocks=).*$").Success) { filterBlocks = Regex.Match(reg, "(?<=filter_blocks=).*$").Value; fbs = res.SimpleBlockInfoCollection(Regex.Match(reg, "(?<=filter_blocks=).*$").Value, Application.StartupPath); } } //Remove from List foreach (var b in fbs) { res.DelectBlockInfo(b.Id, b.Data); } #endregion #endregion #endregion #region Set BlockCollection if (target == ".schematic") { Schematic2BlockCollection(file); } if (target == ".nbt") { NBT2BlockCollection(file); } bcl.blocks.RemoveAll(block => block == null); #endregion #region Output Info Current.WriteLine(""); Current.WriteLine("- Info:"); //-output target Current.WriteLine("Target = " + target.Replace(".", "").ToUpper()); //-output size Current.WriteLine("Width = " + bcl.GetWidth() + " ,Height = " + bcl.GetHeight() + " ,Length = " + bcl.GetLength() + ";"); //-output filter var ig_b = String.Join(";", filterBlocks); Current.WriteLine(ig_b == "" ? "Filter Blocks = none;" : "Filter Blocks = " + ig_b + ";"); var ig_m = String.Join(";", filterClasses); Current.WriteLine(ig_m == "" ? "Filter Models = none;" : "Filter Models = " + ig_m + ";"); //-output biome Current.WriteLine(biome == "" ? "Biome = none" : "Biome = " + biome + ";"); //-output mode Current.WriteLine("Unlimit = " + unlimit.ToString() + " ,Smooth = " + smooth.ToString() + ";"); //-output compress Current.WriteLine("Nocompress = " + nocompress.ToString() + " ,Hollow = " + hollow.ToString() + " ,Surface = " + surface.ToString()); #endregion if (hollow) { bcl = Hollow(bcl); } if (fillflow) { bcl = FillFlow(bcl, fillflow_xyz, fillflow_block, reverse_fillflow); } var jsonModel = JsonModel(Application.StartupPath); if (!nocompress) { jsonModel = DuplicateOverlap(jsonModel); } if (surface) { jsonModel.KeepSurface(); } jsonModel = ScaleModel(RemoveEmptyElement(jsonModel)); #region Generating File Current.WriteLine(""); Current.WriteLine("- Generating File:"); var extension = Path.GetExtension(file); var newFile = file.Replace(extension, ".json"); File.WriteAllText(newFile, JsonConvert.SerializeObject(jsonModel, Formatting.Indented)); Current.WriteLine(newFile + " has been Created"); #endregion if (log) { File.WriteAllText("Log -" + DateTime.Now.ToFileTime() + ".txt", Current.Log.ToString()); } if (nopause) { return; } Current.WriteLine("[ Press any key to continue... ]"); Console.ReadKey(true); }
private int[] GetUV(BlockInfo _info, string directoryPath) { var uv = new int[] { 0, 0 }; var t = GetTexture(_info); var path = ""; if (Program.version >= 1.13) { var m = t.Path.ToList(); m.RemoveAt(5); path = String.Join(null, m.ToArray()); } if (t.Params != null && t.Params.Contains("ColorMap")) //ColorMap { var pars = t.Params.Split(' '); if (pars.Length != 5 && pars[0] != "ColorMap") { uv = GetColorMapUV(Program.temp, Program.rain, 0, false, 0); } else { uv = GetColorMapUV(Program.temp, Program.rain, int.Parse(pars[1]), bool.Parse(pars[2]), float.Parse(pars[3]), float.Parse(pars[4])); } } else //Default { bool textureError = true; if (Program.smooth) { try { Bitmap compare = new Bitmap(directoryPath + "\\textures\\" + path.Replace("/", "\\") + ".png"); for (int mh = 0; mh < compare.Size.Height; mh++) { for (int mw = 0; mw < compare.Size.Width; mw++) { if (compare.GetPixel(mh, mw).A > 8) { uv[0] = mh; uv[1] = mw; break; } } if (uv[0] > 0 && uv[1] > 0) { break; } } } catch { Current.Error("Texture: " + t.Path + ".png Not Found", false); } } else { while (textureError) { uv[0] = (int)Math.Floor(StaticRandom.NextDouble() * 16); uv[1] = (int)Math.Floor(StaticRandom.NextDouble() * 16); try { Bitmap compare = new Bitmap(System.Windows.Forms.Application.StartupPath + "\\textures\\" + path.Replace("/", "\\") + ".png"); textureError = (compare.GetPixel((int)uv[0], (int)uv[1]).A <= 8); } catch { Current.Error("Texture: " + t.Path + ".png Not Found", false); } } } } return(uv); }