Helix tree feature (WIP)

This commit is contained in:
paulevsGitch 2020-12-09 23:49:29 +03:00
parent 27668f27a1
commit d1dec4da56
4 changed files with 128 additions and 0 deletions

View file

@ -87,6 +87,15 @@ public class SplineHelper {
return true;
}
public static void fillSplineForce(List<Vector3f> spline, StructureWorldAccess world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
Vector3f startPos = spline.get(0);
for (int i = 1; i < spline.size(); i++) {
Vector3f endPos = spline.get(i);
fillLineForce(startPos, endPos, world, state, pos, replace);
startPos = endPos;
}
}
private static boolean fillLine(Vector3f start, Vector3f end, StructureWorldAccess world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
float dx = end.getX() - start.getX();
float dy = end.getY() - start.getY();
@ -137,6 +146,49 @@ public class SplineHelper {
}
}
private static void fillLineForce(Vector3f start, Vector3f end, StructureWorldAccess world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
float dx = end.getX() - start.getX();
float dy = end.getY() - start.getY();
float dz = end.getZ() - start.getZ();
float max = MHelper.max(Math.abs(dx), Math.abs(dy), Math.abs(dz));
int count = MHelper.floor(max + 1);
dx /= max;
dy /= max;
dz /= max;
float x = start.getX();
float y = start.getY();
float z = start.getZ();
boolean down = Math.abs(dy) > 0.2;
BlockState bState;
Mutable bPos = new Mutable();
for (int i = 0; i < count; i++) {
bPos.set(x + pos.getX(), y + pos.getY(), z + pos.getZ());
bState = world.getBlockState(bPos);
if (replace.apply(bState)) {
BlocksHelper.setWithoutUpdate(world, bPos, state);
bPos.setY(bPos.getY() - 1);
bState = world.getBlockState(bPos);
if (down && bState.equals(state) || replace.apply(bState)) {
BlocksHelper.setWithoutUpdate(world, bPos, state);
}
}
x += dx;
y += dy;
z += dz;
}
bPos.set(end.getX() + pos.getX(), end.getY() + pos.getY(), end.getZ() + pos.getZ());
bState = world.getBlockState(bPos);
if (replace.apply(bState)) {
BlocksHelper.setWithoutUpdate(world, bPos, state);
bPos.setY(bPos.getY() - 1);
bState = world.getBlockState(bPos);
if (down && bState.equals(state) || replace.apply(bState)) {
BlocksHelper.setWithoutUpdate(world, bPos, state);
}
}
}
public static boolean canGenerate(List<Vector3f> spline, float scale, BlockPos start, StructureWorldAccess world, Function<BlockState, Boolean> canReplace) {
int count = spline.size();
Vector3f vec = spline.get(0);