public override bool ShouldReceiveServerGameTicks(IWorldAccessor world, BlockPos pos, Random offThreadRandom, out object extra)
        {
            extra = null;

            bool isGrowing = false;

            Block    grass         = null;
            BlockPos upPos         = pos.UpCopy();
            string   grasscoverage = LastCodePart();
            bool     lowLightLevel = world.BlockAccessor.GetLightLevel(pos, EnumLightLevelType.MaxLight) < growthLightLevel;

            if (lowLightLevel || isSmotheringBlock(world, upPos))
            {
                grass = tryGetBlockForDying(world);
            }
            else
            {
                isGrowing = true;
                grass     = tryGetBlockForGrowing(world, pos);
            }

            if (grass != null)
            {
                extra = new GrassTick()
                {
                    Grass     = grass,
                    TallGrass = isGrowing ? getTallGrassBlock(world, upPos, offThreadRandom) : null
                };
            }
            return(extra != null);
        }
        public override void OnServerGameTick(IWorldAccessor world, BlockPos pos, object extra = null)
        {
            base.OnServerGameTick(world, pos, extra);

            GrassTick tick = extra as GrassTick;

            world.BlockAccessor.SetBlock(tick.Grass.BlockId, pos);
            if (tick.TallGrass != null && world.BlockAccessor.GetBlock(pos.UpCopy()).BlockId == 0)
            {
                world.BlockAccessor.SetBlock(tick.TallGrass.BlockId, pos.UpCopy());
            }
        }
示例#3
0
        public override bool ShouldReceiveServerGameTicks(IWorldAccessor world, BlockPos pos, Random offThreadRandom, out object extra)
        {
            extra = null;

            if (offThreadRandom.NextDouble() > growthChanceOnTick)
            {
                return(false);
            }

            if (growOnlyWhereRainfallExposed && world.BlockAccessor.GetRainMapHeightAt(pos) > pos.Y + 1)
            {
                return(false);
            }

            bool isGrowing = false;

            Block    grass;
            BlockPos upPos = pos.UpCopy();

            bool lowLightLevel = world.BlockAccessor.GetLightLevel(pos, EnumLightLevelType.MaxLight) < growthLightLevel;

            if (lowLightLevel || isSmotheringBlock(world, upPos))
            {
                grass = tryGetBlockForDying(world);
            }
            else
            {
                isGrowing = true;
                grass     = tryGetBlockForGrowing(world, pos);
            }

            if (grass != null)
            {
                extra = new GrassTick()
                {
                    Grass     = grass,
                    TallGrass = isGrowing ? getTallGrassBlock(world, upPos, offThreadRandom) : null
                };
            }
            return(extra != null);
        }