public void Move(RegionSelector selector, int count, BlockCoordinates dir) { 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>(); foreach (var coord in selected.ToArray()) { Block block = _level.GetBlock(coord); block.Coordinates += (dir * count); movedBlocks.Add(block); selected.Remove(block.Coordinates); } // Actually move them foreach (var block in movedBlocks) { SetBlock(block); } // Set the left-overs (gap) to air foreach (var coord in selected) { SetBlock(new Air { Coordinates = coord }); } // Move selection too selector.Select(selector.Position1 + (dir * count), selector.Position2 + (dir * count)); }
public void Center(RegionSelector selector, Pattern pattern) { Vector3 centerVec = selector.GetCenter(); BlockCoordinates center = new Vector3((float)Math.Truncate(centerVec.X), (float)Math.Truncate(centerVec.Y), (float)Math.Truncate(centerVec.Z)); RegionSelector centerRegion = new RegionSelector(selector.Player); centerRegion.SelectPrimary(center); centerRegion.SelectSecondary(centerVec); SetBlocks(centerRegion.GetSelectedBlocks(), pattern); }
public void Center(RegionSelector selector, Pattern pattern) { Vector3 centerVec = selector.GetCenter(); BlockCoordinates center = new BlockCoordinates((int)centerVec.X, (int)centerVec.Y, (int)centerVec.Z); RegionSelector centerRegion = new RegionSelector(selector.Player); centerRegion.SelectPrimary(center); centerRegion.SelectSecondary(centerVec); SetBlocks(centerRegion.GetSelectedBlocks(), pattern); }
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; } } } } }
public void ReplaceBlocks(RegionSelector selector, Mask mask, Pattern pattern) { var selected = selector.GetSelectedBlocks(); foreach (BlockCoordinates coordinates in selected) { if (mask.Test(coordinates)) { SetBlock(coordinates, pattern); } } }
private void LevelTick(object o) { foreach (var kvp in RegionSelector.RegionSelectors) { Player player = kvp.Key; RegionSelector selector = kvp.Value; //if (!(player.Inventory.GetItemInHand() is DistanceWand wand)) continue; selector.DisplaySelection(forceHide: !(player.Inventory.GetItemInHand() is DistanceWand wand)); } }
private void LevelTick(object o) { foreach (var kvp in RegionSelector.RegionSelectors) { Player player = kvp.Key; RegionSelector selector = kvp.Value; var wand = player.Inventory.GetItemInHand() as DistanceWand; if (wand == null) { continue; } selector.DisplaySelection(); } }
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)); } }
public void SetBlocks(RegionSelector selector, Pattern pattern) { SetBlocks(selector.GetSelectedBlocks(), pattern); }
public int DrawLine(RegionSelector selector, Pattern pattern, BlockCoordinates pos1, BlockCoordinates pos2, double radius, bool filled) { HashSet <BlockCoordinates> vset = new HashSet <BlockCoordinates>(); bool notdrawn = true; int x1 = pos1.X, y1 = pos1.Y, z1 = pos1.Z; int x2 = pos2.X, y2 = pos2.Y, z2 = pos2.Z; int tipx = x1, tipy = y1, tipz = z1; int dx = Math.Abs(x2 - x1), dy = Math.Abs(y2 - y1), dz = Math.Abs(z2 - z1); if (dx + dy + dz == 0) { vset.Add(new BlockCoordinates(tipx, tipy, tipz)); notdrawn = false; } if (Math.Max(Math.Max(dx, dy), dz) == dx && notdrawn) { for (int domstep = 0; domstep <= dx; domstep++) { tipx = x1 + domstep * (x2 - x1 > 0 ? 1 : -1); tipy = (int)Math.Round(y1 + domstep * ((double)dy) / ((double)dx) * (y2 - y1 > 0 ? 1 : -1)); tipz = (int)Math.Round(z1 + domstep * ((double)dz) / ((double)dx) * (z2 - z1 > 0 ? 1 : -1)); vset.Add(new BlockCoordinates(tipx, tipy, tipz)); } notdrawn = false; } if (Math.Max(Math.Max(dx, dy), dz) == dy && notdrawn) { for (int domstep = 0; domstep <= dy; domstep++) { tipy = y1 + domstep * (y2 - y1 > 0 ? 1 : -1); tipx = (int)Math.Round(x1 + domstep * ((double)dx) / ((double)dy) * (x2 - x1 > 0 ? 1 : -1)); tipz = (int)Math.Round(z1 + domstep * ((double)dz) / ((double)dy) * (z2 - z1 > 0 ? 1 : -1)); vset.Add(new BlockCoordinates(tipx, tipy, tipz)); } notdrawn = false; } if (Math.Max(Math.Max(dx, dy), dz) == dz && notdrawn) { for (int domstep = 0; domstep <= dz; domstep++) { tipz = z1 + domstep * (z2 - z1 > 0 ? 1 : -1); tipy = (int)Math.Round(y1 + domstep * ((double)dy) / ((double)dz) * (y2 - y1 > 0 ? 1 : -1)); tipx = (int)Math.Round(x1 + domstep * ((double)dx) / ((double)dz) * (x2 - x1 > 0 ? 1 : -1)); vset.Add(new BlockCoordinates(tipx, tipy, tipz)); } notdrawn = false; } vset = GetBallooned(vset, radius); if (!filled) { vset = GetHollowed(vset); } var drawLine = SetBlocks(vset, pattern); return(drawLine); }