mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add FindBlock on GetWorld (#1152)
* Add FindBlock * Add FindBlock Array * Update World.cs * Factorize FindBlock methods
This commit is contained in:
parent
61ac5bb3d1
commit
8fedd59f0a
1 changed files with 45 additions and 0 deletions
|
|
@ -83,6 +83,51 @@ namespace MinecraftClient.Mapping
|
|||
return new Block(0); //Air
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Look for a block around the specified location
|
||||
/// </summary>
|
||||
/// <param name="from">Start location</param>
|
||||
/// <param name="block">Block type</param>
|
||||
/// <param name="radius">Search radius - larger is slower: O^3 complexity</param>
|
||||
/// <returns>Block matching the specified block type</returns>
|
||||
public List<Location> FindBlock(Location from, Material block, int radius)
|
||||
{
|
||||
return FindBlock(from, block, radius, radius, radius);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Look for a block around the specified location
|
||||
/// </summary>
|
||||
/// <param name="from">Start location</param>
|
||||
/// <param name="block">Block type</param>
|
||||
/// <param name="radiusx">Search radius on the X axis</param>
|
||||
/// <param name="radiusy">Search radius on the Y axis</param>
|
||||
/// <param name="radiusz">Search radius on the Z axis</param>
|
||||
/// <returns>Block matching the specified block type</returns>
|
||||
public List<Location> 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<Location> list = new List<Location> { };
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set block at the specified location
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue