Example #1
0
        public void Naturalize(Player player, RegionSelector selector)
        {
            var min = selector.GetMin();
            var max = selector.GetMax();

            var level = player.Level;

            for (int x = min.X; x <= max.X; x++)
            {
                for (int z = min.Z; z <= max.Z; z++)
                {
                    int depth = 0;
                    for (int y = Math.Min(255, max.Y); y >= min.Y; y--)
                    {
                        var coordinates = new BlockCoordinates(x, y, z);
                        if (level.IsAir(coordinates) || !level.GetBlock(coordinates).IsSolid)
                        {
                            if (depth != 0)
                            {
                                depth = 4;
                            }
                            continue;
                        }

                        switch (depth++)
                        {
                        case 0:
                            SetBlock(new Grass()
                            {
                                Coordinates = coordinates
                            });
                            break;

                        case 1:
                        case 2:
                        case 3:
                            SetBlock(new Dirt()
                            {
                                Coordinates = coordinates
                            });
                            break;

                        default:
                            SetBlock(new Stone()
                            {
                                Coordinates = coordinates
                            });
                            break;
                        }
                    }
                }
            }
        }
Example #2
0
        public void Stack(RegionSelector selector, int count, BlockCoordinates dir, bool skipAir, bool moveSelection)
        {
            BlockCoordinates size = selector.GetMax() - selector.GetMin() + BlockCoordinates.One;

            var selected = new List <BlockCoordinates>(selector.GetSelectedBlocks());

            // Save old blocks with new coordinates so we don't overwrite while traverse

            List <Block> movedBlocks = new List <Block>();

            for (int i = 1; i <= count; i++)
            {
                foreach (var coord in selected.ToArray())
                {
                    Block block = _level.GetBlock(coord);
                    block.Coordinates += (dir * size * i);
                    movedBlocks.Add(block);
                }
            }

            // Actually stack them
            foreach (var block in movedBlocks)
            {
                if (skipAir && block is Air)
                {
                    continue;
                }
                SetBlock(block);
            }

            // Move selection too last stack
            if (moveSelection)
            {
                selector.Select(selector.Position1 + (dir * size * count), selector.Position2 + (dir * size * count));
            }
        }