diff --git a/src/main/java/ru/betterend/util/SplineHelper.java b/src/main/java/ru/betterend/util/SplineHelper.java index 6b211387..1bda0f28 100644 --- a/src/main/java/ru/betterend/util/SplineHelper.java +++ b/src/main/java/ru/betterend/util/SplineHelper.java @@ -96,7 +96,7 @@ public class SplineHelper { } } - private static boolean fillLine(Vector3f start, Vector3f end, StructureWorldAccess world, BlockState state, BlockPos pos, Function replace) { + public static boolean fillLine(Vector3f start, Vector3f end, StructureWorldAccess world, BlockState state, BlockPos pos, Function 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 replace) { + public static void fillLineForce(Vector3f start, Vector3f end, StructureWorldAccess world, BlockState state, BlockPos pos, Function replace) { float dx = end.getX() - start.getX(); float dy = end.getY() - start.getY(); float dz = end.getZ() - start.getZ(); diff --git a/src/main/java/ru/betterend/world/features/trees/HelixTreeFeature.java b/src/main/java/ru/betterend/world/features/trees/HelixTreeFeature.java index 1c0afeba..2c03f536 100644 --- a/src/main/java/ru/betterend/world/features/trees/HelixTreeFeature.java +++ b/src/main/java/ru/betterend/world/features/trees/HelixTreeFeature.java @@ -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 spline = new ArrayList(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; }