wip: further code cleanup

This commit is contained in:
2024-07-23 22:25:00 +02:00
parent e5e1f39989
commit 93dc9d8a80
25 changed files with 556 additions and 407 deletions

View File

@@ -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));
}
}
}
}
}