Intersections, lakes, cleanup

This commit is contained in:
paulevsGitch 2020-10-03 01:24:33 +03:00
parent 8eb15c8d73
commit 81e62efcf6
13 changed files with 77 additions and 33 deletions

View file

@ -7,6 +7,7 @@ import net.minecraft.world.Heightmap.Type;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import ru.betterend.util.BlocksHelper;
public abstract class DefaultFeature extends Feature<DefaultFeatureConfig> {
protected static final BlockState AIR = Blocks.AIR.getDefaultState();
@ -19,4 +20,14 @@ public abstract class DefaultFeature extends Feature<DefaultFeatureConfig> {
protected BlockPos getPosOnSurface(StructureWorldAccess world, BlockPos pos) {
return world.getTopPosition(Type.WORLD_SURFACE, pos);
}
protected BlockPos getPosOnSurfaceRaycast(StructureWorldAccess world, BlockPos pos) {
int h = BlocksHelper.downRay(world, pos, 256);
return pos.down(h);
}
protected BlockPos getPosOnSurfaceRaycast(StructureWorldAccess world, BlockPos pos, int dist) {
int h = BlocksHelper.downRay(world, pos, dist);
return pos.down(h);
}
}

View file

@ -48,12 +48,12 @@ public class EndFeature {
}
public static EndFeature makeRawGenFeature(String name, Feature<DefaultFeatureConfig> feature, int chance) {
ConfiguredFeature<?, ?> configured = feature.configure(FeatureConfig.DEFAULT).decorate(Decorator.CHANCE.configure(new ChanceDecoratorConfig(100)));
ConfiguredFeature<?, ?> configured = feature.configure(FeatureConfig.DEFAULT).decorate(Decorator.CHANCE.configure(new ChanceDecoratorConfig(chance)));
return new EndFeature(name, feature, GenerationStep.Feature.RAW_GENERATION, configured);
}
public static EndFeature makeLakeFeature(String name, Feature<DefaultFeatureConfig> feature, int chance) {
ConfiguredFeature<?, ?> configured = feature.configure(FeatureConfig.DEFAULT).decorate(Decorator.CHANCE.configure(new ChanceDecoratorConfig(100)));
ConfiguredFeature<?, ?> configured = feature.configure(FeatureConfig.DEFAULT).decorate(Decorator.WATER_LAKE.configure(new ChanceDecoratorConfig(chance)));
return new EndFeature(name, feature, GenerationStep.Feature.LAKES, configured);
}

View file

@ -4,6 +4,7 @@ import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.StructureWorldAccess;
@ -32,21 +33,22 @@ public class EndLakeFeature extends DefaultFeature {
int waterLevel = blockPos.getY();
BlockPos pos = getPosOnSurface(world, blockPos.north(dist));
if (pos.getY() < 10) return false;
BlockPos pos = getPosOnSurfaceRaycast(world, blockPos.north(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurface(world, blockPos.south(dist));
if (pos.getY() < 10) return false;
pos = getPosOnSurfaceRaycast(world, blockPos.south(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurface(world, blockPos.east(dist));
if (pos.getY() < 10) return false;
pos = getPosOnSurfaceRaycast(world, blockPos.east(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurface(world, blockPos.west(dist));
if (pos.getY() < 10) return false;
pos = getPosOnSurfaceRaycast(world, blockPos.west(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
BlockState state;
for (int y = blockPos.getY(); y <= blockPos.getY() + 10; y++) {
POS.setY(y);
@ -62,13 +64,14 @@ public class EndLakeFeature extends DefaultFeature {
double r = add * 1.8 + radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75);
r *= r;
if (x2 + z2 <= r) {
if (world.getBlockState(POS).isIn(BlockTagRegistry.END_GROUND)) {
state = world.getBlockState(POS);
if (state.isIn(BlockTagRegistry.END_GROUND) || !state.canPlaceAt(world, POS) || state.getBlock() == BlockRegistry.ENDSTONE_DUST) {
BlocksHelper.setWithoutUpdate(world, POS, AIR);
}
pos = POS.down();
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND))
{
BlockState state = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial();
state = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial();
if (y > waterLevel + 1)
BlocksHelper.setWithoutUpdate(world, pos, state);
else if (y > waterLevel)
@ -106,13 +109,16 @@ public class EndLakeFeature extends DefaultFeature {
r *= r;
rb *= rb;
if (y2 + x2 + z2 <= r) {
BlocksHelper.setWithoutUpdate(world, POS, y < waterLevel ? WATER : AIR);
state = world.getBlockState(POS);
if (state.isIn(BlockTagRegistry.END_GROUND) || state.getMaterial().equals(Material.PLANT) || state.getBlock() == BlockRegistry.ENDSTONE_DUST) {
BlocksHelper.setWithoutUpdate(world, POS, y < waterLevel ? WATER : AIR);
}
pos = POS.down();
if (world.getBlockState(pos).getBlock().isIn(BlockTagRegistry.END_GROUND))
BlocksHelper.setWithoutUpdate(world, POS.down(), BlockRegistry.ENDSTONE_DUST.getDefaultState());
pos = POS.up();
if (!world.getBlockState(pos).isAir()) {
while (!world.getBlockState(pos).isAir()) {
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
while (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR);
pos = pos.up();
}
@ -121,7 +127,7 @@ public class EndLakeFeature extends DefaultFeature {
else if (y <= waterLevel && y2 + x2 + z2 <= rb) {
if (world.getBlockState(POS).getMaterial().isReplaceable()) {
if (world.isAir(POS.up())) {
BlockState state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig().getTopMaterial();
state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig().getTopMaterial();
BlocksHelper.setWithoutUpdate(world, POS, random.nextBoolean() ? state : BlockRegistry.ENDSTONE_DUST.getDefaultState());
BlocksHelper.setWithoutUpdate(world, POS.down(), END_STONE);
}

View file

@ -10,7 +10,9 @@ 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.BlockPos.Mutable;
import net.minecraft.util.math.Direction;
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;
@ -50,6 +52,8 @@ public class MossyGlowshroomFeature extends DefaultFeature {
private static final SDFPrimitive CONE_GLOW;
private static final SDFPrimitive ROOTS;
private static final Mutable POS = new Mutable();
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig featureConfig) {
blockPos = getPosOnSurface(world, blockPos);
@ -77,8 +81,39 @@ public class MossyGlowshroomFeature extends DefaultFeature {
HEAD_POS.setTranslate(pos.getX(), pos.getY(), pos.getZ());
ROOTS_ROT.setAngle(random.nextFloat() * MHelper.PI2);
FUNCTION.setSourceA(sdf);
float scale = MHelper.randRange(0.75F, 1.1F, random);
Vector3f vec = spline.get(0);
float x1 = blockPos.getX() + vec.getX() * scale;
float y1 = blockPos.getY() + vec.getY() * scale;
float z1 = blockPos.getZ() + vec.getZ() * scale;
for (int i = 1; i < count; i++) {
vec = spline.get(i);
float x2 = blockPos.getX() + vec.getX() * scale;
float y2 = blockPos.getY() + vec.getY() * scale;
float z2 = blockPos.getZ() + vec.getZ() * scale;
for (float py = y1; py < y2; py += 3) {
if (py - blockPos.getY() < 10) continue;
float lerp = (py - y1) / (y2 - y1);
float x = MathHelper.lerp(lerp, x1, x2);
float z = MathHelper.lerp(lerp, z1, z2);
POS.set(x, py, z);
BlockState state = world.getBlockState(POS);
boolean generate = state.getMaterial().isReplaceable() || state.getMaterial().equals(Material.PLANT);
if (!generate) {
return false;
}
}
x1 = x2;
y1 = y2;
z1 = z2;
}
BlocksHelper.setWithoutUpdate(world, blockPos, AIR);
Set<BlockPos> blocks = new SDFScale()
.setScale(MHelper.randRange(0.75F, 1.1F, random))
.setScale(scale)
.setSource(FUNCTION)
.setReplaceFunction(REPLACE)
.setPostProcess(POST_PROCESS)

View file

@ -35,8 +35,8 @@ public class BetterEndBiomeSource extends BiomeSource {
public BetterEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
super(Collections.emptyList());
this.mapLand = new BiomeMap(seed, 50, BiomeRegistry.LAND_BIOMES);
this.mapVoid = new BiomeMap(seed, 50, BiomeRegistry.VOID_BIOMES);
this.mapLand = new BiomeMap(seed, 150, BiomeRegistry.LAND_BIOMES);
this.mapVoid = new BiomeMap(seed, 150, BiomeRegistry.VOID_BIOMES);
this.centerBiome = biomeRegistry.getOrThrow(BiomeKeys.THE_END);
this.biomeRegistry = biomeRegistry;
this.seed = seed;