Jade caves (WIP)

This commit is contained in:
paulevsGitch 2021-04-29 12:39:15 +03:00
parent c91478ee99
commit d5a93cb730
5 changed files with 97 additions and 5 deletions

View file

@ -1,13 +1,16 @@
package ru.betterend.world.features.terrain.caves;
import java.util.List;
import java.util.Random;
import java.util.Set;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks;
@ -29,6 +32,7 @@ public abstract class EndCaveFeature extends DefaultFeature {
protected static final BlockState CAVE_AIR = Blocks.CAVE_AIR.defaultBlockState();
protected static final BlockState END_STONE = Blocks.END_STONE.defaultBlockState();
protected static final BlockState WATER = Blocks.WATER.defaultBlockState();
private static final Vec3i[] SPHERE;
@Override
public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) {
@ -68,10 +72,10 @@ public abstract class EndCaveFeature extends DefaultFeature {
}
}
});
BlockState surfaceBlock = biome.getBiome().getGenerationSettings().getSurfaceBuilderConfig()
.getTopMaterial();
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, caveBlocks);
}
@ -109,6 +113,34 @@ public abstract class EndCaveFeature extends DefaultFeature {
}
});
}
protected void placeWalls(WorldGenLevel world, EndCaveBiome biome, Set<BlockPos> positions, Random random) {
Set<BlockPos> placed = Sets.newHashSet();
positions.forEach(pos -> {
if (random.nextInt(4) == 0 && hasOpenSide(pos, positions)) {
BlockState wallBlock = biome.getWall(pos);
if (wallBlock != null) {
for (Vec3i offset: SPHERE) {
BlockPos wallPos = pos.offset(offset);
if (!positions.contains(wallPos) && !placed.contains(wallPos) && world.getBlockState(wallPos).is(EndTags.GEN_TERRAIN)) {
wallBlock = biome.getWall(wallPos);
BlocksHelper.setWithoutUpdate(world, wallPos, wallBlock);
placed.add(wallPos);
}
}
}
}
});
}
private boolean hasOpenSide(BlockPos pos, Set<BlockPos> positions) {
for (Direction dir: BlocksHelper.DIRECTIONS) {
if (!positions.contains(pos.relative(dir))) {
return true;
}
}
return false;
}
protected void setBiomes(WorldGenLevel world, EndCaveBiome biome, Set<BlockPos> blocks) {
blocks.forEach((pos) -> setBiome(world, pos, biome));
@ -202,4 +234,23 @@ public abstract class EndCaveFeature extends DefaultFeature {
}
return false;
}
static {
List<Vec3i> prePos = Lists.newArrayList();
int radius = 5;
int r2 = radius * radius;
for (int x = -radius; x <= radius; x++) {
int x2 = x * x;
for (int y = -radius; y <= radius; y++) {
int y2 = y * y;
for (int z = -radius; z <= radius; z++) {
int z2 = z * z;
if (x2 + y2 + z2 < r2) {
prePos.add(new Vec3i(x, y, z));
}
}
}
}
SPHERE = prePos.toArray(new Vec3i[] {});
}
}