Added try to prevent crashes during world generation

This commit is contained in:
Francesco Macagno 2015-08-20 22:41:37 -07:00
parent 3e8d774941
commit 19372a61a6

View file

@ -46,38 +46,42 @@ public class SpaceWorldGenerator implements IWorldGenerator {
*/
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
if (world.provider.dimensionId != WarpDriveConfig.G_SPACE_DIMENSION_ID) {
return;
}
int x = (chunkX * 16) + (5 - random.nextInt(10));
int z = (chunkZ * 16) + (5 - random.nextInt(10));
if (WarpDriveConfig.G_SPACE_WORLDBORDER_BLOCKS > 0 && (Math.abs(x) > WarpDriveConfig.G_SPACE_WORLDBORDER_BLOCKS || Math.abs(z) > WarpDriveConfig.G_SPACE_WORLDBORDER_BLOCKS)) {
return;
}
int y = Y_LIMIT_SOFT_MIN + random.nextInt(Y_LIMIT_SOFT_MAX - Y_LIMIT_SOFT_MIN);
// Moon setup
if (random.nextInt(700) == 1)
generateMoon(world, x, y, z, null);
// Simple asteroids
else if (random.nextInt(150) == 1) {
generateAsteroidOfBlock(world, x, y, z, 6, 11, null, 0);
// Random asteroid of block
} else if (random.nextInt(400) == 1) {
generateRandomAsteroid(world, x, y, z, 6, 11);
if (random.nextBoolean()) {
generateGasCloudOfColor(world, x, y, z, 6, 11, null);
try {
if (world.provider.dimensionId != WarpDriveConfig.G_SPACE_DIMENSION_ID) {
return;
}
} else if (random.nextInt(200) == 1) {// Ice asteroid
generateAsteroidOfBlock(world, x, y, z, 6, 11, Blocks.ice, 0);
} else if (random.nextInt(500) == 1) {// Asteroid field
generateAsteroidField(world, x, y, z);
} else if (random.nextInt(1400) == 1) {// Diamond asteroid
generateAsteroidOfBlock(world, x, y, z, 3, 2, Blocks.diamond_ore, 0);
// Diamond block core
world.setBlock(x, y, z, Blocks.diamond_block, 0, 2);
if (random.nextBoolean()) {
generateGasCloudOfColor(world, x, y, z, 6, 11, null);
int x = (chunkX * 16) + (5 - random.nextInt(10));
int z = (chunkZ * 16) + (5 - random.nextInt(10));
if (WarpDriveConfig.G_SPACE_WORLDBORDER_BLOCKS > 0 && (Math.abs(x) > WarpDriveConfig.G_SPACE_WORLDBORDER_BLOCKS || Math.abs(z) > WarpDriveConfig.G_SPACE_WORLDBORDER_BLOCKS)) {
return;
}
int y = Y_LIMIT_SOFT_MIN + random.nextInt(Y_LIMIT_SOFT_MAX - Y_LIMIT_SOFT_MIN);
// Moon setup
if (random.nextInt(700) == 1)
generateMoon(world, x, y, z, null);
// Simple asteroids
else if (random.nextInt(150) == 1) {
generateAsteroidOfBlock(world, x, y, z, 6, 11, null, 0);
// Random asteroid of block
} else if (random.nextInt(400) == 1) {
generateRandomAsteroid(world, x, y, z, 6, 11);
if (random.nextBoolean()) {
generateGasCloudOfColor(world, x, y, z, 6, 11, null);
}
} else if (random.nextInt(200) == 1) {// Ice asteroid
generateAsteroidOfBlock(world, x, y, z, 6, 11, Blocks.ice, 0);
} else if (random.nextInt(500) == 1) {// Asteroid field
generateAsteroidField(world, x, y, z);
} else if (random.nextInt(1400) == 1) {// Diamond asteroid
generateAsteroidOfBlock(world, x, y, z, 3, 2, Blocks.diamond_ore, 0);
// Diamond block core
world.setBlock(x, y, z, Blocks.diamond_block, 0, 2);
if (random.nextBoolean()) {
generateGasCloudOfColor(world, x, y, z, 6, 11, null);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@ -318,7 +322,7 @@ public class SpaceWorldGenerator implements IWorldGenerator {
}
public static void generateSphereDirect(
World world, int xCoord, int yCoord, int zCoord, Orb orb, Random rand) {
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...
// sphere