/// <summary> /// Reads the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <returns></returns> /// <remarks></remarks> public static ItemStack Read(BigEndianStream stream) { if (stream == null) throw new System.ArgumentNullException("stream"); var stack = new ItemStack(); if ((stack.ItemType = stream.ReadInt16()) >= 0) { stack.Count = stream.ReadByte(); stack.Durability = stream.ReadInt16(); } else return stack; if (((stream.Owner as PacketEndPoint).Version >=36 && stack.ItemType != -1) || (EnchantHelper.Enchantable.Contains(stack.ItemType) && !((stream.Owner as PacketEndPoint).Use12w18aFix && !(_12w18a.Contains(stack.ItemType)))))//12w18a fix { short hasData = stream.ReadInt16(); if (hasData > 0) { stack.AdditionalData = stream.ReadBytes(hasData); } } if (stack.AdditionalData == null) stack.AdditionalData = new byte[0]; return stack; }
/// <summary> /// Receives the specified reader. /// </summary> /// <param name="reader"> The reader. </param> /// <param name="version"> The version. </param> /// <remarks> /// </remarks> protected override void OnReceive(BigEndianStream reader, int version) { if (reader == null) throw new ArgumentNullException("reader"); Slot = reader.ReadInt16 (); Item = ItemStack.Read(reader); }
/// <summary> /// Receives the specified reader. /// </summary> /// <param name="reader">The reader.</param> /// <param name="version">The version.</param> /// <remarks></remarks> protected override void OnReceive(BigEndianStream reader, int version) { if (reader == null) throw new System.ArgumentNullException("reader"); WindowId = reader.ReadByte(); Slot = reader.ReadInt16(); RightClick = reader.ReadByte(); ActionNumber = reader.ReadInt16(); Shift = reader.ReadBoolean(); Item = ItemStack.Read(reader); }
/// <summary> /// Receives the specified reader. /// </summary> /// <param name="reader"> The reader. </param> /// <param name="version"> The version. </param> /// <remarks> /// </remarks> protected override void OnReceive(BigEndianStream reader, int version) { if (reader == null) throw new ArgumentNullException("reader"); EntityId = reader.ReadInt32 (); Slot = reader.ReadInt16 (); if (version >= 35) { Stack = ItemStack.Read(reader); } else { Stack = new ItemStack { ItemType = reader.ReadInt16 (), Durability = reader.ReadInt16 (), AdditionalData = new byte[0], Count = 1 }; } }
/// <summary> /// Writes the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <param name="stack">The stack.</param> /// <remarks></remarks> public static void Write(BigEndianStream stream, ItemStack stack) { if (stream == null) throw new System.ArgumentNullException("stream"); if ((stack == null)) stack = new ItemStack { ItemType = 0 }; stream.Write(stack.ItemType); if (stack.ItemType >= 0) { stream.Write(stack.Count); stream.Write(stack.Durability); } if (((stream.Owner as PacketEndPoint).Version >= 36 && stack.ItemType != -1) || (EnchantHelper.Enchantable.Contains(stack.ItemType) && !((stream.Owner as PacketEndPoint).Use12w18aFix && !(_12w18a.Contains(stack.ItemType)))))//12w18a fix { short hasData = stack.AdditionalData == null ? (short)0 : (short)stack.AdditionalData.Count(); if (hasData > 0) { stream.Write(hasData); stream.Write(stack.AdditionalData.ToArray()); } else { stream.Write((short)-1); } } }
/// <summary> /// Initializes a new instance of the <see cref="EntityEquipment" /> class. /// </summary> /// <remarks> /// </remarks> public EntityEquipment() { Code = 0x05; Stack = new ItemStack (); }
/// <summary> /// Writes the specified stream. /// </summary> /// <param name="stream"> The stream. </param> /// <param name="data"> The data. </param> /// <remarks> /// </remarks> public static void Write(this BigEndianStream stream, ItemStack data) { ItemStack.Write(stream, data); }
/// <summary> /// Initializes a new instance of the <see cref="PickupSpawn" /> class. /// </summary> /// <remarks> /// </remarks> public PickupSpawn() { Code = 0x15; Item = new ItemStack (); }
/// <summary> /// Receives the specified reader. /// </summary> /// <param name="reader"> The reader. </param> /// <param name="version"> The version. </param> /// <remarks> /// </remarks> protected override void OnReceive(BigEndianStream reader, int version) { if (reader == null) throw new ArgumentNullException("reader"); EntityId = reader.ReadInt32 (); if (version >= 41) Item = ItemStack.Read(reader); else { Item = new ItemStack { ItemType = reader.ReadInt16 (), Count = reader.ReadByte (), Durability = reader.ReadInt16 (), AdditionalData = new byte[0] }; } PositionX = reader.ReadInt32 (); PositionY = reader.ReadInt32 (); PositionZ = reader.ReadInt32 (); Rotation = reader.ReadByte (); Pitch = reader.ReadByte (); Roll = reader.ReadByte (); }