Exemple #1
0
 public void StartSort(IPlayer player, EnumSortMode mode, string invstring)
 {
     if (invstring != "")
     {
         IInventory inv = player.InventoryManager.GetInventory(invstring);
         Sort(player, mode, inv);
     }
     else
     {
         for (int i = 0; i < player.InventoryManager.OpenedInventories.Count; i++)
         {
             Sort(player, mode, player.InventoryManager.OpenedInventories[i]);
         }
     }
 }
Exemple #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;
                        }
                    }
                }
            }
        }
Exemple #3
0
        public static ItemStack[] SortArr(this ItemStack[] arr, EnumSortMode mode)
        {
            switch (mode)
            {
            case EnumSortMode.Dictionary:
                Array.Sort(arr, delegate(ItemStack a, ItemStack b) { return(Lang.Get(b.Collectible.Code.ToString()).CompareTo(Lang.Get(a.Collectible.Code.ToString()))); });
                break;

            case EnumSortMode.ID:
                Array.Sort(arr, delegate(ItemStack a, ItemStack b) { return(b.Collectible.Id.CompareTo(a.Collectible.Id)); });
                break;

            case EnumSortMode.Code:
                Array.Sort(arr, delegate(ItemStack a, ItemStack b) { return(b.Collectible.Code.ToString().CompareTo(a.Collectible.Code.ToString())); });
                break;
            }

            return(arr);
        }
Exemple #4
0
 public static List <ItemStack> SortArr(this IInventory inv, EnumSortMode mode) => inv.ToItemStacks().SortArr(mode).ToList();