public override bool TryReadEntry(byte[] buffer, ref int offset, int length) { if (buffer.Length - offset < 6) return false; offset++; ushort id, metadata; byte count; if (!DataUtility.TryReadUInt16(buffer, ref offset, length, out id)) return false; if (!DataUtility.TryReadByte(buffer, ref offset, length, out count)) return false; if (!DataUtility.TryReadUInt16(buffer, ref offset, length, out metadata)) return false; Value = new Slot(id, count, metadata); return true; }
public static bool TryReadSlot(byte[] buffer, ref int offset, int length, out Slot slot) { slot = new Slot(); if (!DataUtility.TryReadUInt16(buffer, ref offset, length, out slot.Id)) return false; if (slot.Id == 0xFFFF) return true; if (!DataUtility.TryReadByte(buffer, ref offset, length, out slot.Count)) return false; if (!DataUtility.TryReadUInt16(buffer, ref offset, length, out slot.Metadata)) return false; short nbtLength = 0; if (!DataUtility.TryReadInt16(buffer, ref offset, length, out nbtLength)) return false; if (nbtLength == -1) return true; var compressed = new byte[nbtLength]; if (!DataUtility.TryReadArray(buffer, ref offset, length, out compressed, nbtLength)) return false; if (nbtLength != -1) { var output = new MemoryStream(); var gzs = new GZipStream(new MemoryStream(compressed), CompressionMode.Decompress, false); gzs.CopyTo(output); gzs.Close(); slot.Nbt = new NbtFile(); slot.Nbt.LoadFile(output, false); } return true; }
/// <summary> /// Reads a slot from the given stream. /// </summary> /// <param name="stream">The stream to read from.</param> /// <returns></returns> /// <remarks></remarks> public static Slot ReadSlot(Stream stream) { var s = new Slot(); s.Id = ReadUShort(stream); if (s.Id == 0xFFFF) return s; s.Count = (byte)stream.ReadByte(); s.Metadata = ReadUShort(stream); short length = ReadShort(stream); if (length != -1) { var compressed = new byte[length]; stream.Read(compressed, 0, length); var output = new MemoryStream(); var gzs = new GZipStream(new MemoryStream(compressed), CompressionMode.Decompress, false); gzs.CopyTo(output); gzs.Close(); s.Nbt = new NbtFile(); s.Nbt.LoadFile(output, false); } return s; }
public static Slot FromNbt(NbtCompound compound) { var s = new Slot(); s.Id = (ushort)compound.Get<NbtShort>("id").Value; s.Metadata = (ushort)compound.Get<NbtShort>("Damage").Value; s.Count = compound.Get<NbtByte>("Count").Value; s.Index = compound.Get<NbtByte>("Slot").Value; return s; }
public MetadataSlot(byte index, Slot value) : base(index) { Value = value; }