public GuiSeedBag(ICoreClientAPI api, SeedBagInventory inventory, ItemSlot slot) : base(api) { this.inventory = inventory; this.slotGrid = slot; SetupDialog(); this.OnClosed += CloseMe; }
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 = new SeedBagInventory("seedbagInv", "id", api, slot); inventory.SyncFromSeedBag(); 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(); }
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(); } }
public ItemSlotSeeds(SeedBagInventory inventory) : base(inventory) { }