private bool TrySpawnVine(ICoreAPI api, IFarmlandBlockEntity farmland, double currentTotalHours)
        {
            BlockPos motherplantPos = farmland.UpPos;

            foreach (BlockFacing facing in BlockFacing.HORIZONTALS)
            {
                BlockPos candidatePos = motherplantPos.AddCopy(facing);
                Block    block        = api.World.BlockAccessor.GetBlock(candidatePos);
                if (CanReplace(block))
                {
                    Block supportBlock = api.World.BlockAccessor.GetBlock(candidatePos.DownCopy());
                    if (IsSolid(supportBlock))
                    {
                        DoSpawnVine(api, candidatePos, motherplantPos, facing, currentTotalHours);
                        return(true);
                    }
                }
            }

            return(false);
        }
        public override bool TryGrowCrop(ICoreAPI api, IFarmlandBlockEntity farmland, double currentTotalHours, int newGrowthStage, ref EnumHandling handling)
        {
            if (vineGrowthQuantity == 0)
            {
                vineGrowthQuantity = farmland.CropAttributes.GetFloat("vineGrowthQuantity", vineGrowthQuantityGen.nextFloat(1, api.World.Rand));
                farmland.CropAttributes.SetFloat("vineGrowthQuantity", vineGrowthQuantity);
            }

            handling = EnumHandling.PassThrough;

            if (newGrowthStage >= vineGrowthStage)
            {
                if (newGrowthStage == 8)
                {
                    bool allWithered = true;
                    foreach (BlockFacing facing in BlockFacing.HORIZONTALS)
                    {
                        Block block = api.World.BlockAccessor.GetBlock(farmland.Pos.AddCopy(facing).Up());
                        if (block.Code.Path.StartsWith("pumpkin-vine"))
                        {
                            allWithered &= block.LastCodePart() == "withered";
                        }
                    }

                    if (!allWithered)
                    {
                        handling = EnumHandling.PreventDefault;
                    }
                    return(false);
                }

                if (api.World.Rand.NextDouble() < vineGrowthQuantity)
                {
                    return(TrySpawnVine(api, farmland, currentTotalHours));
                }
            }

            return(false);
        }
Esempio n. 3
0
 /// <summary>
 /// Attempts to grow the crop.
 /// </summary>
 /// <param name="api">The Core API</param>
 /// <param name="farmland">The farmland below the crop.</param>
 /// <param name="currentTotalHours"></param>
 /// <param name="newGrowthStage">The next growth stage.</param>
 /// <param name="handling">Whether or not this event was handled.</param>
 /// <returns>Whether or not the crop grew.</returns>
 public virtual bool TryGrowCrop(ICoreAPI api, IFarmlandBlockEntity farmland, double currentTotalHours, int newGrowthStage, ref EnumHandling handling)
 {
     handling = EnumHandling.PassThrough;
     return(false);
 }