Capsacis tree enhancements
This commit is contained in:
parent
527ba2bbaa
commit
7e750411a0
40 changed files with 172 additions and 28 deletions
|
@ -9,15 +9,18 @@ import com.google.common.collect.Lists;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
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.BlockProperties;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
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.SDFFlatWave;
|
||||
import ru.betterend.util.sdf.operator.SDFScale;
|
||||
import ru.betterend.util.sdf.operator.SDFSmoothUnion;
|
||||
import ru.betterend.util.sdf.operator.SDFTranslate;
|
||||
import ru.betterend.util.sdf.operator.SDFUnion;
|
||||
|
@ -28,12 +31,6 @@ import ru.betterend.world.features.DefaultFeature;
|
|||
public class CapsacisTreeFeature extends DefaultFeature {
|
||||
private static final Function<BlockState, Boolean> REPLACE;
|
||||
private static final List<Vector3f> ROOT;
|
||||
|
||||
private final Function<Random, BlockState> capFunction;
|
||||
|
||||
public CapsacisTreeFeature(Function<Random, BlockState> capFunction) {
|
||||
this.capFunction = capFunction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
|
||||
|
@ -49,30 +46,41 @@ public class CapsacisTreeFeature extends DefaultFeature {
|
|||
|
||||
BlockState woodState = EndBlocks.CAPSACIS.bark.getDefaultState();
|
||||
BlockState logState = EndBlocks.CAPSACIS.log.getDefaultState();
|
||||
BlockState capState = capFunction.apply(random);
|
||||
BlockState capState = EndBlocks.CAPSACIS_CAP.getDefaultState();
|
||||
|
||||
SplineHelper.offsetParts(spline, random, 0.5F, 0, 0.5F);
|
||||
SDF sdf = SplineHelper.buildSDF(spline, 2.5F, 0.8F, (bpos) -> {
|
||||
return woodState;
|
||||
});
|
||||
|
||||
SDF cap = makeCap(height * 0.2F, height * 0.25F, random, capState);
|
||||
final float scale = config == null ? 1 : MHelper.randRange(1, 3, random);
|
||||
final float offset = height * 0.2F;
|
||||
final float radius = height * 0.25F;
|
||||
final float heightScale = radius * 2 * scale;
|
||||
final int count = MHelper.randRange(5, 7, random);
|
||||
final float angle = random.nextFloat() * MHelper.PI2;
|
||||
SDF cap = makeCap(offset, radius, count, angle, capState);
|
||||
|
||||
sdf = new SDFUnion().setSourceA(sdf).setSourceB(cap);
|
||||
sdf = new SDFScale().setScale(scale).setSource(sdf);
|
||||
makeRoots(world, center, height * 0.4F, random, woodState);
|
||||
sdf.addPostProcess((info) -> {
|
||||
if (EndBlocks.CAPSACIS.isTreeLog(info.getStateUp()) && EndBlocks.CAPSACIS.isTreeLog(info.getStateDown())) {
|
||||
return logState;
|
||||
}
|
||||
else if (info.getState().equals(capState)) {
|
||||
double off = Math.cos(Math.atan2(info.getPos().getX() - pos.getX(), info.getPos().getZ() - pos.getZ()) * count + angle) * 2;
|
||||
int color = (int) ((info.getPos().getY() - pos.getY() - radius) / heightScale * 7 + off);
|
||||
color = 7 - MathHelper.clamp(color, 0, 7);
|
||||
return info.getState().with(BlockProperties.COLOR, color);
|
||||
}
|
||||
return info.getState();
|
||||
}).fillRecursive(world, center);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private SDF makeCap(float offset, float radius, Random random, BlockState capState) {
|
||||
float angle = random.nextFloat() * MHelper.PI2;
|
||||
int count = MHelper.randRange(5, 7, random);
|
||||
private SDF makeCap(float offset, float radius, int count, float angle, BlockState capState) {
|
||||
SDF cap = new SDFSphere().setRadius(radius).setBlock(capState);
|
||||
SDF cone = new SDFCappedCone().setRadius1(radius).setRadius2(radius * 0.4F).setHeight(radius * 0.3F).setBlock(capState);
|
||||
cone = new SDFTranslate().setTranslate(0, radius * 0.3F, 0).setSource(cone);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue