From 6f99cdf3a744c9b240df582aea24587aef380378 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Tue, 13 Oct 2020 15:13:49 +0300 Subject: [PATCH] Leaves --- .../ru/betterend/registry/BlockRegistry.java | 2 +- .../features/PythadendronTreeFeature.java | 41 +++++++++++++----- .../textures/block/pythadendron_log_side.png | Bin 0 -> 1639 bytes 3 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 src/main/resources/assets/betterend/textures/block/pythadendron_log_side.png diff --git a/src/main/java/ru/betterend/registry/BlockRegistry.java b/src/main/java/ru/betterend/registry/BlockRegistry.java index 3f8a57ff..3b932f7e 100644 --- a/src/main/java/ru/betterend/registry/BlockRegistry.java +++ b/src/main/java/ru/betterend/registry/BlockRegistry.java @@ -63,7 +63,7 @@ public class BlockRegistry { public static final WoodenMaterial MOSSY_GLOWSHROOM = new WoodenMaterial("mossy_glowshroom", MaterialColor.GRAY, MaterialColor.WOOD); public static final Block PYTHADENDRON_SAPLING = registerBlock("pythadendron_sapling", new BlockMossyPythadendronSapling()); - public static final Block PYTHADENDRON_LEAVES = registerBlock("pythadendron_leaves", new BlockLeaves(MaterialColor.MAGENTA, 8)); + public static final Block PYTHADENDRON_LEAVES = registerBlock("pythadendron_leaves", new BlockLeaves(MaterialColor.MAGENTA)); public static final WoodenMaterial PYTHADENDRON = new WoodenMaterial("pythadendron", MaterialColor.MAGENTA, MaterialColor.PURPLE); // Small Plants // diff --git a/src/main/java/ru/betterend/world/features/PythadendronTreeFeature.java b/src/main/java/ru/betterend/world/features/PythadendronTreeFeature.java index 3a824d56..78577afc 100644 --- a/src/main/java/ru/betterend/world/features/PythadendronTreeFeature.java +++ b/src/main/java/ru/betterend/world/features/PythadendronTreeFeature.java @@ -13,13 +13,17 @@ 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.SDFScale; +import ru.betterend.util.sdf.operator.SDFTranslate; import ru.betterend.util.sdf.operator.SDFUnion; +import ru.betterend.util.sdf.primitive.SDFSphere; public class PythadendronTreeFeature extends DefaultFeature { private static final Function REPLACE; @@ -28,12 +32,13 @@ public class PythadendronTreeFeature extends DefaultFeature { public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) { if (world.getBlockState(pos.down()).getBlock() != BlockRegistry.CHORUS_NYLIUM) return false; - float size = MHelper.randRange(10, 20, random); + float size = MHelper.randRange(10, 13, random); List> splines = Lists.newArrayList(); List spline = SplineHelper.makeSpline(0, 0, 0, 0, size, 0, 4); SplineHelper.offsetParts(spline, random, 0.7F, 0, 0.7F); Vector3f last = spline.get(spline.size() - 1); - branch(splines, last.getX(), last.getY(), last.getZ(), size * 0.6F, MHelper.randRange(0, MHelper.PI2, random), random, MHelper.floor(Math.log(size) * 1.5F)); + List ends = Lists.newArrayList(); + branch(splines, ends, last.getX(), last.getY(), last.getZ(), size * 0.6F, MHelper.randRange(0, MHelper.PI2, random), random, MHelper.floor(Math.log(size) * 1.5F)); SDF function = SplineHelper.buildSDF(spline, 1.4F, 0.8F, (bpos) -> { return BlockRegistry.PYTHADENDRON.bark.getDefaultState(); @@ -41,21 +46,28 @@ public class PythadendronTreeFeature extends DefaultFeature { for (List sp: splines) { float width = 0.8F - (sp.get(0).getY() - size) / 40; - if (size > 0F) { - SDF funcSp = SplineHelper.buildSDF(sp, width, width, (bpos) -> { - return BlockRegistry.PYTHADENDRON.bark.getDefaultState(); - }); - function = new SDFUnion().setSourceA(function).setSourceB(funcSp); - } + SDF funcSp = SplineHelper.buildSDF(sp, width, width, (bpos) -> { + return BlockRegistry.PYTHADENDRON.bark.getDefaultState(); + }); + function = new SDFUnion().setSourceA(function).setSourceB(funcSp); } - function = new SDFScale().setScale(MHelper.randRange(1F, 2F, random)).setSource(function); + + OpenSimplexNoise noise = new OpenSimplexNoise(random.nextInt()); + for (Vector3f v: ends) { + SDF sphere = new SDFSphere().setRadius(MHelper.randRange(2.5F, 3.5F, random)).setBlock(BlockRegistry.PYTHADENDRON_LEAVES); + sphere = new SDFTranslate().setTranslate(v.getX(), v.getY(), v.getZ()).setSource(sphere); + sphere = new SDFDisplacement().setFunction((vec) -> { return (float) noise.eval(vec.getX() * 0.2, vec.getY() * 0.2, vec.getZ() * 0.2); }).setSource(sphere); + function = new SDFUnion().setSourceA(function).setSourceB(sphere); + } + + function = new SDFScale().setScale(MHelper.randRange(1.6F, 2.0F, random)).setSource(function); function.setReplaceFunction(REPLACE); function.fillRecursive(world, pos); return true; } - private void branch(List> splines, float x, float y, float z, float size, float angle, Random random, int depth) { + private void branch(List> splines, List ends, float x, float y, float z, float size, float angle, Random random, int depth) { if (depth == 0) return; float dx = (float) Math.cos(angle) * size * 0.3F; @@ -78,8 +90,13 @@ public class PythadendronTreeFeature extends DefaultFeature { splines.add(spline); Vector3f pos2 = spline.get(spline.size() - 1); - branch(splines, pos1.getX(), pos1.getY(), pos1.getZ(), size * 0.8F, angle + (float) Math.PI * 0.5F, random, depth - 1); - branch(splines, pos2.getX(), pos2.getY(), pos2.getZ(), size * 0.8F, angle + (float) Math.PI * 0.5F, random, depth - 1); + if (depth == 1) { + ends.add(pos1); + ends.add(pos2); + } + + branch(splines, ends, pos1.getX(), pos1.getY(), pos1.getZ(), size * 0.8F, angle + (float) Math.PI * 0.5F, random, depth - 1); + branch(splines, ends, pos2.getX(), pos2.getY(), pos2.getZ(), size * 0.8F, angle + (float) Math.PI * 0.5F, random, depth - 1); } static { diff --git a/src/main/resources/assets/betterend/textures/block/pythadendron_log_side.png b/src/main/resources/assets/betterend/textures/block/pythadendron_log_side.png new file mode 100644 index 0000000000000000000000000000000000000000..cf0f76a958de5556962dc78e7d21e738274fef00 GIT binary patch literal 1639 zcmbVNZEO=|9KYcLWwJUH$()j0ZbR|qdT(9ZJ1JwdWv%hX+$t2J(d*sQ_E_(p z_x%2^&;N#cy1N=1S{g76Ym7z1y{K<;Ue_}8ePKA`L)}Uvy3@k28*g#mI_%I$GltbK zsquuJ5FZp|sCgs>CV{7*83>JG8#@YyB=-XwPlB|n2ZkLFqLeK<=qev0-}3`f$8K>Gxa$19CM(o7{K^oF-qWT9D*$k?_a zP*gsj_vASbG}9Er^E^ef6w8tbL0U!KmI|b9wN@Fzz>-bXuvMtz4x^NWIXg%oP0J=| zMvYdtDsDm!qY9EiF&^46sRUHy8qUa>*^+QYra%^GK({S~WolUDB~h%wuS%2{c`XiYOHn$(F7S z3>7t1{7*^(}USU5-^RXwVz2!21ur&6p!DuJX# z252u&@(SZ81AaEi`@M{u=v3t3zl~t7Je&<;z5M%C#V`!mzrQ zShzF3VOZ-u>^@GfdE`Wsof_P|7^T}>^=BaYarzYECXS^4t$B*1|{*H6g)(A353>XmH=$ zH~sX~{M3;M*l8{<4}mv)yONE^hTnPZr?qvNb-Y@ EPs!vZZ2$lO literal 0 HcmV?d00001