use of com.builtbroken.mc.imp.transform.sorting.Vector3DistanceComparator in project Engine by VoltzEngine-Project.
the class Selection method getLocationsWithin.
/**
* Grabs all blocks near the point and within the distance.
* <p/>
* Note this search pattern does start at most negative corner
* TODO replace search pattern with same code the blasts use
* to select blocks in a bubble
*
* @param location - center point of the search
* @param size - number of items to return
* @param distance - distance to search
* @return list of locations of non air blocks sorted to closest to location
*/
public List<Pos> getLocationsWithin(Location location, int size, int distance) {
List<Pos> list = new LinkedList<>();
if (distance > 0) {
int min_y = (int) Math.max(min().yi(), location.y() - distance);
int max_y = (int) Math.min(max().yi(), location.y() + distance);
int min_x = (int) Math.max(min().xi(), location.x() - distance);
int max_x = (int) Math.min(max().xi(), location.x() + distance);
int min_z = (int) Math.max(min().zi(), location.z() - distance);
int max_z = (int) Math.min(max().zi(), location.z() + distance);
for (int y = min_y; y <= max_y; y++) {
for (int x = min_x; x <= max_x; x++) {
for (int z = min_z; z <= max_z; z++) {
if (size > 0 && list.size() >= size) {
Collections.sort(list, new Vector3DistanceComparator(location));
return list;
}
Pos pos = new Pos(x, y, z);
if (location.distance(pos) <= distance) {
Block b = pos.getBlock(location.world());
if (b != null && !pos.isAirBlock(location.world()) && pos.getHardness(location.world()) >= 0) {
list.add(pos);
}
}
}
}
}
}
return list;
}
use of com.builtbroken.mc.imp.transform.sorting.Vector3DistanceComparator in project Engine by VoltzEngine-Project.
the class Vector3Sorter method testClosestSorter.
public void testClosestSorter() {
List<Pos> list = new ArrayList();
Pos vec_1 = newVector(list, 1, 0, 1);
Pos vec_2 = newVector(list, 2, 0, 2);
Pos vec_3 = newVector(list, 3, 0, 3);
Pos vec_4 = newVector(list, -1, 0, -2);
Pos vec_5 = newVector(list, -4, 0, -4);
Collections.sort(list, new Vector3DistanceComparator(new Pos(0, 0, 0)));
assertEquals(list.get(0), vec_1);
assertEquals(list.get(1), vec_4);
assertEquals(list.get(2), vec_2);
assertEquals(list.get(3), vec_3);
assertEquals(list.get(4), vec_5);
}
Aggregations