internal override bool ReadTag(NbtBinaryReader readStream) { if (readStream.Selector != null && !readStream.Selector(this)) { readStream.ReadInt16(); return(false); } Value = readStream.ReadInt16(); return(true); }
public void Import(byte[] data) { using (var stream = new MemoryStream(data)) { var reader = new NbtBinaryReader(stream, false); Health = reader.ReadInt32(); Air = reader.ReadInt16(); FireTick = reader.ReadInt32(); IsOnFire = reader.ReadBoolean(); } }
public static ChunkColumn DecocedChunkColumn(byte[] buffer) { lock (_chunkRead) { MemoryStream stream = new MemoryStream(buffer); { NbtBinaryReader defStream = new NbtBinaryReader(stream, true); Log.Debug("New chunk column"); int count = defStream.ReadByte(); if (count < 1) { Log.Warn("Nothing to read"); return(null); } if (count > 1) { Log.Debug($"Reading {count} sections"); } else { Log.Debug($"Reading {count} sections"); } ChunkColumn chunkColumn = new ChunkColumn(); for (int s = 0; s < count; s++) { int idx = defStream.ReadByte(); Log.Debug($"New section {s}, index={idx}"); Chunk chunk = chunkColumn.chunks[s]; int chunkSize = 16 * 16 * 16; defStream.Read(chunk.blocks, 0, chunkSize); //Log.Debug($"Blocks1:\n{Package.HexDump(chunk.blocks)}"); if (defStream.Read(chunk.metadata.Data, 0, chunkSize / 2) != chunkSize / 2) { Log.Error($"Out of data: metadata"); } //Log.Debug($"metadata:\n{Package.HexDump(chunk.metadata.Data)}"); if (defStream.Read(chunk.skylight.Data, 0, chunkSize / 2) != chunkSize / 2) { Log.Error($"Out of data: skylight"); } //Log.Debug($"skylight:\n{Package.HexDump(chunk.skylight.Data)}"); if (defStream.Read(chunk.blocklight.Data, 0, chunkSize / 2) != chunkSize / 2) { Log.Error($"Out of data: blocklight"); } //Log.Debug($"blocklight:\n{Package.HexDump(chunk.blocklight.Data)}"); //Log.Debug($"skylight.Data:\n{Package.HexDump(chunk.skylight.Data, 64)}"); //Log.Debug($"blocklight.Data:\n{Package.HexDump(chunk.blocklight.Data)}"); //byte[] ints = new byte[256*4]; //var readLen = defStream.Read(ints, 0, ints.Length); //if (readLen != ints.Length) Log.Error($"Out of data biomeColors, read lenght {readLen}"); //Log.Debug($"biomeColor (pre):\n{Package.HexDump(ints)}"); //return null; //int j = 0; //for (int i = 0; i < ints.Length; i = i + 4) //{ // chunk.biomeId[j] = ints[i]; // chunk.biomeColor[j++] = BitConverter.ToInt32(new[] {(byte) 0, ints[i + 1], ints[i + 2], ints[i + 3]}, 0); //} //Log.Debug($"biomeId (post):\n{Package.HexDump(chunk.biomeId)}"); //if (stream.Position >= stream.Length - 1) return chunk; ////return chunk; //return chunk; } //if (stream.Position >= stream.Length - 1) continue; if (defStream.Read(chunkColumn.height, 0, 256 * 2) != 256 * 2) { Log.Error($"Out of data height"); } //Log.Debug($"Heights:\n{Package.HexDump(chunk.height)}"); //if (stream.Position >= stream.Length - 1) continue; if (defStream.Read(chunkColumn.biomeId, 0, 256) != 256) { Log.Error($"Out of data biomeId"); } //Log.Debug($"biomeId:\n{Package.HexDump(chunk.biomeId)}"); //if (stream.Position >= stream.Length - 1) continue; int borderBlock = VarInt.ReadSInt32(stream); if (borderBlock != 0) { Log.Warn($"??? Got borderblock {borderBlock}"); } int extraCount = VarInt.ReadSInt32(stream); if (extraCount != 0) { //Log.Warn($"Got extradata\n{Package.HexDump(defStream.ReadBytes(extraCount*10))}"); for (int i = 0; i < extraCount; i++) { var hash = VarInt.ReadSInt32(stream); var blockData = defStream.ReadInt16(); Log.Warn($"Got extradata: hash=0x{hash:X2}, blockdata=0x{blockData:X2}"); } } if (stream.Position < stream.Length - 1) { //Log.Debug($"Got NBT data\n{Package.HexDump(defStream.ReadBytes((int) (stream.Length - stream.Position)))}"); while (stream.Position < stream.Length) { NbtFile file = new NbtFile() { BigEndian = false, UseVarInt = true }; file.LoadFromStream(stream, NbtCompression.None); Log.Debug($"Blockentity: {file.RootTag}"); } } if (stream.Position < stream.Length - 1) { Log.Warn($"Still have data to read\n{Package.HexDump(defStream.ReadBytes((int)(stream.Length - stream.Position)))}"); } } return(new ChunkColumn()); } }
internal override void SkipTag(NbtBinaryReader readStream) { readStream.ReadInt16(); }
public static ChunkColumn DecocedChunkColumn(byte[] buffer) { MemoryStream stream = new MemoryStream(buffer); { NbtBinaryReader defStream = new NbtBinaryReader(stream, true); ChunkColumn chunk = new ChunkColumn(); //chunk.x = IPAddress.NetworkToHostOrder(defStream.ReadInt32()); //chunk.z = IPAddress.NetworkToHostOrder(defStream.ReadInt32()); int chunkSize = 16 * 16 * 128; defStream.Read(chunk.blocks, 0, chunkSize); defStream.Read(chunk.metadata.Data, 0, chunkSize / 2); defStream.Read(chunk.skylight.Data, 0, chunkSize / 2); defStream.Read(chunk.blocklight.Data, 0, chunkSize / 2); //Log.Debug($"skylight.Data:\n{Package.HexDump(chunk.skylight.Data, 64)}"); //Log.Debug($"blocklight.Data:\n{Package.HexDump(chunk.blocklight.Data)}"); defStream.Read(chunk.height, 0, 256); //Log.Debug($"Heights:\n{Package.HexDump(chunk.height)}"); byte[] ints = new byte[256 * 4]; defStream.Read(ints, 0, ints.Length); //Log.Debug($"biomeColor (pre):\n{Package.HexDump(ints)}"); int j = 0; for (int i = 0; i < ints.Length; i = i + 4) { chunk.biomeId[j] = ints[i]; chunk.biomeColor[j++] = BitConverter.ToInt32(new[] { (byte)0, ints[i + 1], ints[i + 2], ints[i + 3] }, 0); } //Log.Debug($"biomeId (post):\n{Package.HexDump(chunk.biomeId)}"); if (stream.Position >= stream.Length - 1) { return(chunk); } //return chunk; int extraSize = defStream.ReadInt16(); if (extraSize != 0) { Log.Debug($"Got extradata\n{Package.HexDump(defStream.ReadBytes(extraSize))}"); } if (stream.Position >= stream.Length - 1) { return(chunk); } //Log.Debug($"Got NBT data\n{Package.HexDump(defStream.ReadBytes((int) (stream.Length - stream.Position)))}"); while (stream.Position < stream.Length) { NbtFile file = new NbtFile() { BigEndian = false, UseVarInt = true }; file.LoadFromStream(stream, NbtCompression.None); //Log.Debug($"Blockentity: {file.RootTag}"); } return(chunk); } }
internal override bool ReadTag(NbtBinaryReader readStream) { if (readStream.Selector != null && !readStream.Selector(this)) { readStream.ReadInt16(); return false; } Value = readStream.ReadInt16(); return true; }