From 8fedd59f0a2f9ec3f3cbff536b4c2ddefe3bc373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=BC=D0=B0=20=D0=94=D0=B0=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= <35975332+Nekiplay@users.noreply.github.com> Date: Thu, 30 Jul 2020 00:49:16 +0500 Subject: [PATCH] Add FindBlock on GetWorld (#1152) * Add FindBlock * Add FindBlock Array * Update World.cs * Factorize FindBlock methods --- MinecraftClient/Mapping/World.cs | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) 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 ///