/// <summary> /// Update itms from web. /// </summary> public static void UpdateItems() { WebClient wc = new WebClient(); string[] derp = wc.DownloadString("http://copy.mcft.net/mc/items/").Split(new string[]{"\n","\r\n"},StringSplitOptions.RemoveEmptyEntries); foreach (string line in derp) { if (line.StartsWith("<img src=\"/mc/icons/")) { string[] chunks = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // icon HEX DEC NAME //<img src="/mc/icons/0.png"/> 0 0 Air Block nb = new Block(); nb.ID = short.Parse(chunks[3]); nb.Name = string.Join(" ", chunks, 4, chunks.Length - 4); short i=0; if (Find(nb.Name) != null) { string type = (nb.ID<255) ? " block": " (item)"; nb.Name+=type; if (Find(nb.Name) != null) { while(true) { string nm = nb.Name+" "+(++i).ToString(); if (Find(nm) == null) { nb.Name=nm; break; } } } } BlocksToDL.Enqueue(nb); TotalImages++; } } }
/// <summary> /// Get average color of the image for this block /// </summary> /// <param name="b">Block</param> /// <returns>Average color of block texture</returns> private static Color GetColorFor(Block b) { int R, G, B,C; R = G = B = C=0; for (int x = 0; x < b.Image.Width; x++) { for (int y = 0; y < b.Image.Height; y++) { Color c = b.Image.GetPixel(x, y); R += (int)c.R; G += (int)c.G; B += (int)c.B; C++; } } return Color.FromArgb(R / C, G / C, B / C); }
// Since copyboy's getting burnt out... // TODO: Make a mirror in case someone bitches. public static void UpdateIDs() { //WebClient wc = new WebClient(); //wc.Headers.Add("User-Agent: MineEdit/" + Version); //wc.Headers.Add("Referer: http://www.minecraftwiki.net/"); //string derp = wc.DownloadString("http://www.minecraftwiki.net/wiki/Data_values"); //<tr> // <td> // <a href="/wiki/File:Stone2.png" class="image"> // <img alt="Stone2.png" src="/images/thumb/a/a0/Stone2.png/25px-Stone2.png" height="25" width="25"> // </a> // </td> // <td>1</td> // <td>01</td> // <td> // <a href="/wiki/Stone" title="Stone">Stone</a> // </td> //</tr> XmlReaderSettings xrs = new XmlReaderSettings(); xrs.ValidationType = ValidationType.None; xrs.ValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags.None; xrs.ConformanceLevel = ConformanceLevel.Auto; xrs.ProhibitDtd = false; xrs.XmlResolver = null; XmlDocument dom = new XmlDocument(); dom.XmlResolver = null; dom.Load(XmlReader.Create("http://www.minecraftwiki.net/wiki/Data_values",xrs)); foreach (XmlNode node in dom.GetElementsByTagName("tr")) { if (node.ChildNodes.Count == 4) { string imgurl,name; // Image, Decimal, Hex, Name // Yay xpath XmlElement img = (XmlElement)node.SelectSingleNode("/td[1]/a/img"); if(img==null) continue; XmlElement xNameParent = (XmlElement)node.SelectSingleNode("/td[4]"); if(xNameParent==null) continue; if (xNameParent.ChildNodes[0].Name == "a") name = xNameParent.ChildNodes[0].Value; else if (xNameParent.ChildNodes[0].Name == "i") name = xNameParent.ChildNodes[0].ChildNodes[0].Value; else continue; XmlElement xID = (XmlElement)node.SelectSingleNode("/td[2]"); if(xID==null) continue; imgurl = img.Attributes["src"].Value; // Load it up Block nb = new Block(); nb.ID = short.Parse(xID.Value); nb.Name = xID.InnerText; nb.FromImage = imgurl; short i = 0; if (Find(nb.Name) != null) { string type = (nb.ID < 255) ? " block" : " (item)"; nb.Name += type; if (Find(nb.Name) != null) { while (true) { string nm = nb.Name + " " + (++i).ToString(); if (Find(nm) == null) { nb.Name = nm; break; } } } } BlocksToDL.Enqueue(nb); TotalImages++; } } }
/// <summary> /// Update blocks from web. /// </summary> public static void UpdateBlocks() { WebClient wc = new WebClient(); string[] derp = wc.DownloadString("http://copy.mcft.net/mc/blocks/").Split(new string[]{"\n","\r\n"},StringSplitOptions.RemoveEmptyEntries); foreach (string line in derp) { if (line.StartsWith("<img src=\"/mc/icons/")) { string[] chunks = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); //Console.WriteLine(string.Join(", ", chunks)); // icon HEX DEC NAME //<img src="/mc/icons/0.png"/> 0 0 Air Block nb = new Block(); nb.ID = short.Parse(chunks[3]); nb.Name = string.Join(" ", chunks, 4, chunks.Length - 4); WebClient icondl = new WebClient(); BlocksToDL.Enqueue(nb); TotalImages++; } } }
/// <summary> /// Load blocks, update if needed. /// </summary> public static void Init() { if (!File.Exists("blocks.txt")) { frmUpdate up = new frmUpdate(); up.Start(); up.ShowDialog(); return; } MapGenerators.Init(); foreach(string line in File.ReadAllLines("blocks.txt")) { if (string.IsNullOrEmpty(line)) continue; if (line.StartsWith("#")) continue; //Console.WriteLine(line); // dec file color name string[] chunks = line.Split(new string[]{"\t"},StringSplitOptions.RemoveEmptyEntries); Block b = new Block(); short id = short.Parse(chunks[0]); b.ID = id; b.Name = chunks[2]; string bf = Path.Combine("blocks", string.Format("{0}.png", (short)id)); string if_ = Path.Combine("items", chunks[1]); string af = Path.Combine("blocks","0.png"); if (id<255 && File.Exists(bf)) b.Image = (Bitmap)Bitmap.FromFile(bf); else if (File.Exists(if_)) b.Image = (Bitmap)Bitmap.FromFile(if_); else b.Image = new Bitmap(16,16); b.Color = GetColorFor(b); BlockList.Add(id, b); #if DEBUG Console.WriteLine(b); #endif } SetupLighting(); }
public static Block Get(short type) { if (!BlockList.ContainsKey(type)) { Console.WriteLine("BlockList does not contain a definition for {0} (0x{0:X2}).", type); Block b = new Block(); b.Color = Color.Black; b.ID = type; b.Image = GetQuestionMark(); b.Name = "[UNKNOWN]"; return b; } return BlockList[type]; }
public bool SideVisible(Block adjacent) { return (adjacent == null || adjacent.DrawMode != DrawMode.Normal && !(adjacent.DrawMode > DrawMode.Leaves && adjacent==this)); }