mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Added lush caves to the cave world
This commit is contained in:
parent
3f0b9beb5c
commit
2ff5f2758e
4 changed files with 121 additions and 28 deletions
|
@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||||
import net.minecraft.entity.EnumCreatureType;
|
import net.minecraft.entity.EnumCreatureType;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.biome.Biome;
|
import net.minecraft.world.biome.Biome;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
@ -33,12 +34,14 @@ public class ChunkProviderCave implements IChunkGenerator{
|
||||||
private final Random rand;
|
private final Random rand;
|
||||||
|
|
||||||
private final WorldGenerator spawnGenerator;
|
private final WorldGenerator spawnGenerator;
|
||||||
|
private final WorldGenerator lushCaveGenerator;
|
||||||
|
|
||||||
private final MapGenBase caveGenerator = new MapGenCustomCaves();
|
private final MapGenBase caveGenerator = new MapGenCustomCaves();
|
||||||
|
|
||||||
public ChunkProviderCave(World world){
|
public ChunkProviderCave(World world){
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.rand = new Random(world.getSeed());
|
this.rand = new Random(world.getSeed());
|
||||||
|
this.lushCaveGenerator = new WorldGenLushCaves(this.rand);
|
||||||
this.spawnGenerator = new WorldGenCaveSpawn(this.rand);
|
this.spawnGenerator = new WorldGenCaveSpawn(this.rand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +88,12 @@ public class ChunkProviderCave implements IChunkGenerator{
|
||||||
this.spawnGenerator.generate(this.world, this.rand, spawn);
|
this.spawnGenerator.generate(this.world, this.rand, spawn);
|
||||||
ModUtil.LOGGER.info("Generating spawn cave...");
|
ModUtil.LOGGER.info("Generating spawn cave...");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
if(this.rand.nextInt(3) <= 0){
|
||||||
|
BlockPos pos = new BlockPos(x*16+this.rand.nextInt(16)+8, MathHelper.getRandomIntegerInRange(this.rand, 12, 244), z*16+this.rand.nextInt(16)+8);
|
||||||
|
this.lushCaveGenerator.generate(this.world, this.rand, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,22 +25,8 @@ import javax.annotation.Nonnull;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
//This is hideous. It's mostly copied from MapGenCaves and changed slightly.
|
//This is hideous. It's mostly copied from MapGenCaves and changed slightly.
|
||||||
//I also have no idea what I'm actually doing here as all of the variables have
|
|
||||||
//horrible names and I don't know what half of them do so I just try it out.
|
|
||||||
public class MapGenCustomCaves extends MapGenCaves{
|
public class MapGenCustomCaves extends MapGenCaves{
|
||||||
|
|
||||||
private static final Block[] NO_REPLACEY = new Block[]{
|
|
||||||
Blocks.BEDROCK,
|
|
||||||
Blocks.LOG,
|
|
||||||
Blocks.LOG2,
|
|
||||||
Blocks.LEAVES,
|
|
||||||
Blocks.DIRT,
|
|
||||||
Blocks.PLANKS,
|
|
||||||
Blocks.OAK_FENCE,
|
|
||||||
Blocks.CHEST,
|
|
||||||
Blocks.LADDER
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addRoom(long probablySeed, int chunkX, int chunkZ, @Nonnull ChunkPrimer primer, double x, double y, double z){
|
protected void addRoom(long probablySeed, int chunkX, int chunkZ, @Nonnull ChunkPrimer primer, double x, double y, double z){
|
||||||
this.addTunnel(probablySeed, chunkX, chunkZ, primer, x, y, z, 1.0F+this.rand.nextFloat()*15.0F, 0.0F, 0.0F, -1, -1, this.rand.nextDouble()*1.2F+0.25F);
|
this.addTunnel(probablySeed, chunkX, chunkZ, primer, x, y, z, 1.0F+this.rand.nextFloat()*15.0F, 0.0F, 0.0F, -1, -1, this.rand.nextDouble()*1.2F+0.25F);
|
||||||
|
@ -139,16 +125,10 @@ public class MapGenCustomCaves extends MapGenCaves{
|
||||||
i1 = 16;
|
i1 = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean flag3 = false;
|
for(int j1 = k2; j1 < k; ++j1){
|
||||||
|
for(int k1 = i3; k1 < i1; ++k1){
|
||||||
for(int j1 = k2; !flag3 && j1 < k; ++j1){
|
for(int l1 = l+1; l1 >= l2-1; --l1){
|
||||||
for(int k1 = i3; !flag3 && k1 < i1; ++k1){
|
|
||||||
for(int l1 = l+1; !flag3 && l1 >= l2-1; --l1){
|
|
||||||
if(l1 >= 0 && l1 < 256){
|
if(l1 >= 0 && l1 < 256){
|
||||||
if(this.isOceanBlock(primer, j1, l1, k1, chunkX, chunkZ)){
|
|
||||||
flag3 = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(l1 != l2-1 && j1 != k2 && j1 != k-1 && k1 != i3 && k1 != i1-1){
|
if(l1 != l2-1 && j1 != k2 && j1 != k-1 && k1 != i3 && k1 != i1-1){
|
||||||
l1 = l2;
|
l1 = l2;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +137,6 @@ public class MapGenCustomCaves extends MapGenCaves{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!flag3){
|
|
||||||
for(int j3 = k2; j3 < k; ++j3){
|
for(int j3 = k2; j3 < k; ++j3){
|
||||||
double d10 = ((double)(j3+chunkX*16)+0.5D-x)/d2;
|
double d10 = ((double)(j3+chunkX*16)+0.5D-x)/d2;
|
||||||
|
|
||||||
|
@ -187,11 +166,10 @@ public class MapGenCustomCaves extends MapGenCaves{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canReplaceBlock(IBlockState first, @Nonnull IBlockState second){
|
protected boolean canReplaceBlock(IBlockState first, @Nonnull IBlockState second){
|
||||||
return Util.arrayContains(NO_REPLACEY, first.getBlock()) < 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -215,7 +193,7 @@ public class MapGenCustomCaves extends MapGenCaves{
|
||||||
|
|
||||||
for(int j = 0; j < i; ++j){
|
for(int j = 0; j < i; ++j){
|
||||||
double d0 = (double)(chunkX*16+this.rand.nextInt(16));
|
double d0 = (double)(chunkX*16+this.rand.nextInt(16));
|
||||||
double d1 = (double)this.rand.nextInt(this.rand.nextInt(244)+8);
|
double d1 = (double)this.rand.nextInt(this.rand.nextInt(236)+16);
|
||||||
double d2 = (double)(chunkZ*16+this.rand.nextInt(16));
|
double d2 = (double)(chunkZ*16+this.rand.nextInt(16));
|
||||||
int k = 1;
|
int k = 1;
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class WorldGenCaveSpawn extends WorldGenerator{
|
||||||
this.makeSphere(world, center.add(-2, -1, 8), 3);
|
this.makeSphere(world, center.add(-2, -1, 8), 3);
|
||||||
|
|
||||||
world.setBlockState(center.add(-1, -5, -8), Blocks.DIRT.getStateFromMeta(1));
|
world.setBlockState(center.add(-1, -5, -8), Blocks.DIRT.getStateFromMeta(1));
|
||||||
WorldGenTrees trees = new WorldGenTrees(true);
|
WorldGenTrees trees = new WorldGenTrees(false);
|
||||||
trees.generate(world, this.rand, center.add(-1, -4, -8));
|
trees.generate(world, this.rand, center.add(-1, -4, -8));
|
||||||
|
|
||||||
int length = this.rand.nextInt(20)+20;
|
int length = this.rand.nextInt(20)+20;
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
* This file ("WorldGenLushCaves.java") is part of the Actually Additions mod for Minecraft.
|
||||||
|
* It is created and owned by Ellpeck and distributed
|
||||||
|
* under the Actually Additions License to be found at
|
||||||
|
* http://ellpeck.de/actaddlicense
|
||||||
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||||
|
*
|
||||||
|
* © 2015-2016 Ellpeck
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.ellpeck.actuallyadditions.mod.gen.cave;
|
||||||
|
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.item.EnumDyeColor;
|
||||||
|
import net.minecraft.item.ItemDye;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.gen.feature.*;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class WorldGenLushCaves extends WorldGenerator{
|
||||||
|
|
||||||
|
private final Random rand;
|
||||||
|
|
||||||
|
public WorldGenLushCaves(Random rand){
|
||||||
|
this.rand = rand;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generate(@Nonnull World world, @Nonnull Random rand, @Nonnull BlockPos position){
|
||||||
|
this.generateCave(world, position);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateCave(World world, BlockPos center){
|
||||||
|
int spheres = this.rand.nextInt(5)+3;
|
||||||
|
for(int i = 0; i <= spheres; i++){
|
||||||
|
this.makeSphereWithGrassFloor(world, center.add(this.rand.nextInt(11)-5, this.rand.nextInt(7)-3, this.rand.nextInt(11)-5), this.rand.nextInt(3)+5);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.genTreesAndTallGrass(world, center, 10, spheres*3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void genTreesAndTallGrass(World world, BlockPos center, int radius, int amount){
|
||||||
|
List<BlockPos> possiblePoses = new ArrayList<BlockPos>();
|
||||||
|
for(double x = -radius; x < radius; x++){
|
||||||
|
for(double y = -radius; y < radius; y++){
|
||||||
|
for(double z = -radius; z < radius; z++){
|
||||||
|
if(this.rand.nextDouble() >= 0.5D){
|
||||||
|
BlockPos pos = center.add(x, y, z);
|
||||||
|
if(world.getBlockState(pos).getBlock() == Blocks.GRASS){
|
||||||
|
possiblePoses.add(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!possiblePoses.isEmpty()){
|
||||||
|
for(int i = 0; i <= amount; i++){
|
||||||
|
Collections.shuffle(possiblePoses);
|
||||||
|
if(this.rand.nextBoolean()){
|
||||||
|
WorldGenAbstractTree trees = this.rand.nextBoolean() ? (this.rand.nextBoolean() ? new WorldGenBigTree(false) : new WorldGenShrub(Blocks.LOG.getDefaultState(), Blocks.LEAVES.getDefaultState())) : new WorldGenTrees(false);
|
||||||
|
trees.generate(world, this.rand, possiblePoses.get(0).up());
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
ItemDye.applyBonemeal(new ItemStack(Items.DYE, 1, EnumDyeColor.WHITE.getDyeDamage()), world, possiblePoses.get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeSphereWithGrassFloor(World world, BlockPos center, int radius){
|
||||||
|
for(double x = -radius; x < radius; x++){
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(double x = -radius; x < radius; x++){
|
||||||
|
for(double z = -radius; z < radius; z++){
|
||||||
|
for(double y = -radius; y <= -3; y++){
|
||||||
|
BlockPos pos = center.add(x, y, z);
|
||||||
|
IBlockState state = world.getBlockState(pos);
|
||||||
|
BlockPos posUp = pos.up();
|
||||||
|
IBlockState stateUp = world.getBlockState(posUp);
|
||||||
|
if(!state.getBlock().isAir(state, world, pos) && stateUp.getBlock().isAir(stateUp, world, posUp)){
|
||||||
|
world.setBlockState(pos, Blocks.GRASS.getDefaultState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue