Cave bushes

This commit is contained in:
paulevsGitch 2020-10-21 17:02:22 +03:00
parent 8a89794f08
commit 28d501f351
19 changed files with 264 additions and 11 deletions

View file

@ -0,0 +1,55 @@
package ru.betterend.world.features;
import java.util.Random;
import java.util.function.Function;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.BlockRegistry;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
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.SDFSubtraction;
import ru.betterend.util.sdf.operator.SDFTranslate;
import ru.betterend.util.sdf.primitive.SDFSphere;
public class CaveBushFeature extends FullHeightScatterFeature {
public CaveBushFeature(int radius) {
super(radius);
}
private static final Function<BlockState, Boolean> REPLACE;
@Override
public boolean canGenerate(StructureWorldAccess world, Random random, BlockPos center, BlockPos blockPos, float radius) {
return world.getBlockState(blockPos.down()).isOf(BlockRegistry.CAVE_MOSS);
}
@Override
public void generate(StructureWorldAccess world, Random random, BlockPos blockPos) {
float radius = MHelper.randRange(0.8F, 2.5F, random);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextInt());
SDF sphere = new SDFSphere().setRadius(radius).setBlock(BlockRegistry.CAVE_BUSH);
sphere = new SDFScale3D().setScale(MHelper.randRange(0.8F, 1.2F, random), MHelper.randRange(0.8F, 1.2F, random), MHelper.randRange(0.8F, 1.2F, random)).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 = new SDFDisplacement().setFunction((vec) -> { return random.nextFloat() * 3F - 1.5F; }).setSource(sphere);
sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(new SDFTranslate().setTranslate(0, -radius, 0).setSource(sphere));
sphere.setReplaceFunction(REPLACE);
sphere.fillRecursive(world, blockPos);
BlocksHelper.setWithoutUpdate(world, blockPos, BlockRegistry.CAVE_BUSH);
}
static {
REPLACE = (state) -> {
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
}
}

View file

@ -0,0 +1,56 @@
package ru.betterend.world.features;
import java.util.Random;
import java.util.function.Function;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.BlockRegistry;
import ru.betterend.registry.BlockTagRegistry;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
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.SDFSubtraction;
import ru.betterend.util.sdf.operator.SDFTranslate;
import ru.betterend.util.sdf.primitive.SDFSphere;
public class CaveBushFeatureCeil extends InvertedScatterFeature {
public CaveBushFeatureCeil(int radius) {
super(radius);
}
private static final Function<BlockState, Boolean> REPLACE;
@Override
public boolean canGenerate(StructureWorldAccess world, Random random, BlockPos center, BlockPos blockPos, float radius) {
return blockPos.getY() < 64 && world.isAir(blockPos) && world.getBlockState(blockPos.up()).isIn(BlockTagRegistry.GEN_TERRAIN);
}
@Override
public void generate(StructureWorldAccess world, Random random, BlockPos blockPos) {
float radius = MHelper.randRange(0.8F, 2.5F, random);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextInt());
SDF sphere = new SDFSphere().setRadius(radius).setBlock(BlockRegistry.CAVE_BUSH);
sphere = new SDFScale3D().setScale(MHelper.randRange(0.8F, 1.2F, random), MHelper.randRange(0.8F, 1.2F, random), MHelper.randRange(0.8F, 1.2F, random)).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 = new SDFDisplacement().setFunction((vec) -> { return random.nextFloat() * 3F - 1.5F; }).setSource(sphere);
sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(new SDFTranslate().setTranslate(0, -radius, 0).setSource(sphere));
sphere.setReplaceFunction(REPLACE);
sphere.fillRecursive(world, blockPos.down());
BlocksHelper.setWithoutUpdate(world, blockPos.down(), BlockRegistry.CAVE_BUSH);
}
static {
REPLACE = (state) -> {
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
}
}

View file

@ -4,6 +4,7 @@ import java.util.Random;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.Heightmap;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -24,7 +25,9 @@ public abstract class InvertedScatterFeature extends DefaultFeature {
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos center, DefaultFeatureConfig featureConfig) {
for (int y = 128; y > 0; y--) {
int maxY = world.getTopY(Heightmap.Type.WORLD_SURFACE_WG, center.getX(), center.getZ());
int minY = BlocksHelper.upRay(world, new BlockPos(center.getX(), 0, center.getZ()), maxY);
for (int y = maxY; y > minY; y--) {
POS.set(center.getX(), y, center.getZ());
if (world.getBlockState(POS).isAir() && !world.getBlockState(POS.up()).isAir()) {
float r = MHelper.randRange(radius * 0.5F, radius, random);

View file

@ -3,6 +3,7 @@ package ru.betterend.world.features;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
@ -44,9 +45,7 @@ public class RoundCave extends DefaultFeature {
double nr = radius * 0.25;
Mutable bpos = new Mutable();
BlockState stateGround;
BlockState terrain = BlockRegistry.CAVE_MOSS.getDefaultState();
//BlockState grass = BlockRegistry.CAVE_GRASS.getDefaultState();
for (int x = x1; x <= x2; x++) {
int xsq = x - pos.getX();
xsq *= xsq;
@ -63,16 +62,12 @@ public class RoundCave extends DefaultFeature {
double r = noise.eval(x * 0.1, y * 0.1, z * 0.1) * nr + hr;
double dist = xsq + ysq + zsq;
if (dist < r * r) {
if ((stateGround = world.getBlockState(bpos)).isIn(BlockTagRegistry.GEN_TERRAIN) || stateGround.getMaterial().isReplaceable()) {
if (isReplaceable(world.getBlockState(bpos))) {
BlocksHelper.setWithoutUpdate(world, bpos, AIR);
}
bpos.setY(y - 1);
if (world.getBlockState(bpos).isIn(BlockTagRegistry.GEN_TERRAIN)) {
BlocksHelper.setWithoutUpdate(world, bpos, terrain);
/*if (random.nextInt(8) == 0) {
bpos.setY(y);
BlocksHelper.setWithoutUpdate(world, bpos, grass);
}*/
}
}
}
@ -95,6 +90,15 @@ public class RoundCave extends DefaultFeature {
}
}
BlocksHelper.fixBlocks(world, new BlockPos(x1, y1, z1), new BlockPos(x2, y2, z2));
return true;
}
private boolean isReplaceable(BlockState state) {
return state.isIn(BlockTagRegistry.GEN_TERRAIN)
|| state.getMaterial().isReplaceable()
|| state.getMaterial().equals(Material.PLANT)
|| state.getMaterial().equals(Material.LEAVES);
}
}