Unfinished helix leaf

This commit is contained in:
paulevsGitch 2020-12-10 01:01:40 +03:00
parent d1dec4da56
commit f35146610b
2 changed files with 42 additions and 8 deletions

View file

@ -96,7 +96,7 @@ public class SplineHelper {
}
}
private static boolean fillLine(Vector3f start, Vector3f end, StructureWorldAccess world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
public 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();
float dz = end.getZ() - start.getZ();
@ -146,7 +146,7 @@ public class SplineHelper {
}
}
private static void fillLineForce(Vector3f start, Vector3f end, StructureWorldAccess world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
public 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();

View file

@ -7,6 +7,7 @@ import java.util.Random;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -31,11 +32,13 @@ public class HelixTreeFeature extends DefaultFeature {
float radiusRange = MHelper.randRange(4.5F, 6F, random);
float scale = MHelper.randRange(0.5F, 1F, random);
float dx;
float dz;
List<Vector3f> spline = new ArrayList<Vector3f>(10);
for (int i = 0; i < 10; i++) {
float radius = (0.9F - i * 0.1F) * radiusRange;
float dx = (float) Math.sin(i + angle) * radius;
float dz = (float) Math.cos(i + angle) * radius;
dx = (float) Math.sin(i + angle) * radius;
dz = (float) Math.cos(i + angle) * radius;
spline.add(new Vector3f(dx, i * 2, dz));
}
SDF sdf = SplineHelper.buildSDF(spline, 1.7F, 0.5F, (p) -> { return EndBlocks.HELIX_TREE.bark.getDefaultState(); });
@ -49,7 +52,7 @@ public class HelixTreeFeature extends DefaultFeature {
sdf = new SDFSmoothUnion().setRadius(3).setSourceA(sdf).setSourceB(stem);
sdf = new SDFScale().setScale(scale).setSource(sdf);
float dx = 30 * scale;
dx = 30 * scale;
float dy1 = -20 * scale;
float dy2 = 100 * scale;
sdf.fillArea(world, pos, new Box(pos.add(-dx, dy1, -dx), pos.add(dx, dy2, dx)));
@ -62,11 +65,42 @@ public class HelixTreeFeature extends DefaultFeature {
return state.getMaterial().isReplaceable();
});
SplineHelper.scale(spline2, scale);
SplineHelper.fillSplineForce(spline2, world, EndBlocks.HELIX_TREE.bark.getDefaultState(),
pos.add(lastPoint.getX() + 0.5, lastPoint.getY() + 0.5, lastPoint.getZ() + 0.5),
(state) -> {
BlockPos leafStart = pos.add(lastPoint.getX() + 0.5, lastPoint.getY() + 0.5, lastPoint.getZ() + 0.5);
SplineHelper.fillSplineForce(spline2, world, EndBlocks.HELIX_TREE.bark.getDefaultState(), leafStart, (state) -> {
return state.getMaterial().isReplaceable();
});
spline.clear();
for (int i = 0; i <= 20; i++) {
float radius = i * 0.1F - 1;
radius *= radius;
radius = (1 - radius) * 4F * scale;
dx = (float) Math.sin(i * 0.25F + angle) * radius;
dz = (float) Math.cos(i * 0.25F + angle) * radius;
spline.add(new Vector3f(dx, i * scale, dz));
}
Vector3f start = new Vector3f();
Vector3f end = new Vector3f();
lastPoint = spline.get(0);
for (int i = 1; i < spline.size(); i++) {
Vector3f point = spline.get(i);
int minY = MHelper.floor(lastPoint.getY());
int maxY = MHelper.floor(point.getY());
float div = point.getY() - lastPoint.getY();
for (float py = minY; py <= maxY; py += 0.25F) {
//for (int py = minY; py <= maxY; py ++) {
start.set(0, py, 0);
float delta = (float) (py - minY) / div;
float px = MathHelper.lerp(delta, lastPoint.getX(), point.getX());
float pz = MathHelper.lerp(delta, lastPoint.getZ(), point.getZ());
end.set(px, py, pz);
SplineHelper.fillLineForce(start, end, world, EndBlocks.HELIX_TREE_LEAVES.getDefaultState(), leafStart, (state) -> {
return state.getMaterial().isReplaceable();
});
}
lastPoint = point;
}
return true;
}