Removed old End Caves (temporary), added new Caves and Cave API (WIP)
This commit is contained in:
parent
2135fe50b5
commit
231794363b
14 changed files with 384 additions and 28 deletions
|
@ -32,6 +32,7 @@ import ru.betterend.util.sdf.primitive.SDFSphere;
|
|||
import ru.betterend.world.features.DefaultFeature;
|
||||
import ru.betterend.world.generator.GeneratorOptions;
|
||||
|
||||
@Deprecated
|
||||
public class RoundCaveFeature extends DefaultFeature {
|
||||
private static final BlockState CAVE_AIR = Blocks.CAVE_AIR.getDefaultState();
|
||||
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
package ru.betterend.world.features.terrain.caves;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
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;
|
||||
import ru.betterend.interfaces.IBiomeArray;
|
||||
import ru.betterend.registry.EndBiomes;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
import ru.betterend.world.biome.EndCaveBiome;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
import ru.betterend.world.generator.GeneratorOptions;
|
||||
|
||||
public abstract class EndCaveFeature extends DefaultFeature {
|
||||
protected static final BlockState CAVE_AIR = Blocks.CAVE_AIR.getDefaultState();
|
||||
protected static final BlockState END_STONE = Blocks.END_STONE.getDefaultState();
|
||||
protected static final BlockState WATER = Blocks.WATER.getDefaultState();
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
|
||||
if (!(GeneratorOptions.useNewGenerator() && GeneratorOptions.noRingVoid()) || pos.getX() * pos.getX() + pos.getZ() * pos.getZ() <= 22500) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int radius = MHelper.randRange(10, 30, random);
|
||||
BlockPos center = findPos(world, pos, radius, random);
|
||||
|
||||
if (center == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EndCaveBiome biome = EndBiomes.getCaveBiome(random);
|
||||
Set<BlockPos> caveBlocks = generate(world, center, radius, random);
|
||||
if (biome != null && !caveBlocks.isEmpty()) {
|
||||
setBiomes(world, biome, caveBlocks);
|
||||
Set<BlockPos> floorPositions = Sets.newHashSet();
|
||||
Set<BlockPos> ceilPositions = Sets.newHashSet();
|
||||
Mutable mut = new Mutable();
|
||||
caveBlocks.forEach((bpos) -> {
|
||||
mut.set(bpos);
|
||||
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
|
||||
mut.setY(bpos.getY() - 1);
|
||||
if (world.getBlockState(mut).isIn(EndTags.GEN_TERRAIN)) {
|
||||
floorPositions.add(mut.toImmutable());
|
||||
}
|
||||
mut.setY(bpos.getY() + 1);
|
||||
if (world.getBlockState(mut).isIn(EndTags.GEN_TERRAIN)) {
|
||||
ceilPositions.add(mut.toImmutable());
|
||||
}
|
||||
}
|
||||
});
|
||||
BlockState surfaceBlock = biome.getBiome().getGenerationSettings().getSurfaceConfig().getTopMaterial();
|
||||
placeFloor(world, biome, floorPositions, random, surfaceBlock);
|
||||
placeCeil(world, biome, ceilPositions, random);
|
||||
}
|
||||
fixBlocks(world, center, radius);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract Set<BlockPos> generate(StructureWorldAccess world, BlockPos center, int radius, Random random);
|
||||
|
||||
protected void placeFloor(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> floorPositions, Random random, BlockState surfaceBlock) {
|
||||
floorPositions.forEach((pos) -> {
|
||||
BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock);
|
||||
});
|
||||
}
|
||||
|
||||
protected void placeCeil(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> ceilPositions, Random random) {
|
||||
|
||||
}
|
||||
|
||||
protected void setBiomes(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> blocks) {
|
||||
blocks.forEach((pos) -> setBiome(world, pos, biome));
|
||||
}
|
||||
|
||||
private void setBiome(StructureWorldAccess world, BlockPos pos, EndCaveBiome biome) {
|
||||
IBiomeArray array = (IBiomeArray) world.getChunk(pos).getBiomeArray();
|
||||
if (array != null) {
|
||||
array.setBiome(biome.getActualBiome(), pos);
|
||||
}
|
||||
}
|
||||
|
||||
private BlockPos findPos(StructureWorldAccess world, BlockPos pos, int radius, Random random) {
|
||||
int top = world.getTopY(Heightmap.Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
|
||||
Mutable bpos = new Mutable();
|
||||
bpos.setX(pos.getX());
|
||||
bpos.setZ(pos.getZ());
|
||||
bpos.setY(top - 1);
|
||||
|
||||
BlockState state = world.getBlockState(bpos);
|
||||
while (!state.isIn(EndTags.GEN_TERRAIN) && bpos.getY() > 5) {
|
||||
bpos.setY(bpos.getY() - 1);
|
||||
state = world.getBlockState(bpos);
|
||||
}
|
||||
if (bpos.getY() < 10) {
|
||||
return null;
|
||||
}
|
||||
top = (int) (bpos.getY() - (radius * 1.3F + 5));
|
||||
|
||||
while (state.isIn(EndTags.GEN_TERRAIN) || !state.getFluidState().isEmpty() && bpos.getY() > 5) {
|
||||
bpos.setY(bpos.getY() - 1);
|
||||
state = world.getBlockState(bpos);
|
||||
}
|
||||
int bottom = (int) (bpos.getY() + radius * 1.3F + 5);
|
||||
|
||||
if (top <= bottom) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BlockPos(pos.getX(), MHelper.randRange(bottom, top, random), pos.getZ());
|
||||
}
|
||||
|
||||
private void fixBlocks(StructureWorldAccess world, BlockPos pos, int radius) {
|
||||
int x1 = pos.getX() - radius - 5;
|
||||
int y1 = pos.getY() - radius - 5;
|
||||
int z1 = pos.getZ() - radius - 5;
|
||||
int x2 = pos.getX() + radius + 5;
|
||||
int y2 = pos.getY() + radius + 5;
|
||||
int z2 = pos.getZ() + radius + 5;
|
||||
BlocksHelper.fixBlocks(world, new BlockPos(x1, y1, z1), new BlockPos(x2, y2, z2));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package ru.betterend.world.features.terrain.caves;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.noise.OpenSimplexNoise;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class RoundCaveFeature extends EndCaveFeature {
|
||||
@Override
|
||||
protected Set<BlockPos> generate(StructureWorldAccess world, BlockPos center, int radius, Random random) {
|
||||
OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
|
||||
|
||||
int x1 = center.getX() - radius - 5;
|
||||
int z1 = center.getZ() - radius - 5;
|
||||
int x2 = center.getX() + radius + 5;
|
||||
int z2 = center.getZ() + radius + 5;
|
||||
int y1 = MHelper.floor(center.getY() - (radius + 5) / 1.6);
|
||||
int y2 = MHelper.floor(center.getY() + (radius + 5) / 1.6);
|
||||
|
||||
double hr = radius * 0.75;
|
||||
double nr = radius * 0.25;
|
||||
|
||||
BlockState state;
|
||||
Mutable bpos = new Mutable();
|
||||
Set<BlockPos> blocks = Sets.newHashSet();
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
int xsq = x - center.getX();
|
||||
xsq *= xsq;
|
||||
bpos.setX(x);
|
||||
for (int z = z1; z <= z2; z++) {
|
||||
int zsq = z - center.getZ();
|
||||
zsq *= zsq;
|
||||
bpos.setZ(z);
|
||||
for (int y = y1; y <= y2; y++) {
|
||||
int ysq = y - center.getY();
|
||||
ysq *= 1.6;
|
||||
ysq *= ysq;
|
||||
bpos.setY(y);
|
||||
double r = noise.eval(x * 0.1, y * 0.1, z * 0.1) * nr + hr;
|
||||
//double r2 = r + 5;
|
||||
double dist = xsq + ysq + zsq;
|
||||
if (dist < r * r) {
|
||||
state = world.getBlockState(bpos);
|
||||
if (isReplaceable(state)) {
|
||||
BlocksHelper.setWithoutUpdate(world, bpos, CAVE_AIR);
|
||||
blocks.add(bpos.toImmutable());
|
||||
|
||||
while (state.getMaterial().equals(Material.LEAVES)) {
|
||||
BlocksHelper.setWithoutUpdate(world, bpos, CAVE_AIR);
|
||||
bpos.setY(bpos.getY() + 1);
|
||||
state = world.getBlockState(bpos);
|
||||
}
|
||||
|
||||
bpos.setY(y - 1);
|
||||
while (state.getMaterial().equals(Material.LEAVES)) {
|
||||
BlocksHelper.setWithoutUpdate(world, bpos, CAVE_AIR);
|
||||
bpos.setY(bpos.getY() - 1);
|
||||
state = world.getBlockState(bpos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private boolean isReplaceable(BlockState state) {
|
||||
return state.isIn(EndTags.GEN_TERRAIN)
|
||||
|| state.getMaterial().isReplaceable()
|
||||
|| state.getMaterial().equals(Material.PLANT)
|
||||
|| state.getMaterial().equals(Material.LEAVES);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue