Represents an inventory slot.
Esempio n. 1
0
        protected void ReadSlotData()
        {
            /* short[] enchantable = {
                0x103, //#Flint and steel
                0x105, //#Bow
                0x15A, //#Fishing rod
                0x167, //#Shears

                //#TOOLS
                //#sword, shovel, pickaxe, axe, hoe
                0x10C, 0x10D, 0x10E, 0x10F, //0x122, //#WOOD
                0x110, 0x111, 0x112, 0x113, //0x123, //#STONE
                0x10B, 0x100, 0x101, 0x102, //0x124, //#IRON
                0x114, 0x115, 0x116, 0x117, //0x125, //#DIAMOND
                0x11B, 0x11C, 0x11D, 0x11E, //0x126, //#GOLD

                //#ARMOUR
                //#helmet, chestplate, leggings, boots
                0x12A, 0x12B, 0x12C, 0x12D, //#LEATHER
                0x12E, 0x12F, 0x130, 0x131, //#CHAIN
                0x132, 0x133, 0x134, 0x135, //#IRON
                0x136, 0x137, 0x138, 0x139, //#DIAMOND
                0x13A, 0x13B, 0x13C, 0x14D  //#GOLD
            };
            short itemID = Short;
            if (itemID != -1)
            {
                sbyte cnt = SByte;
                short Damage = Short;
                //if (enchantable.Contains(itemID))
                //{
                    short tmp = Short;
                    if (tmp != -1)
                    {
                        ReadSTUB( tmp);
                    }
                //}
             }
            */
            Slot slot = new Slot();
            Slot.ReadSlot(str);
        }
Esempio n. 2
0
        /// <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)
        {
            Slot s = new Slot();
            s.Id = ReadShort(stream);
            if (s.Id == -1)
                return s;
            s.Count = (byte)stream.ReadByte();
            s.Metadata = ReadShort(stream);

            short length = ReadShort(stream);
            if (length != -1)
            {
                byte[] compressed = new byte[length];
                stream.Read(compressed, 0, length);
                MemoryStream output = new MemoryStream();
                GZipStream 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;
        }
Esempio n. 3
0
 public static void WriteSlot(Stream stream, Slot s)
 {
     WriteShort(stream, s.Id);
     if (s.Id == -1)
         return;
     stream.WriteByte(s.Count);
     WriteShort(stream, s.Metadata);
     MemoryStream output = new MemoryStream();
     MemoryStream nbt = new MemoryStream();
     s.Nbt.SaveFile(output);
     GZipStream gzs = new GZipStream(nbt, CompressionMode.Compress, true);
     gzs.CopyTo(output);
     gzs.Close();
     nbt.Close();
     WriteShort(stream, (short)output.Length);
     output.CopyTo(stream);
     output.Close();
 }
Esempio n. 4
0
 public static bool TryReadSlot(byte[] buffer, ref int offset, out Slot slot)
 {
     slot = new Slot();
     if (!Packet.TryReadShort(buffer, ref offset, out slot.Id))
         return false;
     if (slot.Id == -1)
         return true;
     if (!Packet.TryReadByte(buffer, ref offset, out slot.Count))
         return false;
     if (!Packet.TryReadShort(buffer, ref offset, out slot.Metadata))
         return false;
     short length = 0;
     if (!Packet.TryReadShort(buffer, ref offset, out length))
         return false;
     if (length == -1)
         return true;
     byte[] compressed = new byte[length];
     if (!Packet.TryReadArray(buffer, length, ref offset, out compressed))
         return false;
     if (length != -1)
     {
         MemoryStream output = new MemoryStream();
         GZipStream 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;
 }