Tree fixes

This commit is contained in:
paulevsGitch 2020-12-10 14:09:59 +03:00
parent 2302371ac6
commit ee60f73e53
10 changed files with 100 additions and 12 deletions

View file

@ -4,13 +4,16 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
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;
import ru.betterend.blocks.BlockHelixTreeLeaves;
import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndTags;
import ru.betterend.util.BlocksHelper;
@ -76,7 +79,7 @@ public class HelixTreeFeature extends DefaultFeature {
float radius = 1 - i * 0.05F;
radius = radius * radius * 2 - 1;
radius *= radius;
radius = (1 - radius) * 10F * scale;
radius = (1 - radius) * 8F * scale;
dx = (float) Math.sin(i * 0.45F + angle) * radius;
dz = (float) Math.cos(i * 0.45F + angle) * radius;
spline.add(new Vector3f(dx, i * scale * 1.75F, dz));
@ -85,37 +88,68 @@ public class HelixTreeFeature extends DefaultFeature {
Vector3f start = new Vector3f();
Vector3f end = new Vector3f();
lastPoint = spline.get(0);
BlockState leaf = EndBlocks.HELIX_TREE_LEAVES.getDefaultState();
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.2F) {
for (float py = minY; py <= maxY; py += 0.1F) {
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();
});
fillLine(start, end, world, leaf, leafStart, i / 2 - 1);
}
lastPoint = point;
}
leafStart = leafStart.add(0, lastPoint.getY() + 1, 0);
leaf = leaf.with(BlockHelixTreeLeaves.COLOR, 7);
leafStart = leafStart.add(0, lastPoint.getY(), 0);
if (world.getBlockState(leafStart).isAir()) {
BlocksHelper.setWithoutUpdate(world, leafStart, EndBlocks.HELIX_TREE_LEAVES);
BlocksHelper.setWithoutUpdate(world, leafStart, leaf);
leafStart = leafStart.up();
if (world.getBlockState(leafStart).isAir()) {
BlocksHelper.setWithoutUpdate(world, leafStart, EndBlocks.HELIX_TREE_LEAVES);
BlocksHelper.setWithoutUpdate(world, leafStart, leaf);
leafStart = leafStart.up();
if (world.getBlockState(leafStart).isAir()) {
BlocksHelper.setWithoutUpdate(world, leafStart, EndBlocks.HELIX_TREE_LEAVES);
BlocksHelper.setWithoutUpdate(world, leafStart, leaf);
}
}
}
return true;
}
private void fillLine(Vector3f start, Vector3f end, StructureWorldAccess world, BlockState state, BlockPos pos, int offset) {
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();
Mutable bPos = new Mutable();
for (int i = 0; i < count; i++) {
int color = MHelper.floor((float) i / (float) count * 7F + 0.5F) + offset;
color = MathHelper.clamp(color, 0, 7);
bPos.set(x + pos.getX(), y + pos.getY(), z + pos.getZ());
if (world.getBlockState(bPos).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, bPos, state.with(BlockHelixTreeLeaves.COLOR, color));
}
x += dx;
y += dy;
z += dz;
}
bPos.set(end.getX() + pos.getX(), end.getY() + pos.getY(), end.getZ() + pos.getZ());
if (world.getBlockState(bPos).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, bPos, state.with(BlockHelixTreeLeaves.COLOR, 7));
}
}
}