当前位置: 首页>>代码示例>>C#>>正文


C# Chunk.ForNSEW方法代码示例

本文整理汇总了C#中Chunk.ForNSEW方法的典型用法代码示例。如果您正苦于以下问题:C# Chunk.ForNSEW方法的具体用法?C# Chunk.ForNSEW怎么用?C# Chunk.ForNSEW使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chunk的用法示例。


在下文中一共展示了Chunk.ForNSEW方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanGrow

        public bool CanGrow(StructBlock block, Chunk chunk)
        {
            if (chunk == null)
                return false;

            // BlockMeta = 0x0 is a freshly planted cactus.
            // The data value is incremented at random intervals.
            // When it becomes 15, a new cactus block is created on top as long as the total height does not exceed 3.
            int maxHeight = 3;

            if (block.Coords.WorldY == 127)
                return false;

            UniversalCoords oneUp = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ);
            BlockData.Blocks blockId = chunk.GetType(oneUp);
            if (blockId != BlockData.Blocks.Air)
                return false;

            // Calculating the cactus length below this block
            int cactusHeightBelow = 0;
            for (int i = block.Coords.WorldY - 1; i >= 0; i--)
            {
                blockId = chunk.GetType(UniversalCoords.FromWorld(block.Coords.WorldX, i, block.Coords.WorldZ));
                if (blockId != BlockData.Blocks.Cactus)
                    break;
                cactusHeightBelow++;
            }

            if ((cactusHeightBelow + 1) >= maxHeight)
                return false;

            bool isAir = true;

            chunk.ForNSEW(oneUp,
                delegate(UniversalCoords uc)
                {
                    byte? nearbyBlockId = block.World.GetBlockId(uc);
                    if (nearbyBlockId == null || nearbyBlockId != (byte)BlockData.Blocks.Air)
                        isAir = false;
                });

            if (!isAir)
                return false;

            return true;
        }
开发者ID:dekema2,项目名称:c-raft,代码行数:46,代码来源:BlockCactus.cs

示例2: CanGrow

        public bool CanGrow(StructBlock block, Chunk chunk)
        {
            if (chunk == null)
                return false;

            // Can't grow above the sky
            if (block.Coords.WorldY == 127)
                return false;

            // Can grow only if the block above is free
            byte blockId = (byte)chunk.GetType(UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ));
            if (blockId != (byte)BlockData.Blocks.Air)
                return false;

            // MetaData = 0x0 is a freshly planted reed (sugar cane).
            // The data value is incremented randomly.
            // When it becomes 15, a new reed block is created on top as long as the total height does not exceed 3.

            // Calculating the reed length below this block
            int reedHeightBelow = 0;
            for (int i = block.Coords.WorldY - 1; i >= 0; i--)
            {
                if (chunk.GetType(block.Coords.BlockX, i, block.Coords.BlockZ) != BlockData.Blocks.Reed)
                    break;
                reedHeightBelow++;
            }

            // If the total reed height is bigger than the maximal height - it'll not grow
            if ((reedHeightBelow + 1) >= MaxHeight)
                return false;

            // Checking if there are water next to the basement block
            bool isWater = false;

            chunk.ForNSEW(UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY - reedHeightBelow - 1, block.Coords.WorldZ),
                delegate(UniversalCoords uc)
                {
                    byte? blockIdBelow = block.World.GetBlockId(uc);
                    if (blockIdBelow != null && (blockIdBelow == (byte)BlockData.Blocks.Water || blockIdBelow == (byte)BlockData.Blocks.Still_Water))
                    {
                        isWater = true;
                    }
                });

            if (!isWater && reedHeightBelow < MaxHeight)
            {
                UniversalCoords baseBlock = UniversalCoords.FromWorld(block.Coords.WorldX,
                                                                      block.Coords.WorldY - reedHeightBelow,
                                                                      block.Coords.WorldZ);
                BlockHelper.Instance(block.Type).Destroy(new StructBlock(baseBlock, block.Type, block.MetaData, block.World));
                return false;
            }

            return true;
        }
开发者ID:IdentErr,项目名称:c-raft,代码行数:55,代码来源:BlockReed.cs


注:本文中的Chunk.ForNSEW方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。