Beispiel #1
0
 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);
 }
Beispiel #2
0
        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();
        }