Make sure caves don't go through bedrock

Closes #248
This commit is contained in:
Ellpeck 2016-09-25 21:10:37 +02:00
parent 1d77f1e168
commit fe974365b1
2 changed files with 21 additions and 4 deletions

View file

@ -71,7 +71,7 @@ public class OreGen implements IWorldGenerator{
if(ConfigBoolValues.GEN_LUSH_CAVES.isEnabled() && random.nextInt(ConfigIntValues.LUSH_CAVE_CHANCE.getValue()) <= 0){
BlockPos posAtHeight = world.getTopSolidOrLiquidBlock(new BlockPos(x+random.nextInt(16)+8, 0, z+random.nextInt(16)+8));
this.caveGen.generate(world, random, posAtHeight.down(MathHelper.getRandomIntegerInRange(random, 10, posAtHeight.getY()-10)));
this.caveGen.generate(world, random, posAtHeight.down(MathHelper.getRandomIntegerInRange(random, 15, posAtHeight.getY()-15)));
}
}

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.gen;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
@ -73,7 +74,10 @@ public class WorldGenLushCaves extends WorldGenerator{
for(double y = -radius; y < radius; y++){
for(double z = -radius; z < radius; z++){
if(Math.sqrt((x*x)+(y*y)+(z*z)) < radius){
world.setBlockToAir(center.add(x, y, z));
BlockPos pos = center.add(x, y, z);
if(!this.checkBedrock(world, pos)){
world.setBlockToAir(pos);
}
}
}
}
@ -86,6 +90,7 @@ public class WorldGenLushCaves extends WorldGenerator{
IBlockState state = world.getBlockState(pos);
BlockPos posUp = pos.up();
IBlockState stateUp = world.getBlockState(posUp);
if(!this.checkBedrock(world, pos) && !this.checkBedrock(world, posUp)){
if(!state.getBlock().isAir(state, world, pos) && stateUp.getBlock().isAir(stateUp, world, posUp)){
world.setBlockState(pos, Blocks.GRASS.getDefaultState());
}
@ -94,3 +99,15 @@ public class WorldGenLushCaves extends WorldGenerator{
}
}
}
private boolean checkBedrock(World world, BlockPos pos){
IBlockState state = world.getBlockState(pos);
if(state != null){
Block block = state.getBlock();
if(block != null && (block.isAir(state, world, pos) || block.getHarvestLevel(state) >= 0F)){
return false;
}
}
return true;
}
}