From d5a93cb730fdef1a62f01a90de4a75a13208d164 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 29 Apr 2021 12:39:15 +0300 Subject: [PATCH] Jade caves (WIP) --- .../java/ru/betterend/registry/EndBiomes.java | 2 + .../java/ru/betterend/registry/EndBlocks.java | 6 +- .../world/biome/cave/EndCaveBiome.java | 4 ++ .../world/biome/cave/JadeCaveBiome.java | 35 ++++++++++++ .../terrain/caves/EndCaveFeature.java | 55 ++++++++++++++++++- 5 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 src/main/java/ru/betterend/world/biome/cave/JadeCaveBiome.java diff --git a/src/main/java/ru/betterend/registry/EndBiomes.java b/src/main/java/ru/betterend/registry/EndBiomes.java index 5b7ef6b6..cf48844a 100644 --- a/src/main/java/ru/betterend/registry/EndBiomes.java +++ b/src/main/java/ru/betterend/registry/EndBiomes.java @@ -38,6 +38,7 @@ import ru.betterend.world.biome.cave.EmptyAuroraCaveBiome; import ru.betterend.world.biome.cave.EmptyEndCaveBiome; import ru.betterend.world.biome.cave.EmptySmaragdantCaveBiome; import ru.betterend.world.biome.cave.EndCaveBiome; +import ru.betterend.world.biome.cave.JadeCaveBiome; import ru.betterend.world.biome.cave.LushAuroraCaveBiome; import ru.betterend.world.biome.cave.LushSmaragdantCaveBiome; import ru.betterend.world.biome.land.AmberLandBiome; @@ -111,6 +112,7 @@ public class EndBiomes { public static final EndCaveBiome LUSH_SMARAGDANT_CAVE = registerCaveBiome(new LushSmaragdantCaveBiome()); public static final EndCaveBiome EMPTY_AURORA_CAVE = registerCaveBiome(new EmptyAuroraCaveBiome()); public static final EndCaveBiome LUSH_AURORA_CAVE = registerCaveBiome(new LushAuroraCaveBiome()); + public static final EndCaveBiome JADE_CAVE = registerCaveBiome(new JadeCaveBiome()); public static void register() { CAVE_BIOMES.rebuild(); diff --git a/src/main/java/ru/betterend/registry/EndBlocks.java b/src/main/java/ru/betterend/registry/EndBlocks.java index 16d13464..aa3ee5d0 100644 --- a/src/main/java/ru/betterend/registry/EndBlocks.java +++ b/src/main/java/ru/betterend/registry/EndBlocks.java @@ -77,9 +77,9 @@ public class EndBlocks { public static final StoneMaterial FLAVOLITE = new StoneMaterial("flavolite", MaterialColor.SAND); public static final StoneMaterial VIOLECITE = new StoneMaterial("violecite", MaterialColor.COLOR_PURPLE); public static final StoneMaterial SULPHURIC_ROCK = new StoneMaterial("sulphuric_rock", MaterialColor.COLOR_BROWN); - public static final StoneMaterial VIRID_jADESTONE = new StoneMaterial("virid_jadestone", MaterialColor.COLOR_GREEN); - public static final StoneMaterial AZURE_jADESTONE = new StoneMaterial("azure_jadestone", MaterialColor.COLOR_LIGHT_BLUE); - public static final StoneMaterial SANDY_jADESTONE = new StoneMaterial("sandy_jadestone", MaterialColor.COLOR_YELLOW); + public static final StoneMaterial VIRID_JADESTONE = new StoneMaterial("virid_jadestone", MaterialColor.COLOR_GREEN); + public static final StoneMaterial AZURE_JADESTONE = new StoneMaterial("azure_jadestone", MaterialColor.COLOR_LIGHT_BLUE); + public static final StoneMaterial SANDY_JADESTONE = new StoneMaterial("sandy_jadestone", MaterialColor.COLOR_YELLOW); public static final Block BRIMSTONE = registerBlock("brimstone", new BrimstoneBlock()); public static final Block SULPHUR_CRYSTAL = registerBlock("sulphur_crystal", new SulphurCrystalBlock()); public static final Block MISSING_TILE = registerBlock("missing_tile", new MissingTileBlock()); diff --git a/src/main/java/ru/betterend/world/biome/cave/EndCaveBiome.java b/src/main/java/ru/betterend/world/biome/cave/EndCaveBiome.java index 26c07fbf..3f25a5bb 100644 --- a/src/main/java/ru/betterend/world/biome/cave/EndCaveBiome.java +++ b/src/main/java/ru/betterend/world/biome/cave/EndCaveBiome.java @@ -56,4 +56,8 @@ public class EndCaveBiome extends EndBiome { public BlockState getCeil(BlockPos pos) { return null; } + + public BlockState getWall(BlockPos pos) { + return null; + } } diff --git a/src/main/java/ru/betterend/world/biome/cave/JadeCaveBiome.java b/src/main/java/ru/betterend/world/biome/cave/JadeCaveBiome.java new file mode 100644 index 00000000..d399695d --- /dev/null +++ b/src/main/java/ru/betterend/world/biome/cave/JadeCaveBiome.java @@ -0,0 +1,35 @@ +package ru.betterend.world.biome.cave; + +import net.minecraft.core.BlockPos; +import net.minecraft.util.Mth; +import net.minecraft.world.level.block.state.BlockState; +import ru.betterend.noise.OpenSimplexNoise; +import ru.betterend.registry.EndBlocks; +import ru.betterend.registry.EndSounds; +import ru.betterend.world.biome.BiomeDefinition; + +public class JadeCaveBiome extends EndCaveBiome { + private static final OpenSimplexNoise WALL_NOISE = new OpenSimplexNoise("jade_cave".hashCode()); + private static final OpenSimplexNoise DEPTH_NOISE = new OpenSimplexNoise("depth_noise".hashCode()); + private static final BlockState[] JADE = new BlockState[3]; + + public JadeCaveBiome() { + super(new BiomeDefinition("jade_cave") + .setFogColor(118, 150, 112) + .setFogDensity(2.0F) + .setWaterAndFogColor(95, 223, 255) + .setMusic(EndSounds.MUSIC_FOREST) + ); + JADE[0] = EndBlocks.VIRID_JADESTONE.stone.defaultBlockState(); + JADE[1] = EndBlocks.AZURE_JADESTONE.stone.defaultBlockState(); + JADE[2] = EndBlocks.SANDY_JADESTONE.stone.defaultBlockState(); + } + + @Override + public BlockState getWall(BlockPos pos) { + double depth = DEPTH_NOISE.eval(pos.getX() * 0.02, pos.getZ() * 0.02) * 0.2 + 0.5; + int index = Mth.floor((pos.getY() + WALL_NOISE.eval(pos.getX() * 0.2, pos.getZ() * 0.2) * 1.5) * depth + 0.5); + index = Mth.abs(index) % 3; + return JADE[index]; + } +} diff --git a/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java b/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java index 90744cb0..c303d01b 100644 --- a/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java @@ -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 positions, Random random) { + Set 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 positions) { + for (Direction dir: BlocksHelper.DIRECTIONS) { + if (!positions.contains(pos.relative(dir))) { + return true; + } + } + return false; + } protected void setBiomes(WorldGenLevel world, EndCaveBiome biome, Set blocks) { blocks.forEach((pos) -> setBiome(world, pos, biome)); @@ -202,4 +234,23 @@ public abstract class EndCaveFeature extends DefaultFeature { } return false; } + + static { + List 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[] {}); + } }