wip: further code cleanup
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.utils;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class LocationUtil {
|
||||
public static void iterateBlocks(Location loc1, Location loc2, Consumer<Location> action) {
|
||||
if (loc1.getWorld() != loc2.getWorld()) {
|
||||
throw new IllegalArgumentException("Locations must be in the same world");
|
||||
}
|
||||
|
||||
World world = loc1.getWorld();
|
||||
int minX = Math.min(loc1.getBlockX(), loc2.getBlockX());
|
||||
int maxX = Math.max(loc1.getBlockX(), loc2.getBlockX());
|
||||
int minY = Math.min(loc1.getBlockY(), loc2.getBlockY());
|
||||
int maxY = Math.max(loc1.getBlockY(), loc2.getBlockY());
|
||||
int minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
|
||||
int maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
|
||||
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
action.accept(new Location(world, x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user