public BlockUpdate(Vector3Int chunk, Vector3Int local, uint Block, uint Reason, BinaryTagNode meta) { ChunkPos = chunk; X = local.X; Y = local.Y; Z = local.Z; BlockID = Block; this.Reason = Reason; Metadata = meta; }
public BlockUpdate(Vector3Int chunk, int X, int Y, int Z, uint Block, uint Reason, BinaryTagNode meta) { ChunkPos = chunk; this.X = X; this.Y = Y; this.Z = Z; BlockID = Block; this.Reason = Reason; Metadata = meta; }
public BlockUpdate(Vector3Int chunk, Vector3Int local, uint Block, uint Reason) { ChunkPos = chunk; X = local.X; Y = local.Y; Z = local.Z; BlockID = Block; this.Reason = Reason; Metadata = null; }
public BlockUpdate(Vector3Int chunk, int X, int Y, int Z, uint Block, uint Reason) { ChunkPos = chunk; this.X = X; this.Y = Y; this.Z = Z; BlockID = Block; this.Reason = Reason; Metadata = null; }
//TODO: Packet to Stream ; Packet from Stream #region Serialization / Deserialization #region BinaryTagNode <=> File Conversion public static BinaryTagNode DeseralizeFromFile(string binaryFile) { BinaryTagNode toReturn; if (File.Exists(binaryFile)) { using (Stream stream = File.Open(binaryFile, FileMode.Open)) { using (var decompressor = new GZipStream(stream, CompressionMode.Decompress)) { //var binaryFormatter = new BinaryFormatter(); //binaryFormatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; //toReturn = (BinaryTagNode)binaryFormatter.Deserialize(decompressor); toReturn = Serializer.Deserialize <BinaryTagNode>(decompressor); } } } else { toReturn = new BinaryTagNode(); } return(toReturn); }
public static void SerializeToFile(string outputFile, BinaryTagNode nodes) { //Ensure the directory exists if (!Directory.Exists(Path.GetDirectoryName(outputFile))) { Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); } using (Stream stream = File.Open(outputFile, FileMode.Create)) { using (var compressor = new GZipStream(stream, CompressionMode.Compress)) { using (var memStream = new MemoryStream()) { //BinaryFormatter formatter = new BinaryFormatter(); //formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; //formatter.Serialize(compressor, nodes); Serializer.Serialize(compressor, nodes); } } stream.Close(); } }
public void LoadChunks() { //TODO: Deserialize //ROADMAP: // // Get chunks folder // Get level data // Get player position // Apply level data // Get chunk at player pos // Read // Update => if(chunkManager.ChunkCount < ChunkThreshold) { return; } #region World Data BinaryTagNode levelData = FileUtil.DeseralizeFromFile(Path.Combine(WorldDirectory, "level.dat")); if (levelData.Type == TagType.TagEnd) { Logger.error(-1, "The file \"" + Path.Combine(WorldDirectory, "level.dat") + "\" doesn't exist, or is malformed!"); } if (levelData.Type == TagType.TagMultiple) { try { BinaryTagNodeMultiple levelRoot = (BinaryTagNodeMultiple)levelData; #region Player state BinaryTagNodeMultiple playerTag = (BinaryTagNodeMultiple)levelRoot.Get("player"); BinaryTagNodeMultiple playerPosTag = (BinaryTagNodeMultiple)playerTag.Get("position"); BinaryTagNodeMultiple playerRotTag = (BinaryTagNodeMultiple)playerTag.Get("rotation"); player.position.X = ((BinaryTagNodeFloat)playerPosTag.Get("X")).Value; player.position.Y = ((BinaryTagNodeFloat)playerPosTag.Get("Y")).Value; player.position.Z = ((BinaryTagNodeFloat)playerPosTag.Get("Z")).Value; player.camera.Pitch = ((BinaryTagNodeFloat)playerRotTag.Get("X")).Value; player.camera.Yaw = ((BinaryTagNodeFloat)playerRotTag.Get("Y")).Value; player.camera.Roll = ((BinaryTagNodeFloat)playerRotTag.Get("Z")).Value; player.HeldSlot = ((BinaryTagNodeByte)playerTag.Get("inventorySlot")).Value; //TODO: Deserialize inventory #endregion seed = ((BinaryTagNodeLong)levelRoot.Get("seed")).Value; } catch (Exception ex) { Logger.error(-1, "MalformedBinaryTagNodeException:\n" + ex.StackTrace); } } #endregion #region Chunks string chunkFolder = Path.Combine(WorldDirectory, "chunks"); if (Directory.Exists(chunkFolder)) { string[] fileEntries = Directory.GetFiles(chunkFolder, "*.cnk"); for (int i = 0; i < fileEntries.Length; i++) { //TODO: loop through chunks folder BinaryTagNode chunkData = FileUtil.DeseralizeFromFile(fileEntries[i]); if (chunkData.Type == TagType.TagEnd) { Logger.error(-1, "The file \"" + Path.Combine(chunkFolder, "level.dat") + "\" doesn't exist, or is malformed!"); } if (chunkData.Type == TagType.TagMultiple) { try { var chunkRoot = (BinaryTagNodeMultiple)chunkData; var chunkX = ((BinaryTagNodeInt)chunkRoot.Get("X")); var chunkY = ((BinaryTagNodeInt)chunkRoot.Get("Y")); var chunkZ = ((BinaryTagNodeInt)chunkRoot.Get("Z")); if (chunkX != null && chunkY != null && chunkZ != null) { var hash = Chunk.GetHash(chunkX.Value, chunkY.Value, chunkZ.Value); if (chunks.ContainsKey(hash)) { chunks[hash].PopulateFromBinaryTag(chunkRoot); } } } catch (Exception ex) { Logger.error(-1, "MalformedBinaryTagNodeException:\n" + ex.StackTrace); } } } } #endregion }