コード例 #1
0
        public override bool TryGiveItemStack(ItemStack itemstack)
        {
            if (itemstack == null || itemstack.StackSize == 0)
            {
                return(false);
            }

            ItemSlot dummySlot = new DummySlot(null);

            dummySlot.Itemstack = itemstack.Clone();

            ItemStackMoveOperation op = new ItemStackMoveOperation(World, EnumMouseButton.Left, 0, EnumMergePriority.AutoMerge, itemstack.StackSize);

            WeightedSlot wslot = inv.GetBestSuitedSlot(dummySlot, new List <ItemSlot>());

            if (wslot.weight > 0)
            {
                dummySlot.TryPutInto(wslot.slot, ref op);
                itemstack.StackSize -= op.MovedQuantity;
                WatchedAttributes.MarkAllDirty();
                return(op.MovedQuantity > 0);
            }

            return(false);
        }
コード例 #2
0
        public static void Sort(this IInventory activeInv, ICoreAPI api, EnumSortMode mode)
        {
            if (api == null || activeInv == null)
            {
                return;
            }
            string name = activeInv.ClassName;

            if (name == "basket" || name == "chest" || name == "hotbar" || name == "backpack")
            {
                List <ItemStack> objects = activeInv.SortArr(mode);

                for (int j = 0; j < activeInv.Count; j++)
                {
                    if (activeInv[j] is ItemSlotOffhand)
                    {
                        continue;
                    }

                    if (activeInv[j].Itemstack != null)
                    {
                        if (activeInv[j].Itemstack.Attributes["backpack"] != null)
                        {
                            continue;
                        }

                        activeInv[j].TakeOutWhole();
                    }
                    for (int o = objects.Count; o-- > 0;)
                    {
                        ItemStackMoveOperation op = new ItemStackMoveOperation(api.World, EnumMouseButton.Left, 0, EnumMergePriority.AutoMerge, 1);
                        DummySlot slot            = new DummySlot(objects[o]);

                        slot.TryPutInto(activeInv[j], ref op);
                        if (op.MovedQuantity > 0)
                        {
                            objects.RemoveAt(o);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }