Exemple #1
0
 public override void FromBytes(BinaryReader reader, IWorldAccessor resolver)
 {
     collisionPos = Vec3d.CreateFromBytes(reader);
     stack        = new ItemStack();
     stack.FromBytes(reader);
     stack.ResolveBlockOrItem(resolver);
     quantity = reader.ReadInt32();
     radius   = reader.ReadSingle();
     scale    = reader.ReadSingle();
 }
        /// <summary>
        /// Creates a collection of slots from a tree.
        /// </summary>
        /// <param name="tree">The tree to build slots from</param>
        /// <param name="slots">pre-existing slots. (default: null)</param>
        /// <param name="modifiedSlots">Pre-modified slots. (default: null)</param>
        /// <returns></returns>
        public virtual ItemSlot[] SlotsFromTreeAttributes(ITreeAttribute tree, ItemSlot[] slots = null, List <ItemSlot> modifiedSlots = null)
        {
            if (tree == null)
            {
                return(slots);
            }

            if (slots == null || slots.Length != tree.GetInt("qslots"))
            {
                slots = new ItemSlot[tree.GetInt("qslots")];
                for (int i = 0; i < slots.Length; i++)
                {
                    slots[i] = NewSlot(i);
                }
            }

            for (int slotId = 0; slotId < slots.Length; slotId++)
            {
                ItemStack newstack = tree.GetTreeAttribute("slots")?.GetItemstack("" + slotId);
                ItemStack oldstack = slots[slotId].Itemstack;

                if (Api?.World == null)
                {
                    slots[slotId].Itemstack = newstack;
                    continue;
                }

                newstack?.ResolveBlockOrItem(Api.World);

                bool a = (newstack != null && !newstack.Equals(Api.World, oldstack));
                bool b = (oldstack != null && !oldstack.Equals(Api.World, newstack));

                bool didModify = a || b;

                slots[slotId].Itemstack = newstack;

                if (didModify && modifiedSlots != null)
                {
                    modifiedSlots.Add(slots[slotId]);
                }
            }



            return(slots);
        }