use of com.builtbroken.mc.lib.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.lib.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);
}
use of com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator in project Engine by VoltzEngine-Project.
the class BlastBasic method expand.
/**
* Called to map another iteration to expand outwards from the center of the explosion
*
* @param map - hash map to store data for block placement to energy used
* @param vec - next block to expand from, and to log to map
* @param energy - current energy at block
* @param side - side not to expand in, and direction we came from
* @param iteration - current iteration count from center, use this to stop the iteration if they get too far from center
*/
protected void expand(HashMap<BlockEdit, Float> map, BlockEdit vec, float energy, EnumFacing side, int iteration) {
long timeStart = System.nanoTime();
if (iteration < size * 2) {
float e = getEnergyCostOfTile(vec, energy);
profile.tilesPathed++;
if (e >= 0) {
// Add block to effect list
vec.energy = energy;
onBlockMapped(vec, e, energy - e);
map.put(vec, energy - e);
// Only iterate threw sides if we have more energy
if (e > 1) {
// Get valid sides to iterate threw
List<BlockEdit> sides = new ArrayList();
for (EnumFacing dir : EnumFacing.values()) {
if (dir != side) {
BlockEdit v = new BlockEdit(world, vec.x(), vec.y(), vec.z());
v.doDrops();
v = v.add(dir);
v.face = dir;
v.logPrevBlock();
sides.add(v);
}
}
Collections.sort(sides, new Vector3DistanceComparator(new Pos(x(), y(), z())));
profile.blockIterationTimes.add(System.nanoTime() - timeStart);
// Iterate threw sides expending energy outwards
for (BlockEdit f : sides) {
float eToSpend = (e / sides.size()) + (e % sides.size());
e -= eToSpend;
EnumFacing face = side == null ? getOpposite(f.face) : side;
if (!map.containsKey(f) || map.get(f) < eToSpend) {
f.face = face;
expand(map, f, eToSpend, face, iteration + 1);
}
}
}
}
}
}
use of com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator in project Engine by VoltzEngine-Project.
the class BlastBasic method getEffectedBlocks.
@Override
public void getEffectedBlocks(List<IWorldEdit> list) {
// TODO disable profiler if not in debug mode
HashMap<BlockEdit, Float> map = new HashMap();
profile.startSection("getEffectedBlocks");
// Start path finder
profile.startSection("Pathfinder");
list.add(new BlockEdit(this, Blocks.air, 0));
triggerPathFinder(map, new BlockEdit(this.world, this.x, this.y, this.z), energy);
profile.endSection("Pathfinder");
// Add map keys to block list
list.addAll(map.keySet());
// Sort results so blocks are placed in the center first
profile.startSection("Sorter");
Collections.sort(list, new Vector3DistanceComparator(new Pos(x(), y(), z())));
profile.endSection("Sorter");
profile.endSection("getEffectedBlocks");
// Generate debug info
if (Engine.runningAsDev) {
Engine.instance.logger().info(profile.getOutputSimple());
}
}
Aggregations