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


C# Chunk.SetBlockAndData方法代码示例

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


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

示例1: Grow

        public void Grow(StructBlock block, Chunk chunk)
        {
            if (!CanGrow(block, chunk))
                return;

            UniversalCoords blockUp = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ);
            if (block.World.GetEffectiveLight(blockUp) < 9)
                return;

            if (block.World.Server.Rand.Next(29) != 0)
                return;

            if ((block.MetaData & 8) == 0)
            {
                chunk.SetData(block.Coords, (byte)(block.MetaData | 8));
                return;
            }

            for (int i = block.Coords.WorldY; i < block.Coords.WorldY + 4; i++)
            {
                chunk.SetBlockAndData(block.Coords.BlockX, i, block.Coords.BlockZ, (byte)BlockData.Blocks.Log, block.MetaData);
                if(chunk.GetType(block.Coords.BlockX, i + 1, block.Coords.BlockZ) != BlockData.Blocks.Air)
                    break;
            }

            // Grow leaves
            for (int i = block.Coords.WorldY + 2; i < block.Coords.WorldY + 5; i++)
                for (int j = block.Coords.WorldX - 2; j <= block.Coords.WorldX + 2; j++)
                    for (int k = block.Coords.WorldZ - 2; k <= block.Coords.WorldZ + 2; k++)
                    {
                        Chunk nearbyChunk = block.World.GetChunkFromWorld(i, k, false, false);
                        if (nearbyChunk == null || (nearbyChunk.GetType(j & 0xF, i, k & 0xF) != BlockData.Blocks.Air))
                            continue;

                        nearbyChunk.SetBlockAndData(j & 0xF, i, k & 0xF, (byte)BlockData.Blocks.Leaves,
                                                        block.MetaData);
                    }

            for (int i = block.Coords.WorldX - 1; i <= block.Coords.WorldX + 1; i++)
                for (int j = block.Coords.WorldZ - 1; j <= block.Coords.WorldZ + 1; j++)
                {
                    Chunk nearbyChunk = block.World.GetChunkFromWorld(i, j, false, false);
                    if (nearbyChunk == null || nearbyChunk.GetType(i & 0xF, block.Coords.WorldY + 5, j & 0xF) != BlockData.Blocks.Air)
                        continue;

                    nearbyChunk.SetBlockAndData(i & 0xF, block.Coords.WorldY + 5, j & 0xF, (byte)BlockData.Blocks.Leaves,
                                                    block.MetaData);
                }
        }
开发者ID:IdentErr,项目名称:c-raft,代码行数:49,代码来源:BlockSapling.cs

示例2: Grow

        public void Grow(StructBlock block, Chunk chunk)
        {
            if (!CanGrow(block, chunk))
                return;

            UniversalCoords oneUp = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ);
            byte blockAboveId = (byte)chunk.GetType(oneUp);
            byte? blockAboveLight = chunk.World.GetEffectiveLight(oneUp);
            if (blockAboveLight == null)
                return;
            if (blockAboveLight < 4 && BlockHelper.Instance(blockAboveId).Opacity > 2)
            {
                if (block.World.Server.Rand.Next(3) == 0)
                {
                    chunk.SetBlockAndData(block.Coords, (byte)BlockData.Blocks.Dirt, 0);
                }
                return;
            }

            if (blockAboveLight >= 9)
            {
                int x = block.Coords.WorldX + block.World.Server.Rand.Next(2) - 1;
                int y = block.Coords.WorldY + block.World.Server.Rand.Next(4) - 3;
                int z = block.Coords.WorldZ + block.World.Server.Rand.Next(2) - 1;

                Chunk nearbyChunk = block.World.GetChunkFromWorld(x, z);

                if (nearbyChunk == null)
                    return;

                byte newBlockId = (byte)nearbyChunk.GetType(x & 0xF, y, z & 0xF);
                if (newBlockId != (byte)BlockData.Blocks.Dirt)
                    return;

                byte? newBlockAboveLight = nearbyChunk.World.GetEffectiveLight(UniversalCoords.FromWorld(x, y + 1, z));
                if (newBlockAboveLight != null && (newBlockAboveLight >= 4 && BlockHelper.Instance(newBlockId).Opacity <= 2))
                    nearbyChunk.SetBlockAndData(x & 0xF, y, z & 0xF, (byte)BlockData.Blocks.Grass, 0);
            }
        }
开发者ID:dekema2,项目名称:c-raft,代码行数:39,代码来源:BlockGrass.cs

示例3: Grow

        public void Grow(StructBlock block, Chunk chunk)
        {
            if (!CanGrow(block, chunk))
                return;

            if (block.MetaData < 0xe) // 14
            {
                chunk.SetData(block.Coords, ++block.MetaData);
                return;
            }

            chunk.SetData(block.Coords, 0);
            UniversalCoords blockAbove = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1,
                                                                   block.Coords.WorldZ);
            chunk.SetBlockAndData(blockAbove, (byte)BlockData.Blocks.Reed, 0x0);
        }
开发者ID:IdentErr,项目名称:c-raft,代码行数:16,代码来源:BlockReed.cs

示例4: Grow

        public void Grow(StructBlock block, Chunk chunk)
        {
            if (!CanGrow(block, chunk))
                return;

            UniversalCoords oneUp = UniversalCoords.FromWorld(block.Coords.WorldX, block.Coords.WorldY + 1, block.Coords.WorldZ);

            if (block.MetaData < 0xe) // 14
            {

                chunk.SetData(block.Coords, ++block.MetaData, false);
                return;
            }

            chunk.SetData(block.Coords, 0);
            chunk.SetBlockAndData(oneUp, (byte)BlockData.Blocks.Cactus, 0x0);
        }
开发者ID:IdentErr,项目名称:c-raft,代码行数:17,代码来源:BlockCactus.cs


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