Exemple #1
0
        private void OnSlotModified(string playerID, ItemSlot activeHotbarSlot, int index)
        {
            Console.WriteLine("OnSlotModified");
            TestMod          mod = api.ModLoader.GetModSystem <TestMod>();
            SeedBagInventory inventory;

            mod.seedBagInventories.TryGetValue(playerID, out inventory);
            if (!(inventory is null))
            {
                inventory.SyncToSeedBag();
            }
        }
Exemple #2
0
        private void OnCloseInventory(IPlayer player)
        {
            Console.WriteLine("OnCloseInventory");
            TestMod          mod = api.ModLoader.GetModSystem <TestMod>();
            SeedBagInventory inventory;

            mod.seedBagInventories.TryGetValue(player.PlayerUID, out inventory);
            if (!(inventory is null))
            {
                inventory.SyncToSeedBag();
                mod.seedBagInventories.Remove(player.PlayerUID);
            }
        }
Exemple #3
0
        private void OpenSeedBagGui(ItemSlot slot, EntityAgent byEntity)
        {
            SeedBagInventory inventory = new SeedBagInventory("seedbagInv", "id", api, slot);

            inventory.SyncFromSeedBag();
            inventory.ResolveBlocksOrItems();
            inventory.OnInventoryClosed += OnCloseInventory;
            IPlayer player = (byEntity as EntityPlayer).Player;

            TestMod mod = api.ModLoader.GetModSystem <TestMod>();

            mod.seedBagInventories.Add(player.PlayerUID, inventory);
            inventory.SlotModified += index => OnSlotModified(player.PlayerUID, player.InventoryManager.ActiveHotbarSlot, index);

            player.InventoryManager.OpenInventory(inventory);

            if (byEntity.World is IClientWorldAccessor)
            {
                GuiSeedBag guiSeedBag = new GuiSeedBag(api as ICoreClientAPI, inventory, slot);
                guiSeedBag.TryOpen();
            }
        }