Cleaned up Space generator to fit with WDConf

This commit is contained in:
Francesco Macagno 2015-08-20 22:41:10 -07:00
parent 5635441fc7
commit 3e8d774941

View file

@ -112,25 +112,8 @@ public class SpaceWorldGenerator implements IWorldGenerator {
}
public static void generateRandomAsteroid(World world, int x, int y, int z, int asteroidSizeMax, int centerRadiusMax) {
if (world.rand.nextInt(30) == 1) {
Block t = Blocks.air;
if (world.rand.nextInt(25) == 1) {
while (t.isAssociatedBlock(Blocks.air)) {
t = WarpDriveConfig.getRandomNetherBlock(world.rand, Blocks.air);
}
} else if (world.rand.nextInt(35) == 1) {
while (t.isAssociatedBlock(Blocks.air)) {
t = WarpDriveConfig.getRandomEndBlock(world.rand, Blocks.air);
}
} else {
while (t.isAssociatedBlock(Blocks.air)) {
t = WarpDriveConfig.getRandomOverworldBlock(world.rand, Blocks.air);
}
}
generateAsteroidOfBlock(world, x, y, z, Math.min(3, asteroidSizeMax), Math.min(2, centerRadiusMax), t, 0);
} else {
generateAsteroidOfBlock(world, x, y, z, asteroidSizeMax, centerRadiusMax, null, 0);
}
generateAsteroidOfBlock(world, x, y, z, asteroidSizeMax, centerRadiusMax, null, 0);
}
private static float binomialRandom(World world) {
@ -309,6 +292,7 @@ public class SpaceWorldGenerator implements IWorldGenerator {
* maximum radius of central ball
*/
private static void generateAsteroidOfBlock(World world, int x, int y, int z, int asteroidSizeMax, int centerRadiusMax, Block ice, int meta) {
/*
// FIXME: get a proper range of random instead of capping it
int asteroidSize = 1 + world.rand.nextInt(6);
if (asteroidSizeMax != 0) {
@ -330,48 +314,16 @@ public class SpaceWorldGenerator implements IWorldGenerator {
int newZ = z + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
generateSphereDirect(world, newX, newY, newZ, radius, true, ice, meta, false, t, 0);
}
}
/**
* Sphere generator
*
* @param world
* target world
* @param xCoord
* center
* @param yCoord
* center
* @param zCoord
* center
* @param radius
* sphere radius
* @param corrupted
* skip random blocks when generating (corrupted effect)
* @param block
* sphere of specified blocks or random blocks if not specified
* @return
*/
public static void generateSphereDirect(World world, int xCoord, int yCoord, int zCoord, double radius, boolean corrupted, Block block, int meta,
boolean hollow) {
if (block == null) {
generateSphereDirect(world, xCoord, yCoord, zCoord, radius, corrupted, block, meta, hollow,
WarpDriveConfig.getDefaultSurfaceBlock(world.rand, corrupted, false), 0);
} else {
generateSphereDirect(world, xCoord, yCoord, zCoord, radius, corrupted, block, meta, hollow, block, meta);
}
*/
}
public static void generateSphereDirect(
World world, int xCoord, int yCoord, int zCoord, double radius, boolean corrupted,
Block ice, int meta, boolean hollow, Block t, int meta2) {
double radiusC = radius + 0.5D; // Radius from center of block
World world, int xCoord, int yCoord, int zCoord, Orb orb, Random rand) {
double radiusC = orb.getHeight() / 2 + 0.5D; // Radius from center of block
double radiusSq = radiusC * radiusC; // Optimization to avoid sqrts...
double radius1Sq = (radiusC - 1.0D) * (radiusC - 1.0D); // for hollow
// sphere
int ceilRadius = (int) Math.ceil(radiusC);
Block block = ice;
// Pass the cube and check points for sphere equation x^2 + y^2 + z^2 = r^2
for (int x = 0; x <= ceilRadius; x++) {
double x2 = (x + 0.5D) * (x + 0.5D);
@ -379,48 +331,26 @@ public class SpaceWorldGenerator implements IWorldGenerator {
double y2 = (y + 0.5D) * (y + 0.5D);
for (int z = 0; z <= ceilRadius; z++) {
double z2 = (z + 0.5D) * (z + 0.5D);
double dSq = x2 + y2 + z2; // Distance from current position
// to center
int dSq = (int) Math.sqrt(x2 + y2 + z2); // Distance from current position
//TODO: Find quicker form of sqrt
// Skip too far blocks
if (dSq > radiusSq) {
continue;
}
// Hollow sphere condition
// only generate at the outer limit with 1 block tolerance along each axis
// (the 1 block tolerance is done to avoid holes in the shape)
if ( hollow
&& ( (dSq < radius1Sq)
|| ( (lengthSq(x + 1.5D, y + 0.5D, z + 0.5D) <= radiusSq)
&& (lengthSq(x + 0.5D, y + 1.5D, z + 0.5D) <= radiusSq)
&& (lengthSq(x + 0.5D, y + 0.5D, z + 1.5D) <= radiusSq) ) ) ) {
continue;
}
// Place blocks
// create holes in corrupted sphere (20% per block)
// cheat by using axial symmetry so we don't create random numbers too frequently
if (!corrupted || world.rand.nextInt(5) != 1) {
if (ice == null) block = WarpDriveConfig.getRandomSurfaceBlock(world.rand, t, false);
world.setBlock(xCoord + x, yCoord + y, zCoord + z, block, 0, 2);
world.setBlock(xCoord - x, yCoord + y, zCoord + z, block, 0, 2);
}
if (!corrupted || world.rand.nextInt(5) != 1) {
if (ice == null) block = WarpDriveConfig.getRandomSurfaceBlock(world.rand, t, false);
world.setBlock(xCoord + x, yCoord - y, zCoord + z, block, 0, 2);
world.setBlock(xCoord + x, yCoord + y, zCoord - z, block, 0, 2);
}
if (!corrupted || world.rand.nextInt(5) != 1) {
if (ice == null) block = WarpDriveConfig.getRandomSurfaceBlock(world.rand, t, false);
world.setBlock(xCoord - x, yCoord - y, zCoord + z, block, 0, 2);
world.setBlock(xCoord + x, yCoord - y, zCoord - z, block, 0, 2);
}
if (!corrupted || world.rand.nextInt(5) != 1) {
if (ice == null) block = WarpDriveConfig.getRandomSurfaceBlock(world.rand, t, false);
world.setBlock(xCoord - x, yCoord + y, zCoord - z, block, 0, 2);
world.setBlock(xCoord - x, yCoord - y, zCoord - z, block, 0, 2);
}
world.setBlock(xCoord + x, yCoord + y, zCoord + z, orb.getBlockForRadius(rand, dSq), 0, 2);
world.setBlock(xCoord - x, yCoord + y, zCoord + z, orb.getBlockForRadius(rand, dSq), 0, 2);
world.setBlock(xCoord + x, yCoord - y, zCoord + z, orb.getBlockForRadius(rand, dSq), 0, 2);
world.setBlock(xCoord + x, yCoord + y, zCoord - z, orb.getBlockForRadius(rand, dSq), 0, 2);
world.setBlock(xCoord - x, yCoord - y, zCoord + z, orb.getBlockForRadius(rand, dSq), 0, 2);
world.setBlock(xCoord + x, yCoord - y, zCoord - z, orb.getBlockForRadius(rand, dSq), 0, 2);
world.setBlock(xCoord - x, yCoord + y, zCoord - z, orb.getBlockForRadius(rand, dSq), 0, 2);
world.setBlock(xCoord - x, yCoord - y, zCoord - z, orb.getBlockForRadius(rand, dSq), 0, 2);
}
}
}