Tree leaves

This commit is contained in:
paulevsGitch 2020-10-14 23:03:47 +03:00
parent c9346da1ee
commit d17c660482
6 changed files with 50 additions and 83 deletions

View file

@ -5,17 +5,23 @@ import java.util.Random;
import java.util.function.Function;
import net.minecraft.block.BlockState;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.Material;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.BlockRegistry;
import ru.betterend.registry.BlockTagRegistry;
import ru.betterend.util.MHelper;
import ru.betterend.util.SplineHelper;
import ru.betterend.util.sdf.SDF;
import ru.betterend.util.sdf.operator.SDFDisplacement;
import ru.betterend.util.sdf.operator.SDFScale3D;
import ru.betterend.util.sdf.operator.SDFTranslate;
import ru.betterend.util.sdf.primitive.SDFSphere;
public class PythadendronTreeFeature extends DefaultFeature {
private static final Function<BlockState, Boolean> REPLACE;
@ -29,7 +35,8 @@ public class PythadendronTreeFeature extends DefaultFeature {
SplineHelper.offsetParts(spline, random, 0.7F, 0, 0.7F);
Vector3f last = spline.get(spline.size() - 1);
branch(last.getX(), last.getY(), last.getZ(), size * 1.5F, MHelper.randRange(0, MHelper.PI2, random), random, 3, world, pos);
int depth = 3;//MHelper.floor((size - 10F) * 3F / 10F + 1F);
branch(last.getX(), last.getY(), last.getZ(), size * 1.5F, MHelper.randRange(0, MHelper.PI2, random), random, depth, world, pos);
SDF function = SplineHelper.buildSDF(spline, 1.5F, 0.8F, (bpos) -> {
return BlockRegistry.PYTHADENDRON.bark.getDefaultState();
@ -57,21 +64,46 @@ public class PythadendronTreeFeature extends DefaultFeature {
SplineHelper.offsetParts(spline, random, 0.3F, 0, 0.3F);
Vector3f pos1 = spline.get(spline.size() - 1);
SplineHelper.fillSpline(spline, world, BlockRegistry.PYTHADENDRON.bark.getDefaultState(), pos, REPLACE);
boolean s1 = SplineHelper.fillSpline(spline, world, BlockRegistry.PYTHADENDRON.bark.getDefaultState(), pos, REPLACE);
spline = SplineHelper.makeSpline(x, y, z, x2, y, z2, 5);
SplineHelper.powerOffset(spline, size * MHelper.randRange(1.0F, 2.0F, random), 4);
SplineHelper.offsetParts(spline, random, 0.3F, 0, 0.3F);
Vector3f pos2 = spline.get(spline.size() - 1);
SplineHelper.fillSpline(spline, world, BlockRegistry.PYTHADENDRON.bark.getDefaultState(), pos, REPLACE);
boolean s2 = SplineHelper.fillSpline(spline, world, BlockRegistry.PYTHADENDRON.bark.getDefaultState(), pos, REPLACE);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextInt());
if (depth == 1) {
if (s1) {
SDF sphere = new SDFSphere().setRadius(MHelper.randRange(4.5F, 6.5F, random)).setBlock(BlockRegistry.PYTHADENDRON_LEAVES.getDefaultState().with(LeavesBlock.DISTANCE, 1));
sphere = new SDFScale3D().setScale(1, 0.4F, 1).setSource(sphere);
//sphere = new SDFTranslate().setTranslate(pos1.getX() + pos.getX(), pos1.getY() + pos.getY(), pos1.getZ() + pos.getZ()).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> { return (float) noise.eval(vec.getX() * 0.2, vec.getY() * 0.2, vec.getZ() * 0.2) * 3; }).setSource(sphere);
sphere.setReplaceFunction(REPLACE);
sphere.fillRecursive(world, new BlockPos(pos1.getX() + pos.getX(), pos1.getY() + pos.getY() + 1, pos1.getZ() + pos.getZ()));
}
if (s2) {
SDF sphere = new SDFSphere().setRadius(MHelper.randRange(4.5F, 6.5F, random)).setBlock(BlockRegistry.PYTHADENDRON_LEAVES.getDefaultState().with(LeavesBlock.DISTANCE, 1));
sphere = new SDFScale3D().setScale(1, 0.4F, 1).setSource(sphere);
//sphere = new SDFTranslate().setTranslate(pos2.getX() + pos.getX(), pos2.getY() + pos.getY(), pos2.getZ() + pos.getZ()).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> { return (float) noise.eval(vec.getX() * 0.2, vec.getY() * 0.2, vec.getZ() * 0.2) * 3; }).setSource(sphere);
sphere.setReplaceFunction(REPLACE);
sphere.fillRecursive(world, new BlockPos(pos2.getX() + pos.getX(), pos2.getY() + pos.getY() + 1, pos2.getZ() + pos.getZ()));
}
}
float size1 = size * MHelper.randRange(0.75F, 0.95F, random);
float size2 = size * MHelper.randRange(0.75F, 0.95F, random);
float angle1 = angle + (float) Math.PI * 0.5F + MHelper.randRange(-0.1F, 0.1F, random);
float angle2 = angle + (float) Math.PI * 0.5F + MHelper.randRange(-0.1F, 0.1F, random);
branch(pos1.getX(), pos1.getY(), pos1.getZ(), size1, angle1, random, depth - 1, world, pos);
branch(pos2.getX(), pos2.getY(), pos2.getZ(), size2, angle2, random, depth - 1, world, pos);
if (s1) {
branch(pos1.getX(), pos1.getY(), pos1.getZ(), size1, angle1, random, depth - 1, world, pos);
}
if (s2) {
branch(pos2.getX(), pos2.getY(), pos2.getZ(), size2, angle2, random, depth - 1, world, pos);
}
}
static {

View file

@ -1,16 +1,7 @@
{
"variants": {
"axis=x": [
{ "model": "betterend:block/pythadendron_log", "x": 90, "y": 90 },
{ "model": "betterend:block/pythadendron_log_2", "x": 90, "y": 90 }
],
"axis=y": [
{ "model": "betterend:block/pythadendron_log" },
{ "model": "betterend:block/pythadendron_log_2" }
],
"axis=z": [
{ "model": "betterend:block/pythadendron_log", "x": 90 },
{ "model": "betterend:block/pythadendron_log_2", "x": 90 }
]
"axis=x": { "model": "betterend:block/pythadendron_log", "x": 90, "y": 90 },
"axis=y": { "model": "betterend:block/pythadendron_log" },
"axis=z": { "model": "betterend:block/pythadendron_log", "x": 90 }
}
}

View file

@ -1,34 +1,12 @@
{
"parent": "block/cube",
"textures": {
"top": "betterend:block/pythadendron_log_top",
"side": "betterend:block/pythadendron_log_side_1",
"glow": "betterend:block/pythadendron_log_side_glow_1",
"particle": "#side"
},
"elements": [
{
"from": [ 0, 0, 0 ],
"to": [ 16, 16, 16 ],
"faces": {
"down": { "uv": [ 0, 0, 16, 16 ], "texture": "#top", "cullface": "down" },
"up": { "uv": [ 0, 0, 16, 16 ], "texture": "#top", "cullface": "up" },
"north": { "uv": [ 0, 0, 16, 16 ], "texture": "#side", "cullface": "north" },
"south": { "uv": [ 0, 0, 16, 16 ], "texture": "#side", "cullface": "south" },
"west": { "uv": [ 0, 0, 16, 16 ], "texture": "#side", "cullface": "west" },
"east": { "uv": [ 0, 0, 16, 16 ], "texture": "#side", "cullface": "east" }
}
},
{
"from": [ 0, 0, 0 ],
"to": [ 16, 16, 16 ],
"shade": false,
"faces": {
"north": { "uv": [ 0, 0, 16, 16 ], "texture": "#glow", "cullface": "north" },
"south": { "uv": [ 0, 0, 16, 16 ], "texture": "#glow", "cullface": "south" },
"west": { "uv": [ 0, 0, 16, 16 ], "texture": "#glow", "cullface": "west" },
"east": { "uv": [ 0, 0, 16, 16 ], "texture": "#glow", "cullface": "east" }
}
}
]
"parent": "block/cube",
"textures": {
"down": "betterend:block/pythadendron_log_top",
"east": "betterend:block/pythadendron_log_side",
"north": "betterend:block/pythadendron_log_side",
"particle": "betterend:block/pythadendron_log_side",
"south": "betterend:block/pythadendron_log_side",
"up": "betterend:block/pythadendron_log_top",
"west": "betterend:block/pythadendron_log_side"
}
}

View file

@ -1,34 +0,0 @@
{
"parent": "block/cube",
"textures": {
"top": "betterend:block/pythadendron_log_top",
"side": "betterend:block/pythadendron_log_side_2",
"glow": "betterend:block/pythadendron_log_side_glow_2",
"particle": "#side"
},
"elements": [
{
"from": [ 0, 0, 0 ],
"to": [ 16, 16, 16 ],
"faces": {
"down": { "uv": [ 0, 0, 16, 16 ], "texture": "#top", "cullface": "down" },
"up": { "uv": [ 0, 0, 16, 16 ], "texture": "#top", "cullface": "up" },
"north": { "uv": [ 0, 0, 16, 16 ], "texture": "#side", "cullface": "north" },
"south": { "uv": [ 0, 0, 16, 16 ], "texture": "#side", "cullface": "south" },
"west": { "uv": [ 0, 0, 16, 16 ], "texture": "#side", "cullface": "west" },
"east": { "uv": [ 0, 0, 16, 16 ], "texture": "#side", "cullface": "east" }
}
},
{
"from": [ 0, 0, 0 ],
"to": [ 16, 16, 16 ],
"shade": false,
"faces": {
"north": { "uv": [ 0, 0, 16, 16 ], "texture": "#glow", "cullface": "north" },
"south": { "uv": [ 0, 0, 16, 16 ], "texture": "#glow", "cullface": "south" },
"west": { "uv": [ 0, 0, 16, 16 ], "texture": "#glow", "cullface": "west" },
"east": { "uv": [ 0, 0, 16, 16 ], "texture": "#glow", "cullface": "east" }
}
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Before After
Before After