Stalactites
This commit is contained in:
parent
2ac1ec8f5a
commit
7e73d9a31c
39 changed files with 657 additions and 31 deletions
|
@ -2,27 +2,36 @@ package ru.betterend.world.features.terrain;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class SmaragdantCrystalShardFeature extends DefaultFeature {
|
||||
public class SingleBlockFeature extends DefaultFeature {
|
||||
private final Block block;
|
||||
|
||||
public SingleBlockFeature(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
|
||||
if (!world.getBlockState(pos.down()).isIn(EndTags.GEN_TERRAIN)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockState shard = EndBlocks.SMARAGDANT_CRYSTAL_SHARD.getDefaultState();
|
||||
boolean waterlogged = !world.getFluidState(pos).isEmpty();
|
||||
BlocksHelper.setWithoutUpdate(world, pos, shard.with(Properties.WATERLOGGED, waterlogged));
|
||||
BlockState state = block.getDefaultState();
|
||||
if (block.getStateManager().getProperty("waterlogged") != null) {
|
||||
boolean waterlogged = !world.getFluidState(pos).isEmpty();
|
||||
state = state.with(Properties.WATERLOGGED, waterlogged);
|
||||
}
|
||||
BlocksHelper.setWithoutUpdate(world, pos, state);
|
||||
|
||||
return true;
|
||||
}
|
|
@ -40,13 +40,8 @@ public class SmaragdantCrystalFeature extends DefaultFeature {
|
|||
BlocksHelper.setWithoutUpdate(world, mut, crystal);
|
||||
mut.setY(mut.getY() + 1);
|
||||
}
|
||||
if (random.nextBoolean()) {
|
||||
boolean waterlogged = !world.getFluidState(mut).isEmpty();
|
||||
BlocksHelper.setWithoutUpdate(world, mut, shard.with(Properties.WATERLOGGED, waterlogged));
|
||||
}
|
||||
else {
|
||||
BlocksHelper.setWithoutUpdate(world, mut, crystal);
|
||||
}
|
||||
boolean waterlogged = !world.getFluidState(mut).isEmpty();
|
||||
BlocksHelper.setWithoutUpdate(world, mut, shard.with(Properties.WATERLOGGED, waterlogged));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package ru.betterend.world.features.terrain;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
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;
|
||||
import ru.betterend.blocks.basis.StalactiteBlock;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class StalactiteFeature extends DefaultFeature {
|
||||
private final boolean ceiling;
|
||||
private final Block[] ground;
|
||||
private final Block block;
|
||||
|
||||
public StalactiteFeature(boolean ceiling, Block block, Block... ground) {
|
||||
this.ceiling = ceiling;
|
||||
this.ground = ground;
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
|
||||
if (!isGround(world.getBlockState(ceiling ? pos.up() : pos.down()).getBlock())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Mutable mut = new Mutable().set(pos);
|
||||
int height = random.nextInt(8);
|
||||
int dir = ceiling ? -1 : 1;
|
||||
boolean stalagnate = false;
|
||||
|
||||
for (int i = 1; i <= height; i++) {
|
||||
mut.setY(pos.getY() + i * dir);
|
||||
BlockState state = world.getBlockState(mut);
|
||||
if (!state.isAir()) {
|
||||
stalagnate = state.isIn(EndTags.GEN_TERRAIN);
|
||||
height = i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int center = stalagnate ? height >> 1 : 0;
|
||||
for (int i = 0; i < height; i++) {
|
||||
mut.setY(pos.getY() + i * dir);
|
||||
int size = stalagnate ? MathHelper.abs(i - center) + 1 : height - i - 1;
|
||||
BlocksHelper.setWithoutUpdate(world, mut, block.getDefaultState().with(StalactiteBlock.SIZE, size));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isGround(Block block) {
|
||||
for (Block b : ground) {
|
||||
if (b == block) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -52,23 +52,31 @@ public abstract class EndCaveFeature extends DefaultFeature {
|
|||
Set<BlockPos> caveBlocks = generate(world, center, radius, random);
|
||||
if (!caveBlocks.isEmpty()) {
|
||||
if (biome != null) {
|
||||
boolean fillFloor = biome.getFloorDensity() > 0;
|
||||
boolean fillCeil = biome.getCeilDensity() > 0;
|
||||
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());
|
||||
if (fillFloor || fillCeil) {
|
||||
caveBlocks.forEach((bpos) -> {
|
||||
mut.set(bpos);
|
||||
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
|
||||
if (fillFloor) {
|
||||
mut.setY(bpos.getY() - 1);
|
||||
if (world.getBlockState(mut).isIn(EndTags.GEN_TERRAIN)) {
|
||||
floorPositions.add(mut.toImmutable());
|
||||
}
|
||||
}
|
||||
if (fillCeil) {
|
||||
mut.setY(bpos.getY() + 1);
|
||||
if (world.getBlockState(mut).isIn(EndTags.GEN_TERRAIN)) {
|
||||
ceilPositions.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);
|
||||
|
@ -100,7 +108,17 @@ public abstract class EndCaveFeature extends DefaultFeature {
|
|||
}
|
||||
|
||||
protected void placeCeil(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> ceilPositions, Random random) {
|
||||
|
||||
float density = biome.getCeilDensity();
|
||||
if (density > 0) {
|
||||
ceilPositions.forEach((pos) -> {
|
||||
if (random.nextFloat() <= density) {
|
||||
Feature<?> feature = biome.getCeilFeature(random);
|
||||
if (feature != null) {
|
||||
feature.generate(world, null, random, pos.down(), null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected void setBiomes(StructureWorldAccess world, EndCaveBiome biome, Set<BlockPos> blocks) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue