void FloodFrom(Region tregion, Location start, Location c, Material mat, double maxRad) { if ((c - start).LengthSquared() > maxRad * maxRad) { return; } if (tregion.GetBlockMaterial(c) != Material.AIR) { return; } tregion.SetBlockMaterial(c, mat); foreach (Location dir in FloodDirs) { FloodFrom(tregion, start, c + dir, mat, maxRad); } }
public void Paste(Region tregion, Location corner, int angle) { corner.X -= Origin.X; corner.Y -= Origin.Y; corner.Z -= Origin.Z; for (int x = 0; x < Size.X; x++) { for (int y = 0; y < Size.Y; y++) { for (int z = 0; z < Size.Z; z++) { BlockInternal bi = Blocks[BlockIndex(x, y, z)]; if ((Material)bi.BlockMaterial != Material.AIR) { int tx = x; int ty = y; if (angle == 90) { tx = -(y + 1); ty = x; } else if (angle == 180) { tx = -(x + 1); ty = -(y + 1); } else if (angle == 270) { tx = y; ty = -(x + 1); } bi.BlockLocalData = (byte)(bi.BlockLocalData | ((int)BlockFlags.EDITED)); tregion.SetBlockMaterial(corner + new Location(tx, ty, z), (Material)bi.BlockMaterial, bi.BlockData, bi._BlockPaintInternal, (byte)(bi.BlockLocalData | (byte)BlockFlags.EDITED), bi.Damage); } } } } }
bool FloodFrom(Region tregion, Location start, List<KeyValuePair<Location, BlockInternal>> blocks, double maxRad, AABB extent) { Queue<Location> locsToGo = new Queue<Location>(); locsToGo.Enqueue(start); while (locsToGo.Count > 0) { Location c = locsToGo.Dequeue(); if ((c - start).LengthSquared() > maxRad * maxRad) { SysConsole.Output(OutputType.INFO, "Escaped radius!"); return false; } BlockInternal bi = tregion.GetBlockInternal(c); if ((Material)bi.BlockMaterial == Material.AIR) { continue; } if (!((BlockFlags)bi.BlockLocalData).HasFlag(BlockFlags.EDITED)) { SysConsole.Output(OutputType.INFO, "Found natural block!"); return false; } if (((BlockFlags)bi.BlockLocalData).HasFlag(BlockFlags.PROTECTED)) { continue; } blocks.Add(new KeyValuePair<Location, BlockInternal>(c, bi)); tregion.SetBlockMaterial(c, (Material)bi.BlockMaterial, bi.BlockData, bi.BlockPaint, (byte)(bi.BlockLocalData | (byte)BlockFlags.PROTECTED), bi.Damage, false, false); extent.Include(c); foreach (Location dir in FloodDirs) { locsToGo.Enqueue(c + dir); } } return true; }