Tree ptototype changes
This commit is contained in:
parent
188ccd7855
commit
9231618094
3 changed files with 119 additions and 29 deletions
|
@ -1,5 +1,6 @@
|
|||
package ru.betterend.integration.byg;
|
||||
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import ru.betterend.integration.Integrations;
|
||||
import ru.betterend.world.biome.BiomeDefinition;
|
||||
import ru.betterend.world.biome.EndBiome;
|
||||
|
@ -7,6 +8,10 @@ import ru.betterend.world.biome.EndBiome;
|
|||
public class OldBulbisGardens extends EndBiome {
|
||||
public OldBulbisGardens() {
|
||||
super(new BiomeDefinition("old_bulbis_gardens")
|
||||
.setFogColor(132, 0, 202)
|
||||
.setFogDensity(2F)
|
||||
.setWaterAndFogColor(40, 0, 56)
|
||||
.setParticles(ParticleTypes.REVERSE_PORTAL, 0.002F)
|
||||
.setSurface(Integrations.BYG.getBlock("ivis_phylium"))
|
||||
.addFeature(BYGFeatures.OLD_BULBIS_TREE)
|
||||
.addFeature(BYGFeatures.IVIS_SPROUT));
|
||||
|
|
|
@ -7,55 +7,44 @@ import java.util.function.Function;
|
|||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.Material;
|
||||
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;
|
||||
import ru.betterend.integration.Integrations;
|
||||
import ru.betterend.noise.OpenSimplexNoise;
|
||||
import ru.betterend.registry.EndTags;
|
||||
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.SDFSubtraction;
|
||||
import ru.betterend.util.sdf.operator.SDFTranslate;
|
||||
import ru.betterend.util.sdf.operator.SDFUnion;
|
||||
import ru.betterend.util.sdf.primitive.SDFSphere;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class OldBulbisTreeFeature extends DefaultFeature {
|
||||
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise("OldBulbisTreeFeature".hashCode());
|
||||
private static final List<Vector3f> SPLINE;
|
||||
private static final List<Vector3f> ROOT;
|
||||
private static final List<Vector3f> LEAF;
|
||||
private static final List<Vector3f> SIDE;
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
|
||||
if (!world.getBlockState(pos.down()).getBlock().isIn(EndTags.END_GROUND)) return false;
|
||||
if (!world.getBlockState(pos.down(4)).getBlock().isIn(EndTags.GEN_TERRAIN)) return false;
|
||||
|
||||
BlockState stem = Integrations.BYG.getDefaultState("bulbis_stem");
|
||||
BlockState wood = Integrations.BYG.getDefaultState("bulbis_wood");
|
||||
BlockState cap = Integrations.BYG.getDefaultState(random.nextBoolean() ? "bulbis_shell" : "purple_bulbis_shell");
|
||||
|
||||
float size = MHelper.randRange(10, 20, random);
|
||||
int count = (int) (size * 0.45F);
|
||||
float var = MHelper.PI2 / (float) (count * 3);
|
||||
float start = MHelper.randRange(0, MHelper.PI2, random);
|
||||
SDF sdf = null;
|
||||
for (int i = 0; i < count; i++) {
|
||||
float angle = (float) i / (float) count * MHelper.PI2 + MHelper.randRange(0, var, random) + start;
|
||||
List<Vector3f> spline = SplineHelper.copySpline(SPLINE);
|
||||
SplineHelper.scale(spline, size + MHelper.randRange(0, size * 0.5F, random));
|
||||
SplineHelper.offset(spline, new Vector3f((20 - size) * 0.6F, 0, 0));
|
||||
SplineHelper.rotateSpline(spline, angle);
|
||||
SplineHelper.offsetParts(spline, random, 1F, 0, 1F);
|
||||
SDF branch = SplineHelper.buildSDF(spline, 1.3F, 0.8F, (bpos) -> {
|
||||
return stem;
|
||||
});
|
||||
Vector3f last = spline.get(spline.size() - 1);
|
||||
SDF sphere = new SDFSphere().setRadius((size + MHelper.randRange(0, size * 0.5F, random)) * 0.2F).setBlock(cap);
|
||||
sphere = new SDFTranslate().setTranslate(last.getX(), last.getY(), last.getZ()).setSource(sphere);
|
||||
branch = new SDFUnion().setSourceA(branch).setSourceB(sphere);
|
||||
sdf = (sdf == null) ? branch : new SDFUnion().setSourceA(sdf).setSourceB(branch);
|
||||
}
|
||||
BlockState glow = Integrations.BYG.getDefaultState("purple_shroomlight");
|
||||
|
||||
Function<BlockState, Boolean> replacement = (state) -> {
|
||||
if (state.equals(stem) || state.equals(wood) || state.isIn(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT)) {
|
||||
|
@ -64,17 +53,93 @@ public class OldBulbisTreeFeature extends DefaultFeature {
|
|||
return state.getMaterial().isReplaceable();
|
||||
};
|
||||
|
||||
float size = MHelper.randRange(10, 20, random);
|
||||
int count = (int) (size * 0.15F);
|
||||
float var = MHelper.PI2 / (float) (count * 3);
|
||||
float start = MHelper.randRange(0, MHelper.PI2, random);
|
||||
SDF sdf = null;
|
||||
int x1 = ((pos.getX() >> 4) << 4) - 16;
|
||||
int z1 = ((pos.getZ() >> 4) << 4) - 16;
|
||||
Box limits = new Box(x1, pos.getY() - 5, z1, x1 + 47, pos.getY() + size * 2, z1 + 47);
|
||||
for (int i = 0; i < count; i++) {
|
||||
float angle = (float) i / (float) count * MHelper.PI2 + MHelper.randRange(0, var, random) + start;
|
||||
List<Vector3f> spline = SplineHelper.copySpline(SPLINE);
|
||||
float sizeXZ = (size + MHelper.randRange(0, size * 0.5F, random)) * 0.7F;
|
||||
SplineHelper.scale(spline, sizeXZ, sizeXZ * 1.5F + MHelper.randRange(0, size * 0.5F, random), sizeXZ);
|
||||
SplineHelper.offset(spline, new Vector3f((20 - size), 0, 0));
|
||||
SplineHelper.rotateSpline(spline, angle);
|
||||
SplineHelper.offsetParts(spline, random, 1F, 0, 1F);//1.3F 0.8F
|
||||
SDF branch = SplineHelper.buildSDF(spline, 2.3F, 1.3F, (bpos) -> {
|
||||
return stem;
|
||||
});
|
||||
|
||||
Vector3f vec = spline.get(spline.size() - 1);
|
||||
float radius = (size + MHelper.randRange(0, size * 0.5F, random)) * 0.35F;
|
||||
bigSphere(world, pos.add(vec.getX(), vec.getY(), vec.getZ()), radius, cap, glow, wood, replacement);
|
||||
vec = SplineHelper.getPos(spline, 0.3F);
|
||||
makeRoots(world, pos.add(vec.getX(), vec.getY(), vec.getZ()), size * 0.4F + 5, random, wood, replacement);
|
||||
|
||||
sdf = (sdf == null) ? branch : new SDFUnion().setSourceA(sdf).setSourceB(branch);
|
||||
}
|
||||
|
||||
sdf.setReplaceFunction(replacement).setPostProcess((info) -> {
|
||||
if (info.getState().equals(stem) && (!info.getStateUp().equals(stem) || !info.getStateDown().equals(stem))) {
|
||||
return wood;
|
||||
}
|
||||
return info.getState();
|
||||
}).fillRecursive(world, pos);
|
||||
makeRoots(world, pos, size * 0.4F + 5, random, wood, replacement);
|
||||
}).fillArea(world, pos, limits);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void bigSphere(StructureWorldAccess world, BlockPos pos, float radius, BlockState cap, BlockState glow, BlockState wood, Function<BlockState, Boolean> replacement) {
|
||||
SDF sphere = new SDFSphere().setRadius(radius).setBlock(cap);
|
||||
|
||||
SDF sphereInner = new SDFSphere().setRadius(radius * 0.53F).setBlock(Blocks.AIR);
|
||||
sphereInner = new SDFDisplacement().setFunction((vec) -> {
|
||||
return (float) NOISE.eval(vec.getX() * 0.1, vec.getY() * 0.1, vec.getZ() * 0.1);
|
||||
}).setSource(sphereInner);
|
||||
|
||||
SDF sphereGlow = new SDFSphere().setRadius(radius * 0.6F).setBlock(glow);
|
||||
sphereGlow = new SDFDisplacement().setFunction((vec) -> {
|
||||
return (float) NOISE.eval(vec.getX() * 0.1, vec.getY() * 0.1, vec.getZ() * 0.1) * 2F;
|
||||
}).setSource(sphereGlow);
|
||||
sphereGlow = new SDFSubtraction().setSourceA(sphereGlow).setSourceB(sphereInner);
|
||||
|
||||
sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sphereGlow);
|
||||
sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sphereInner);
|
||||
|
||||
float offsetY = radius * 1.7F;
|
||||
sphere = new SDFUnion().setSourceA(sphere).setSourceB(sphereGlow);
|
||||
sphere = new SDFTranslate().setTranslate(0, offsetY, 0).setSource(sphere);
|
||||
|
||||
int leafCount = (int) (radius * 0.5F) + 2;
|
||||
System.out.println("Origin " + pos);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
float angle = (float) i / 4 * MHelper.PI2;
|
||||
List<Vector3f> spline = SplineHelper.copySpline(LEAF);
|
||||
SplineHelper.rotateSpline(spline, angle);
|
||||
SplineHelper.scale(spline, radius * 1.4F);
|
||||
SplineHelper.fillSplineForce(spline, world, wood, pos, replacement);
|
||||
|
||||
for (int j = 0; j < leafCount; j++) {
|
||||
float delta = ((float) j / (float) (leafCount - 1));
|
||||
float scale = (float) Math.sin(delta * Math.PI) * 0.8F + 0.2F;
|
||||
float index = MathHelper.lerp(delta, 1F, 3.9F);
|
||||
Vector3f point = SplineHelper.getPos(spline, index);
|
||||
|
||||
List<Vector3f> side = SplineHelper.copySpline(SIDE);
|
||||
SplineHelper.rotateSpline(side, angle);
|
||||
SplineHelper.scale(side, scale * radius);
|
||||
BlockPos p = pos.add(point.getX() + 0.5F, point.getY() + 0.5F, point.getZ() + 0.5F);
|
||||
SplineHelper.fillSplineForce(side, world, wood, p, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
sphere.fillArea(world, pos, new Box(pos.up((int) offsetY)).expand(radius * 1.3F));
|
||||
}
|
||||
|
||||
private void makeRoots(StructureWorldAccess world, BlockPos pos, float radius, Random random, BlockState wood, Function<BlockState, Boolean> replacement) {
|
||||
int count = (int) (radius * 1.5F);
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
@ -102,11 +167,27 @@ public class OldBulbisTreeFeature extends DefaultFeature {
|
|||
);
|
||||
|
||||
ROOT = Lists.newArrayList(new Vector3f(0F, 1F, 0),
|
||||
new Vector3f(0.1F, 0.7F, 0),
|
||||
new Vector3f(0.3F, 0.3F, 0),
|
||||
new Vector3f(0.7F, 0.05F, 0),
|
||||
new Vector3f(0.8F, -0.2F, 0)
|
||||
new Vector3f(0.1F, 0.70F, 0),
|
||||
new Vector3f(0.3F, 0.30F, 0),
|
||||
new Vector3f(0.7F, 0.05F, 0),
|
||||
new Vector3f(0.8F, -0.20F, 0)
|
||||
);
|
||||
SplineHelper.offset(ROOT, new Vector3f(0, -0.45F, 0));
|
||||
|
||||
LEAF = Lists.newArrayList(
|
||||
new Vector3f(0.00F, 0.0F, 0),
|
||||
new Vector3f(0.10F, 0.4F, 0),
|
||||
new Vector3f(0.40F, 0.8F, 0),
|
||||
new Vector3f(0.75F, 0.9F, 0),
|
||||
new Vector3f(1.00F, 0.8F, 0)
|
||||
);
|
||||
|
||||
SIDE = Lists.newArrayList(
|
||||
new Vector3f(0, -0.3F, -0.5F),
|
||||
new Vector3f(0, -0.1F, -0.3F),
|
||||
new Vector3f(0, 0.0F, 0.0F),
|
||||
new Vector3f(0, -0.1F, 0.3F),
|
||||
new Vector3f(0, -0.3F, 0.5F)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -281,8 +281,12 @@ public class SplineHelper {
|
|||
}
|
||||
|
||||
public static void scale(List<Vector3f> spline, float scale) {
|
||||
scale(spline, scale, scale, scale);
|
||||
}
|
||||
|
||||
public static void scale(List<Vector3f> spline, float x, float y, float z) {
|
||||
for (Vector3f v: spline) {
|
||||
v.set(v.getX() * scale, v.getY() * scale, v.getZ() * scale);
|
||||
v.set(v.getX() * x, v.getY() * y, v.getZ() * z);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue