private void UpdatePosition() { NbtFile PlayerDat = new NbtFile(this.Server.ServerDirectory + "\\world\\players\\" + this.Username + ".dat"); PlayerDat.LoadFile(); this._position.x = PlayerDat.Query<LibNbt.Tags.NbtDouble>("//Pos/0").Value; this._position.y = PlayerDat.Query<LibNbt.Tags.NbtDouble>("//Pos/1").Value; this._position.z = PlayerDat.Query<LibNbt.Tags.NbtDouble>("//Pos/2").Value; PlayerDat.Dispose(); }
public static void Init() { if (File.Exists(".luf")) { foreach (string f in File.ReadAllLines(".luf")) { if(File.Exists(f)) LastUsedFiles.Push(f); } } if (File.Exists(".settings")) { try { NbtFile f = new NbtFile(".settings"); f.LoadFile(); ShowGridLines = f.RootTag.Get<NbtByte>("GridLines").Value == 0x01 ? true : false; ShowChunks = f.RootTag.Get<NbtByte>("ShowChunks").Value == 0x01 ? true : false; ShowMapIcons = f.RootTag.Get<NbtByte>("ShowMapIcons").Value == 0x01 ? true : false; ShowWaterDepth = f.RootTag.Get<NbtByte>("ShowWaterDepth").Value == 0x01 ? true : false; f.Dispose(); } catch (Exception) { Save(); } } }
public static void Save() { File.WriteAllLines(".luf", LastUsedFiles.ToArray()); NbtFile f = new NbtFile(); f.RootTag.Add("GridLines",new NbtByte("GridLines", (byte) (ShowGridLines ? 0x01 : 0x00))); f.RootTag.Add("ShowChunks",new NbtByte("ShowChunks", (byte) (ShowChunks ? 0x01 : 0x00))); f.RootTag.Add("ShowMapIcons",new NbtByte("ShowMapIcons", (byte) (ShowMapIcons ? 0x01 : 0x00))); f.RootTag.Add("ShowWaterDepth",new NbtByte("ShowWaterDepth", (byte) (ShowWaterDepth ? 0x01 : 0x00))); f.SaveFile(".settings"); f.Dispose(); }
public static void test(Player player, Command cmd) { if (!File.Exists("C:/users/jb509/desktop/1.schematic")) { player.Message("Nop"); return; } NbtFile file = new NbtFile("C:/users/jb509/desktop/1.schematic"); file.RootTag = new NbtCompound("Schematic"); file.LoadFile(); bool notClassic = false; short width = file.RootTag.Query<NbtShort>("/Schematic/Width").Value; short height = file.RootTag.Query<NbtShort>("/Schematic/Height").Value; short length = file.RootTag.Query<NbtShort>("/Schematic/Length").Value; Byte[] blocks = file.RootTag.Query<NbtByteArray>("/Schematic/Blocks").Value; Vector3I pos = player.Position.ToBlockCoords(); int i = 0; player.Message("&SDrawing Schematic ({0}x{1}x{2})", length, width, height); for (int x = pos.X; x < width + pos.X; x++) { for (int y = pos.Y; y < length + pos.Y; y++) { for (int z = pos.Z; z < height + pos.Z; z++) { if (Enum.Parse(typeof(Block), ((Block)blocks[i]).ToString(), true) != null) { if (!notClassic && blocks[i] > 49) { notClassic = true; player.Message("&WSchematic used is not designed for Minecraft Classic;" + " Converting all unsupported blocks with air"); } if (blocks[i] < 50) { player.WorldMap.QueueUpdate(new BlockUpdate(null, (short)x, (short)y, (short)z, (Block)blocks[i])); } } i++; } } } file.Dispose(); }
private void button8_Click_1(object sender, EventArgs e) { NbtFile PlayerDat = new NbtFile(YAMS.Core.RootFolder + "\\servers\\1\\world\\players\\bigolslabomeat.dat"); PlayerDat.LoadFile(); Vector _position; _position.x = PlayerDat.Query<LibNbt.Tags.NbtDouble>("//Pos/0").Value; _position.y = PlayerDat.Query<LibNbt.Tags.NbtDouble>("//Pos/1").Value; _position.z = PlayerDat.Query<LibNbt.Tags.NbtDouble>("//Pos/2").Value; PlayerDat.Dispose(); MessageBox.Show("x:" + _position.x.ToString() + " y:" + _position.y.ToString() + " z:" + _position.z.ToString()); }
public Vector2i GetChunkCoordsFromFile(string file,bool test) { Vector2i r = new Vector2i(0, 0); // cX.Y.dat // X.Y.dat string[] peices =Path.GetFileName(file.Substring(1)).Split('.'); long X; long Y; Radix.Decode(peices[0],36,out X); Radix.Decode(peices[1],36,out Y); r.X = (int)X; r.Y = (int)Y; if (test) { NbtFile f = new NbtFile(file); try { f.LoadFile(); } catch (Exception e) { if (CorruptChunk != null) CorruptChunk(X,Y,e.ToString(), file); return null; } NbtCompound Level = (NbtCompound)f.RootTag["Level"]; Vector2i t = new Vector2i(0, 0); t.X = (Level["xPos"] as NbtInt).Value; t.Y = (Level["zPos"] as NbtInt).Value; f.Dispose(); if (t != r) throw new Exception("Test failed."); } return r; }
public void ForEachChunk(Chunk.ChunkModifierDelegate cmd) { string[] f = Directory.GetFiles(mFolder,"c*.*.dat",SearchOption.AllDirectories); int Complete=0; foreach (string file in f) { if (ForEachProgress != null) ForEachProgress(f.Length, Complete++); //Console.WriteLine(Path.GetExtension(file)); if (Path.GetExtension(file) == "dat") continue; if (file.EndsWith(".genlock")) continue; NbtFile nf = new NbtFile(file); try { nf.LoadFile(); NbtCompound Level = (NbtCompound)nf.RootTag["Level"]; long x = (Level["xPos"] as NbtInt).Value; long y = (Level["zPos"] as NbtInt).Value; nf.Dispose(); cmd(x, y); } catch (Exception e) { if (CorruptChunk != null) { Vector2i pos = GetChunkCoordsFromFile(file); CorruptChunk(pos.X,pos.Y,"[" + Complete.ToString() + "]" + e.ToString(), file); } // continue; } } // This MUST be done. ForEachProgress = null; }
public Chunk NewChunk(long X, long Y) { NbtCompound c = NewNBTChunk(X, Y); string f = GetChunkFilename((int)X, (int)Y); // Create folder first. string d = Path.GetDirectoryName(f); if(!Directory.Exists(d)) Directory.CreateDirectory(d); // Get around crash where Windows doesn't like creating new files in Write mode for some f*****g stupid reason { FileInfo fi = new FileInfo(f); FileStream fs = fi.Create(); fs.Close(); } // Create the damn file. NbtFile cf = new NbtFile(f); cf.RootTag = c; cf.SaveFile(f); cf.Dispose(); // Pray. return GetChunk(X, Y); }
internal override Vector2i _GetChunkCoordsFromFile(string file) { Vector2i r = new Vector2i(0, 0); NbtFile f = new NbtFile(file); try { f.LoadFile(); } catch (Exception e) { if (CorruptChunk != null) CorruptChunk(0,0,e.ToString(), file); return null; } NbtCompound Level = (NbtCompound)f.RootTag["Level"]; Vector2i t = new Vector2i(0, 0); r.X = (Level["xPos"] as NbtInt).Value; r.Y = (Level["zPos"] as NbtInt).Value; f.Dispose(); return r; }