fCraft.Map.GetBlock C# (CSharp) Method

GetBlock() public method

Gets a block at given coordinates. Checks bounds.
public GetBlock ( Vector3I coords ) : Block
coords Vector3I Coordinate vector (X,Y,Z).
return Block
        public Block GetBlock( Vector3I coords )
        {
            if ( coords.X < Width && coords.Y < Length && coords.Z < Height && coords.X >= 0 && coords.Y >= 0 && coords.Z >= 0 )
                return ( Block )Blocks[Index( coords )];
            return Block.Undefined;
        }

Same methods

Map::GetBlock ( int x, int y, int z ) : Block

Usage Example

Example #1
0
        private void AddBeaches([NotNull] Map map)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }
            int beachExtentSqr = (args.BeachExtent + 1) * (args.BeachExtent + 1);

            for (int x = 0; x < map.Width; x++)
            {
                for (int y = 0; y < map.Length; y++)
                {
                    for (int z = args.WaterLevel; z <= args.WaterLevel + args.BeachHeight; z++)
                    {
                        if (map.GetBlock(x, y, z) != bGroundSurface)
                        {
                            continue;
                        }
                        bool found = false;
                        for (int dx = -args.BeachExtent; !found && dx <= args.BeachExtent; dx++)
                        {
                            for (int dy = -args.BeachExtent; !found && dy <= args.BeachExtent; dy++)
                            {
                                for (int dz = -args.BeachHeight; dz <= 0; dz++)
                                {
                                    if (dx * dx + dy * dy + dz * dz > beachExtentSqr)
                                    {
                                        continue;
                                    }
                                    int xx = x + dx;
                                    int yy = y + dy;
                                    int zz = z + dz;
                                    if (xx < 0 || xx >= map.Width || yy < 0 || yy >= map.Length || zz < 0 ||
                                        zz >= map.Height)
                                    {
                                        continue;
                                    }
                                    Block block = map.GetBlock(xx, yy, zz);
                                    if (block == bWater || block == bWaterSurface)
                                    {
                                        found = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (found)
                        {
                            map.SetBlock(x, y, z, bSeaFloor);
                            if (z > 0 && map.GetBlock(x, y, z - 1) == bGround)
                            {
                                map.SetBlock(x, y, z - 1, bSeaFloor);
                            }
                        }
                    }
                }
            }
        }
All Usage Examples Of fCraft.Map::GetBlock