Use multiple generation attempts in GeneratorColumns

This commit is contained in:
Cheeserolls 2015-06-01 19:18:55 +01:00
parent 1c67753174
commit f8db6d03c1

View file

@ -37,6 +37,7 @@ public class GeneratorColumns extends BOPGeneratorBase
protected IBlockState to = Blocks.cobblestone.getDefaultState(); protected IBlockState to = Blocks.cobblestone.getDefaultState();
protected int minHeight = 2; protected int minHeight = 2;
protected int maxHeight = 4; protected int maxHeight = 4;
protected int generationAttempts = 12;
public Builder amountPerChunk(float a) {this.amountPerChunk = a; return this;} public Builder amountPerChunk(float a) {this.amountPerChunk = a; return this;}
public Builder placeOn(IBlockPosQuery a) {this.placeOn = a; return this;} public Builder placeOn(IBlockPosQuery a) {this.placeOn = a; return this;}
@ -46,11 +47,13 @@ public class GeneratorColumns extends BOPGeneratorBase
public Builder to(IBlockState a) {this.to = a; return this;} public Builder to(IBlockState a) {this.to = a; return this;}
public Builder minHeight(int a) {this.minHeight = a; return this;} public Builder minHeight(int a) {this.minHeight = a; return this;}
public Builder maxHeight(int a) {this.maxHeight = a; return this;} public Builder maxHeight(int a) {this.maxHeight = a; return this;}
public Builder generationAttempts(int a) {this.generationAttempts = a; return this;}
@Override @Override
public GeneratorColumns create() public GeneratorColumns create()
{ {
return new GeneratorColumns(this.amountPerChunk, this.to, this.minHeight, this.maxHeight, this.placeOn); return new GeneratorColumns(this.amountPerChunk, this.to, this.minHeight, this.maxHeight, this.placeOn, this.generationAttempts);
} }
} }
@ -59,14 +62,16 @@ public class GeneratorColumns extends BOPGeneratorBase
protected IBlockState to; protected IBlockState to;
protected int minHeight; protected int minHeight;
protected int maxHeight; protected int maxHeight;
protected int generationAttempts;
public GeneratorColumns(float amountPerChunk, IBlockState to, int minHeight, int maxHeight, IBlockPosQuery placeOn) public GeneratorColumns(float amountPerChunk, IBlockState to, int minHeight, int maxHeight, IBlockPosQuery placeOn, int generationAttempts)
{ {
super(amountPerChunk); super(amountPerChunk);
this.to = to; this.to = to;
this.minHeight = minHeight; this.minHeight = minHeight;
this.maxHeight = maxHeight; this.maxHeight = maxHeight;
this.placeOn = placeOn; this.placeOn = placeOn;
this.generationAttempts = generationAttempts;
} }
@Override @Override
@ -79,23 +84,25 @@ public class GeneratorColumns extends BOPGeneratorBase
@Override @Override
public boolean generate(World world, Random rand, BlockPos pos) public boolean generate(World world, Random rand, BlockPos pos)
{ {
for (int i = 0; i < this.generationAttempts; ++i)
{
BlockPos genPos = pos.add(rand.nextInt(4) - rand.nextInt(4), rand.nextInt(3) - rand.nextInt(3), rand.nextInt(4) - rand.nextInt(4));
// move upwards until we find an air block // see if we can place the column
while (!world.isAirBlock(pos)) {pos = pos.up();} if (this.placeOn.matches(world, genPos.down()))
{
// if we can't place the column, abandon now
if (!this.placeOn.matches(world, pos.down())) {return false;}
// choose random target height // choose random target height
int height = GeneratorUtils.nextIntBetween(rand, this.minHeight, this.maxHeight); int height = GeneratorUtils.nextIntBetween(rand, this.minHeight, this.maxHeight);
// keep placing blocks upwards (if there's room) // keep placing blocks upwards (if there's room)
while(height > 0 && world.isAirBlock(pos)) while(height > 0 && world.isAirBlock(genPos))
{ {
world.setBlockState(pos, this.to); world.setBlockState(genPos, this.to);
pos = pos.up(); genPos = genPos.up();
height--; height--;
} }
}
}
return true; return true;
} }
@ -106,6 +113,7 @@ public class GeneratorColumns extends BOPGeneratorBase
this.to = conf.getBlockState("to", this.to); this.to = conf.getBlockState("to", this.to);
this.minHeight = conf.getInt("minHeight", this.minHeight); this.minHeight = conf.getInt("minHeight", this.minHeight);
this.maxHeight = conf.getInt("maxHeight", this.maxHeight); this.maxHeight = conf.getInt("maxHeight", this.maxHeight);
this.generationAttempts = conf.getInt("generationAttempts", this.generationAttempts);
String placeOnString = conf.getString("placeOn", null); String placeOnString = conf.getString("placeOn", null);
if (placeOnString != null) if (placeOnString != null)
{ {