Added error handling to generate command (wip)

This commit is contained in:
LemADEC 2016-01-17 07:01:10 +01:00
parent b6477aec32
commit fa48d71699
2 changed files with 20 additions and 13 deletions

View file

@ -7,6 +7,8 @@ import net.minecraft.util.MathHelper;
import cpw.mods.fml.common.FMLCommonHandler;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.config.structures.DeployableStructure;
import cr0s.warpdrive.config.structures.StructureManager;
import cr0s.warpdrive.world.JumpgateGenerator;
import cr0s.warpdrive.world.WorldGenSmallShip;
import cr0s.warpdrive.world.WorldGenStation;
@ -53,30 +55,42 @@ public class CommandGenerate extends CommandBase {
if (struct.equals("moon")) {
WarpDrive.logger.info("/generate: generating moon at " + x + ", " + (y - 16) + ", " + z);
WarpDrive.instance.spaceWorldGenerator.generateMoon(player.worldObj, x, y - 16, z, null);
} else if (struct.equals("ship")) {
WarpDrive.logger.info("/generate: generating NPC ship at " + x + ", " + y + ", " + z);
new WorldGenSmallShip(false).generate(player.worldObj, player.worldObj.rand, x, y, z);
} else if (struct.equals("station")) {
WarpDrive.logger.info("/generate: generating station at " + x + ", " + y + ", " + z);
new WorldGenStation(false).generate(player.worldObj, player.worldObj.rand, x, y, z);
} else if (struct.equals("asteroid")) {
WarpDrive.logger.info("/generate: generating asteroid at " + x + ", " + (y - 10) + ", " + z);
WarpDrive.instance.spaceWorldGenerator.generateRandomAsteroid(player.worldObj, x, y - 10, z);
} else if (struct.equals("astfield")) {
WarpDrive.logger.info("/generate: generating asteroid field at " + x + ", " + y + ", " + z);
WarpDrive.instance.spaceWorldGenerator.generateAsteroidField(player.worldObj, x, y, z);
} else if (struct.equals("gascloud")) {
WarpDrive.logger.info("/generate: generating gas cloud at " + x + ", " + y + ", " + z);
String type = (params.length > 1) ? params[1] : null;
WarpDrive.instance.spaceWorldGenerator.generateGasCloudOfColor(player.worldObj, x, y, z, 15, 20, type);
} else if (struct.equals("star")) {
WarpDrive.logger.info("/generate: generating star at " + x + ", " + y + ", " + z);
String type = (params.length > 1) ? params[1] : null;
WarpDrive.instance.spaceWorldGenerator.generateStar(player.worldObj, x, y, z, type);
DeployableStructure star = StructureManager.getStar(player.worldObj.rand, type);
if (star == null) {
WarpDrive.addChatMessage(player, "Invalid star type '" + type + "'");
} else {
WarpDrive.logger.info("/generate: Generating star (class " + star + ") at " + x + " " + y + " " + z);
star.generate(player.worldObj, player.worldObj.rand, x, y, z);
}
} else if (struct.equals("jumpgate")) {
if (params.length == 2) {
WarpDrive.logger.info("/generate: creating jumpgate at " + x + ", " + y + ", " + z);
if (WarpDrive.jumpgates.addGate(params[1], x, y, z)) {
JumpgateGenerator.generate(player.worldObj, x, Math.min(y, 255 - JumpgateGenerator.GATE_SIZE_HALF - 1), z);
} else {

View file

@ -79,13 +79,6 @@ public class SpaceWorldGenerator implements IWorldGenerator {
moon.generate(world, world.rand, x, y, z);
}
public void generateStar(World world, int x, int y, int z, final String starName) {
DeployableStructure star = StructureManager.getStar(world.rand, starName);
WarpDrive.logger.info("Generating star (class " + star + ") at " + x + " " + y + " " + z);
star.generate(world, world.rand, x, y, z);
}
private static void generateSmallShip(World world, int x, int y, int z, int jitter) {
int x2 = x + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(jitter));
int y2 = y + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(jitter));
@ -274,12 +267,12 @@ public class SpaceWorldGenerator implements IWorldGenerator {
* coordinate of center
*/
public static void generateRandomAsteroid(World world, int x, int y, int z) {
DeployableStructure asteroid = StructureManager.getAsteroid(world.rand, null);
WarpDrive.logger.info("Generating asteroid (class " + asteroid + ") at " + x + " " + y + " " + z);
asteroid.generate(world, world.rand, x, y, z);
/*
int asteroidSize = 1 + world.rand.nextInt(6);
if (asteroidSizeMax != 0) {