diff --git a/MinecraftClient/Mapping/World.cs b/MinecraftClient/Mapping/World.cs index 4f34a512..c6eab89a 100644 --- a/MinecraftClient/Mapping/World.cs +++ b/MinecraftClient/Mapping/World.cs @@ -83,6 +83,51 @@ namespace MinecraftClient.Mapping return new Block(0); //Air } + /// + /// Look for a block around the specified location + /// + /// Start location + /// Block type + /// Search radius - larger is slower: O^3 complexity + /// Block matching the specified block type + public List FindBlock(Location from, Material block, int radius) + { + return FindBlock(from, block, radius, radius, radius); + } + + /// + /// Look for a block around the specified location + /// + /// Start location + /// Block type + /// Search radius on the X axis + /// Search radius on the Y axis + /// Search radius on the Z axis + /// Block matching the specified block type + public List FindBlock(Location from, Material block, int radiusx, int radiusy, int radiusz) + { + Location minPoint = new Location(from.X - radiusx, from.Y - radiusy, from.Z - radiusz); + Location maxPoint = new Location(from.X + radiusx, from.Y + radiusy, from.Z + radiusz); + List list = new List { }; + for (double x = minPoint.X; x <= maxPoint.X; x++) + { + for (double y = minPoint.Y; y <= maxPoint.Y; y++) + { + for (double z = minPoint.Z; z <= maxPoint.Z; z++) + { + Location doneloc = new Location(x, y, z); + Block doneblock = GetBlock(doneloc); + Material blockType = GetBlock(doneloc).Type; + if (blockType == block) + { + list.Add(doneloc); + } + } + } + } + return list; + } + /// /// Set block at the specified location ///