Skip to content

Instantly share code, notes, and snippets.

@imDaniX
Created February 27, 2023 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imDaniX/8362f80fa516769dbbe10b612baaca16 to your computer and use it in GitHub Desktop.
Save imDaniX/8362f80fa516769dbbe10b612baaca16 to your computer and use it in GitHub Desktop.
Traversing edges of a cuboid
public class LocationUtils {
public static void traverseEdges(LocationConsumer consumer, Location aLoc, Location bLoc, double step) {
World world = aLoc.getWorld();
double[] xArr = {Math.min(aLoc.getX(), bLoc.getX()), Math.max(aLoc.getX(), bLoc.getX())};
double[] yArr = {Math.min(aLoc.getY(), bLoc.getY()), Math.max(aLoc.getY(), bLoc.getY())};
double[] zArr = {Math.min(aLoc.getZ(), bLoc.getZ()), Math.max(aLoc.getZ(), bLoc.getZ())};
for (double x = xArr[0]; x < xArr[1]; x += step) for (double y : yArr) for (double z : zArr) {
consumer.accept(world, x, y, z);
}
for (double y = yArr[0]; y < yArr[1]; y += step) for (double x : xArr) for (double z : zArr) {
consumer.accept(world, x, y, z);
}
for (double z = zArr[0]; z < zArr[1]; z += step) for (double y : yArr) for (double x : xArr) {
consumer.accept(world, x, y, z);
}
}
@FunctionalInterface
public interface LocationConsumer {
void accept(World world, double x, double y, double z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment