コード例 #1
0
ファイル: WindowArea.cs プロジェクト: Imperceptus/Craft.Net
 protected internal virtual int MoveOrMergeItem(int index, Slot slot, WindowArea from)
 {
     int emptyIndex = -1;
     for (int i = 0; i < Length; i++)
     {
         if (this[i].Empty && emptyIndex == -1)
             emptyIndex = i;
         else if (this[i].Id == slot.Id &&
                  this[i].Metadata == slot.Metadata &&
                  this[i].Count < slot.Item.MaximumStack)
         {
             // Merging takes precedence over empty slots
             emptyIndex = -1;
             if (from != null)
                 from[index] = new Slot();
             if (this[i].Count + slot.Count > slot.Item.MaximumStack)
             {
                 slot.Count -= (byte)(slot.Item.MaximumStack - this[i].Count);
                 this[i].Count = slot.Item.MaximumStack;
                 continue;
             }
             this[i] = new Slot(slot.Id, (byte)(this[i].Count + slot.Count));
             return i;
         }
     }
     if (emptyIndex != -1)
     {
         if (from != null)
             from[index] = new Slot();
         this[emptyIndex] = slot;
     }
     return emptyIndex;
 }
コード例 #2
0
 public EntityEquipmentPacket(int entityId, EntityEquipmentSlot slot, Slot item)
 {
     EntityId = entityId;
     SlotIndex = (short)slot;
     Item = item;
     if (slot == 0 && item.Id != 0xFFFF)
         item.Id = 0xFFFF;
 }
コード例 #3
0
ファイル: Window.cs プロジェクト: ammaraskar/Craft.Net
 public Slot[] GetSlots()
 {
     int length = WindowAreas.Sum(area => area.Length);
     var slots = new Slot[length];
     foreach (var windowArea in WindowAreas)
         Array.Copy(windowArea.Items, 0, slots, windowArea.StartIndex, windowArea.Length);
     return slots;
 }
コード例 #4
0
ファイル: WindowArea.cs プロジェクト: Imperceptus/Craft.Net
 public WindowArea(int startIndex, int length)
 {
     StartIndex = startIndex;
     Length = length;
     Items = new Slot[Length];
     for (int i = 0; i < Items.Length; i++)
         Items[i] = new Slot();
 }
コード例 #5
0
 public SetSlotPacket(byte windowId, short index, Slot slot)
 {
     WindowId = windowId;
     Index = index;
     Slot = slot;
 }
コード例 #6
0
 public SetWindowItemsPacket(byte windowId, Slot[] slots)
 {
     WindowId = windowId;
     Slots = slots;
 }
コード例 #7
0
ファイル: WindowArea.cs プロジェクト: Imperceptus/Craft.Net
 /// <summary>
 /// Returns true if the specified slot is valid to
 /// be placed in this index.
 /// </summary>
 protected virtual bool IsValid(Slot slot, int index)
 {
     return true;
 }
コード例 #8
0
 public EntityEquipmentPacket(int entityId, EntityEquipmentSlot slot, Slot item)
 {
     EntityId = entityId;
     SlotIndex = (short)slot;
     Item = item;
 }
コード例 #9
0
ファイル: Slot.cs プロジェクト: Imperceptus/Craft.Net
 public static bool TryReadSlot(byte[] buffer, ref int offset, out Slot slot)
 {
     slot = new Slot();
     if (!DataUtility.TryReadUInt16(buffer, ref offset, out slot.id))
         return false;
     if (slot.Id == 0xFFFF)
         return true;
     if (!DataUtility.TryReadByte(buffer, ref offset, out slot.count))
         return false;
     if (!DataUtility.TryReadUInt16(buffer, ref offset, out slot.metadata))
         return false;
     short length = 0;
     if (!DataUtility.TryReadInt16(buffer, ref offset, out length))
         return false;
     if (length == -1)
         return true;
     byte[] compressed;
     if (!DataUtility.TryReadArray(buffer, length, ref offset, out compressed))
         return false;
     if (length != -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;
 }
コード例 #10
0
ファイル: Slot.cs プロジェクト: Imperceptus/Craft.Net
        /// <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;
        }
コード例 #11
0
ファイル: Slot.cs プロジェクト: Imperceptus/Craft.Net
 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;
     if (compound.Get<NbtCompound>("tag") != null)
     {
         s.Nbt = new NbtFile();
         s.Nbt.RootTag = compound.Get<NbtCompound>("tag");
     }
     return s;
 }
コード例 #12
0
ファイル: Slot.cs プロジェクト: pdelvo/Craft.Net
 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;
 }
コード例 #13
0
ファイル: Window.cs プロジェクト: ammaraskar/Craft.Net
 /// <summary>
 /// When shift-clicking items between areas, this method is used
 /// to determine which area links to which.
 /// </summary>
 /// <param name="index">The index of the area the item is coming from</param>
 /// <param name="slot">The item being moved</param>
 /// <returns>The area to place the item into</returns>
 protected abstract WindowArea GetLinkedArea(int index, Slot slot);
コード例 #14
0
ファイル: Block.cs プロジェクト: ammaraskar/Craft.Net
 public virtual bool GetDrop(ToolItem tool, out Slot[] drop)
 {
     drop = new[] { new Slot(this.Id, 1, this.Metadata) };
     return CanHarvest(tool);
 }