public GuiSeedBag(ICoreClientAPI api, SeedBagInventory inventory, ItemSlot slot) : base(api) { this.inventory = inventory; this.slotGrid = slot; SetupDialog(); this.OnClosed += CloseMe; }
public static SeedBagInventory CreateInventory(ICoreAPI api, ItemSlot slot) { SeedBagInventory inventory = new SeedBagInventory("fancytools.seedbagInv", "id", api, slot); inventory.SyncFromSeedBag(); inventory.ResolveBlocksOrItems(); return(inventory); }
private void OpenSeedBagGui(ItemSlot slot, EntityAgent byEntity) { SeedBagInventory inventory = CreateInventory(api, slot); inventory.OnInventoryClosed += OnCloseInventory; IPlayer player = (byEntity as EntityPlayer).Player; FancyTools mod = api.ModLoader.GetModSystem <FancyTools>(); 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(); } }
static bool Prefix(EntityPlayer __instance, ItemStack itemstack, ref bool __result) { if (itemstack.Item is ItemPlantableSeed) { // Check if there is a seedbag in the hotbar with enough space foreach (ItemSlot slot in __instance.Player.InventoryManager.GetHotbarInventory()) { if (slot != null && slot.Itemstack != null && slot.Itemstack.Item is SeedBagItem) { SeedBagInventory inventory = SeedBagItem.CreateInventory(__instance.Api, slot); inventory.PlaceItemStack(itemstack); inventory.SyncToSeedBag(); if (itemstack.StackSize <= 0) { break; } } } } return(true); }
private void TryPlacingSeeds(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel) { if (blockSel == null) { return; } IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; BlockPos pos = blockSel.Position; SeedBagInventory inventory = CreateInventory(api, slot); for (int x = -1; x <= 1; x++) { for (int z = -1; z <= 1; z++) { BlockPos p = pos.AddCopy(x, 0, z); blockSel.Position = p; BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(p); if (be is BlockEntityFarmland) { foreach (ItemSlot seedSlot in inventory.slots) { ItemStack seed = seedSlot.Itemstack; if (!(seed is null) && !(seed.Item is null) && seed.StackSize > 0) { EnumHandHandling handling = EnumHandHandling.Handled; seed.Item.OnHeldInteractStart(seedSlot, byEntity, blockSel, null, false, ref handling); break; } } } } } inventory.SyncToSeedBag(); }
public ItemSlotSeeds(SeedBagInventory inventory) : base(inventory) { }