Merge remote-tracking branch 'origin/master'

This commit is contained in:
Aleksey 2021-04-29 18:12:01 +03:00
commit 3d2a495221
35 changed files with 198 additions and 49 deletions

View file

@ -74,13 +74,12 @@ public class EndTerrainBlock extends BlockBase {
@Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
if (random.nextInt(16) == 0 && !canSurvive(state, world, pos)) {
if (random.nextInt(16) == 0 && !canStay(state, world, pos)) {
world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState());
}
}
@Override
public boolean canSurvive(BlockState state, LevelReader worldView, BlockPos pos) {
public boolean canStay(BlockState state, LevelReader worldView, BlockPos pos) {
BlockPos blockPos = pos.above();
BlockState blockState = worldView.getBlockState(blockPos);
if (blockState.is(Blocks.SNOW) && (Integer) blockState.getValue(SnowLayerBlock.LAYERS) == 1) {

View file

@ -83,14 +83,14 @@ public class TripleTerrainBlock extends EndTerrainBlock {
return;
}
else if (random.nextInt(16) == 0) {
boolean bottom = canSurviveBottom(world, pos);
boolean bottom = canStayBottom(world, pos);
if (shape == TripleShape.TOP) {
if (!bottom) {
world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState());
}
}
else {
boolean top = canSurvive(state, world, pos) || isMiddle(world.getBlockState(pos.above()));
boolean top = canStay(state, world, pos) || isMiddle(world.getBlockState(pos.above()));
if (!top && !bottom) {
world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState());
}
@ -104,7 +104,7 @@ public class TripleTerrainBlock extends EndTerrainBlock {
}
}
protected boolean canSurviveBottom(LevelReader world, BlockPos pos) {
protected boolean canStayBottom(LevelReader world, BlockPos pos) {
BlockPos blockPos = pos.below();
BlockState blockState = world.getBlockState(blockPos);
if (isMiddle(blockState)) {

View file

@ -52,6 +52,49 @@ public class VoronoiNoise {
return Math.sqrt(d);
}
public Random getRandom(double x, double y, double z) {
int ix = MHelper.floor(x);
int iy = MHelper.floor(y);
int iz = MHelper.floor(z);
float px = (float) (x - ix);
float py = (float) (y - iy);
float pz = (float) (z - iz);
float d = 10;
int posX = 0;
int posY = 0;
int posZ = 0;
for (int pox = -1; pox < 2; pox++) {
for (int poy = -1; poy < 2; poy++) {
for (int poz = -1; poz < 2; poz++) {
RANDOM.setSeed(getSeed(pox + ix, poy + iy, poz + iz));
float pointX = pox + RANDOM.nextFloat();
float pointY = poy + RANDOM.nextFloat();
float pointZ = poz + RANDOM.nextFloat();
float d2 = MHelper.lengthSqr(pointX - px, pointY - py, pointZ - pz);
if (d2 < d) {
d = d2;
posX = pox;
posY = poy;
posZ = poz;
}
}
}
}
posX += ix;
posY += iy;
posZ += iz;
int seed = MHelper.getSeed(posY, posX, posZ);
RANDOM.setSeed(seed);
return RANDOM;
}
public BlockPos[] getPos(double x, double y, double z, double scale) {
int ix = MHelper.floor(x);
int iy = MHelper.floor(y);

View file

@ -60,6 +60,7 @@ import ru.betterend.world.features.terrain.SulphuricCaveFeature;
import ru.betterend.world.features.terrain.SulphuricLakeFeature;
import ru.betterend.world.features.terrain.SurfaceVentFeature;
import ru.betterend.world.features.terrain.caves.RoundCaveFeature;
import ru.betterend.world.features.terrain.caves.TunelCaveFeature;
import ru.betterend.world.features.trees.DragonTreeFeature;
import ru.betterend.world.features.trees.GiganticAmaranitaFeature;
import ru.betterend.world.features.trees.HelixTreeFeature;
@ -201,7 +202,7 @@ public class EndFeatures {
public static final EndFeature OBSIDIAN_PILLAR_BASEMENT = EndFeature.makeChansedFeature("obsidian_pillar_basement", new ObsidianPillarBasementFeature(), 8);
public static final EndFeature OBSIDIAN_BOULDER = EndFeature.makeChansedFeature("obsidian_boulder", new ObsidianBoulderFeature(), 10);
public static final EndFeature FALLEN_PILLAR = EndFeature.makeChansedFeature("fallen_pillar", new FallenPillarFeature(), 20);
//public static final EndFeature TUNEL_CAVE = EndFeature.makeRawGenFeature("tunel_cave", new TunelCaveFeature(), 2);
public static final EndFeature TUNEL_CAVE = EndFeature.makeChunkFeature("tunel_cave", new TunelCaveFeature());
// Ores //
public static final EndFeature THALLASIUM_ORE = EndFeature.makeOreFeature("thallasium_ore", EndBlocks.THALLASIUM.ore, 12, 6, 0, 16, 128);
@ -258,7 +259,7 @@ public class EndFeatures {
if (EndBiomes.getBiome(id).hasCaves()) {
addFeature(ROUND_CAVE, features);
//addFeature(TUNEL_CAVE, features);
addFeature(TUNEL_CAVE, features);
}
EndBiome endBiome = EndBiomes.getBiome(id);
@ -276,7 +277,7 @@ public class EndFeatures {
if (def.hasCaves()) {
def.addFeature(ROUND_CAVE);
//def.addFeature(TUNEL_CAVE);
def.addFeature(TUNEL_CAVE);
}
}

View file

@ -128,7 +128,17 @@ public class EndTags {
});
ToolManagerImpl.tag(HAMMERS).register(new ModdedToolsVanillaBlocksToolHandler(hammers));
TagHelper.addTag(GEN_TERRAIN, EndBlocks.ENDER_ORE, EndBlocks.FLAVOLITE.stone, EndBlocks.VIOLECITE.stone, EndBlocks.SULPHURIC_ROCK.stone, EndBlocks.BRIMSTONE);
TagHelper.addTag(
GEN_TERRAIN,
EndBlocks.ENDER_ORE,
EndBlocks.FLAVOLITE.stone,
EndBlocks.VIOLECITE.stone,
EndBlocks.SULPHURIC_ROCK.stone,
EndBlocks.BRIMSTONE,
EndBlocks.VIRID_JADESTONE.stone,
EndBlocks.AZURE_JADESTONE.stone,
EndBlocks.SANDY_JADESTONE.stone
);
TagHelper.addTag(END_GROUND, EndBlocks.SULPHURIC_ROCK.stone, EndBlocks.BRIMSTONE);
TagHelper.addTag(FURNACES, Blocks.FURNACE);

View file

@ -146,7 +146,7 @@ public abstract class EndCaveFeature extends DefaultFeature {
blocks.forEach((pos) -> setBiome(world, pos, biome));
}
private void setBiome(WorldGenLevel world, BlockPos pos, EndCaveBiome biome) {
protected void setBiome(WorldGenLevel world, BlockPos pos, EndCaveBiome biome) {
IBiomeArray array = (IBiomeArray) world.getChunk(pos).getBiomes();
if (array != null) {
Biome bio = EndBiomes.getActualBiome(biome);
@ -184,7 +184,7 @@ public abstract class EndCaveFeature extends DefaultFeature {
return new BlockPos(pos.getX(), MHelper.randRange(bottom, top, random), pos.getZ());
}
private void fixBlocks(WorldGenLevel world, Set<BlockPos> caveBlocks) {
protected void fixBlocks(WorldGenLevel world, Set<BlockPos> caveBlocks) {
BlockPos pos = caveBlocks.iterator().next();
MutableBlockPos start = new MutableBlockPos().set(pos);
MutableBlockPos end = new MutableBlockPos().set(pos);
@ -210,7 +210,7 @@ public abstract class EndCaveFeature extends DefaultFeature {
end.setZ(bpos.getZ());
}
});
BlocksHelper.fixBlocks(world, start.offset(-5, -5, -5), end.offset(5, 5, 5));
BlocksHelper.fixBlocks(world, start.offset(-2, -2, -2), end.offset(2, 2, 2));
}
protected boolean isWaterNear(WorldGenLevel world, BlockPos pos) {

View file

@ -1,55 +1,149 @@
package ru.betterend.world.features.terrain.caves;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.function.Function;
import com.mojang.math.Vector3f;
import com.google.common.collect.Sets;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.EndBiomes;
import ru.betterend.registry.EndTags;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.SplineHelper;
import ru.betterend.util.sdf.SDF;
import ru.betterend.world.biome.cave.EndCaveBiome;
public class TunelCaveFeature extends EndCaveFeature {
private static final Function<BlockState, Boolean> REPLACE;
private static final OpenSimplexNoise BIOME_NOISE_X = new OpenSimplexNoise("biome_noise_x".hashCode());
private static final OpenSimplexNoise BIOME_NOISE_Z = new OpenSimplexNoise("biome_noise_z".hashCode());
@Override
protected Set<BlockPos> generate(WorldGenLevel world, BlockPos center, int radius, Random random) {
//OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
float rad = radius * 0.15F;
int min = Mth.ceil(rad) - 15;
int max = 31 - Mth.floor(rad);
List<Vector3f> spline = SplineHelper.makeSpline(0, 0, 0, 0, 0, 0, radius / 3);
spline = SplineHelper.smoothSpline(spline, 5);
SplineHelper.offsetParts(spline, random, 5, radius * 0.4F, 5);
for (Vector3f vec: spline) {
float x = Mth.clamp(vec.x(), min, max);
float y = Mth.clamp(vec.y(), -radius, radius);
float z = Mth.clamp(vec.z(), min, max);
vec.set(x, y, z);
}
SDF sdf = SplineHelper.buildSDF(spline, rad, rad, (vec) -> Blocks.AIR.defaultBlockState());
Set<BlockPos> positions = sdf.setReplaceFunction(REPLACE).getPositions(world, center);
for (BlockPos p: positions) {
BlocksHelper.setWithoutUpdate(world, p, CAVE_AIR);
private Set<BlockPos> generate(WorldGenLevel world, BlockPos center, Random random) {
int x1 = (center.getX() >> 4) << 4;
int z1 = (center.getZ() >> 4) << 4;
int x2 = x1 + 16;
int z2 = z1 + 16;
int y2 = world.getHeight();
Random rand = new Random(world.getSeed());
OpenSimplexNoise noiseH = new OpenSimplexNoise(rand.nextInt());
OpenSimplexNoise noiseV = new OpenSimplexNoise(rand.nextInt());
OpenSimplexNoise noiseD = new OpenSimplexNoise(rand.nextInt());
Set<BlockPos> positions = Sets.newHashSet();
MutableBlockPos pos = new MutableBlockPos();
for (int x = x1; x < x2; x++) {
pos.setX(x);
for (int z = z1; z < z2; z++) {
pos.setZ(z);
for (int y = 0; y < y2; y++) {
pos.setY(y);
float val = Mth.abs((float) noiseH.eval(x * 0.02, y * 0.01, z * 0.02));
float vert = Mth.sin((y + (float) noiseV.eval(x * 0.01, z * 0.01) * 20) * 0.1F) * 0.9F;//Mth.abs(y - 50 + (float) noiseV.eval(x * 0.01, z * 0.01) * 20) * 0.1F;
float dist = (float) noiseD.eval(x * 0.1, y * 0.1, z * 0.1) * 0.12F;
vert *= vert;
if (val + vert + dist < 0.15 && world.getBlockState(pos).is(EndTags.GEN_TERRAIN)) {
BlocksHelper.setWithoutUpdate(world, pos, AIR);
positions.add(pos.immutable());
}
}
}
}
return positions;
}
static {
REPLACE = (state) -> {
return state.is(EndTags.GEN_TERRAIN)
|| state.getMaterial().isReplaceable()
|| state.getMaterial().equals(Material.PLANT)
|| state.getMaterial().equals(Material.LEAVES);
};
@Override
public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) {
if (pos.getX() * pos.getX() + pos.getZ() * pos.getZ() <= 2500) {
return false;
}
if (biomeMissingCaves(world, pos)) {
return false;
}
EndCaveBiome biome = EndBiomes.getCaveBiome(random);
Set<BlockPos> preCaveBlocks = generate(world, pos, random);
Set<BlockPos> caveBlocks = mutateBlocks(preCaveBlocks);
if (!caveBlocks.isEmpty()) {
if (biome != null) {
setBiomes(world, biome, caveBlocks);
Set<BlockPos> floorPositions = Sets.newHashSet();
Set<BlockPos> ceilPositions = Sets.newHashSet();
MutableBlockPos mut = new MutableBlockPos();
caveBlocks.forEach((bpos) -> {
mut.set(bpos);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
mut.setY(bpos.getY() - 1);
if (world.getBlockState(mut).is(EndTags.GEN_TERRAIN)) {
floorPositions.add(mut.immutable());
}
mut.setY(bpos.getY() + 1);
if (world.getBlockState(mut).is(EndTags.GEN_TERRAIN)) {
ceilPositions.add(mut.immutable());
}
}
});
BlockState surfaceBlock = biome.getBiome().getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
placeFloor(world, biome, floorPositions, random, surfaceBlock);
placeCeil(world, biome, ceilPositions, random);
placeWalls(world, biome, caveBlocks, random);
}
fixBlocks(world, preCaveBlocks);
}
return true;
}
private Set<BlockPos> mutateBlocks(Set<BlockPos> caveBlocks) {
Set<BlockPos> result = Sets.newHashSet();
caveBlocks.forEach(pos -> {
int dx = pos.getX() + (int) (BIOME_NOISE_X.eval(pos.getX() * 0.2, pos.getZ() * 0.2) * 5);
int dz = pos.getZ() + (int) (BIOME_NOISE_Z.eval(pos.getX() * 0.2, pos.getZ() * 0.2) * 5);
if ((dx >> 4) == (pos.getX() >> 4) && (dz >> 4) == (pos.getZ() >> 4)) {
result.add(pos);
}
});
return result;
}
@Override
protected Set<BlockPos> generate(WorldGenLevel world, BlockPos center, int radius, Random random) {
return null;
}
@Override
protected void placeFloor(WorldGenLevel world, EndCaveBiome biome, Set<BlockPos> floorPositions, Random random, BlockState surfaceBlock) {
float density = biome.getFloorDensity() * 0.2F;
floorPositions.forEach((pos) -> {
BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock);
if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getFloorFeature(random);
if (feature != null) {
feature.place(world, null, random, pos.above(), null);
}
}
});
}
@Override
protected void placeCeil(WorldGenLevel world, EndCaveBiome biome, Set<BlockPos> ceilPositions, Random random) {
float density = biome.getCeilDensity() * 0.2F;
ceilPositions.forEach((pos) -> {
BlockState ceilBlock = biome.getCeil(pos);
if (ceilBlock != null) {
BlocksHelper.setWithoutUpdate(world, pos, ceilBlock);
}
if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getCeilFeature(random);
if (feature != null) {
feature.place(world, null, random, pos.below(), null);
}
}
});
}
}