Refactored Generation and class structure

This commit is contained in:
2023-11-11 22:13:58 +01:00
parent d9bbaf9865
commit 6dc4269367
53 changed files with 1049 additions and 72 deletions

View File

@@ -0,0 +1,81 @@
package eu.mhsl.minenet.minigames.util;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.instance.generator.GenerationUnit;
import java.util.function.Consumer;
public class GeneratorUtils {
public static void foreachXZ(GenerationUnit unit, Consumer<Point> bottomPoint) {
double startX = unit.absoluteStart().x();
double endX = unit.absoluteEnd().x() - 1;
double startZ = unit.absoluteStart().z();
double endZ = unit.absoluteEnd().z() - 1;
for (double x = startX; x <= endX; x++) {
for (double z = startZ; z <= endZ; z++) {
Point currentPoint = new Pos(x, unit.absoluteStart().y(), z);
bottomPoint.accept(currentPoint);
}
}
}
public static void foreachXZ(Point start, Point end, Consumer<Point> callback) {
double startX = Math.min(start.x(), end.x());
double endX = Math.max(start.x(), end.x());
double startZ = Math.min(start.z(), end.z());
double endZ = Math.max(start.z(), end.z());
for (double x = startX; x <= endX; x++) {
for (double z = startZ; z <= endZ; z++) {
Point currentPoint = new Pos(x, start.y(), z);
callback.accept(currentPoint);
}
}
}
public static void iterateArea(Point pos1, Point pos2, Consumer<Point> callback) {
int minX = (int) Math.min(pos1.x(), pos2.x());
int maxX = (int) Math.max(pos1.x(), pos2.x());
int minY = (int) Math.min(pos1.y(), pos2.y());
int maxY = (int) Math.max(pos1.y(), pos2.y());
int minZ = (int) Math.min(pos1.z(), pos2.z());
int maxZ = (int) Math.max(pos1.z(), pos2.z());
for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
Point point = new Pos(x, y, z);
callback.accept(point);
}
}
}
}
public static void outline(Point pos1, Point pos2, Consumer<Point> outline) {
outline(pos1, pos2, outline, point -> {});
}
public static void outline(Point pos1, Point pos2, Consumer<Point> outline, Consumer<Point> innerFill) {
int minX = (int) Math.min(pos1.x(), pos2.x());
int minY = (int) Math.min(pos1.y(), pos2.y());
int minZ = (int) Math.min(pos1.z(), pos2.z());
int maxX = (int) Math.max(pos1.x(), pos2.x());
int maxY = (int) Math.max(pos1.y(), pos2.y());
int maxZ = (int) Math.max(pos1.z(), pos2.z());
for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
Point blockPos = new Pos(x, y, z);
if (x == minX || x == maxX || y == minY || y == maxY || z == minZ || z == maxZ) {
outline.accept(blockPos);
}
}
}
}
}
}