auto-spawnpoints should work too

This commit is contained in:
Piegames 2018-11-14 18:36:59 +01:00
parent 0be54d1fcc
commit d79061f722
2 changed files with 33 additions and 21 deletions

View File

@ -19,6 +19,7 @@ import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Help.Visibility;
import picocli.CommandLine.HelpCommand;
import picocli.CommandLine.ITypeConverter;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.ParentCommand;
@ -56,8 +57,9 @@ public class CommandLineMain implements Runnable {
private CommandLineMain parent;
@Option(names = "-i", description = "override the iteration spawn offset increment",
defaultValue = "380", showDefaultValue = CommandLine.Help.Visibility.ALWAYS)
private int increment = 380;
defaultValue = "25", showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
hidden = true)
private int increment = 25;
@Parameters(index = "0", description = "X-coordinate")
private int x;
@ -83,7 +85,7 @@ public class CommandLineMain implements Runnable {
}
log.info("Generating world");
server.runMinecraft(world, generateSpawnpoints(x, z, w, h, increment, 12));
server.runMinecraft(world, generateSpawnpoints(x, z, w, h, increment));
log.info("Cleaning up temporary files");
try {
world.resetSpawn();
@ -104,6 +106,8 @@ public class CommandLineMain implements Runnable {
@ParentCommand
private CommandLineMain parent;
@Parameters(index = "0..*")
private Vector2i[] spawnPoints;
// @Option(names = { "-s", "--customspawn" }, description = "Customized SpawnPoints")
// private String[] customSpawnPoints;
@ -121,10 +125,6 @@ public class CommandLineMain implements Runnable {
return;
}
List<Vector2i> spawnpoints = new ArrayList<>();
spawnpoints.add(new Vector2i(100, 100));
spawnpoints.add(new Vector2i(200, 100));
spawnpoints.add(new Vector2i(300, 100));
spawnpoints.add(new Vector2i(400, 100));
log.info("Generating world");
server.runMinecraft(world, spawnpoints);
log.info("Cleaning up temporary files");
@ -155,28 +155,38 @@ public class CommandLineMain implements Runnable {
/* Without this, JOML will print vectors out in scientific notation which isn't the most human readable thing in the world */
System.setProperty("joml.format", "false");
args = new String[] { "-v", "--debug-server", "-s",
"/home/piegames/Documents/GitHub/MinecraftLandGenerator/testserver/server.jar",
"auto-spawnpoints", "200", "100", "200", "100" };
CommandLine cli = new CommandLine(new CommandLineMain());
cli.registerConverter(Vector2i.class, new ITypeConverter<Vector2i>() {
@Override
public Vector2i convert(String value) throws Exception {
String[] dims = value.split(",");
if (dims.length != 2) throw new IllegalArgumentException(
"Input must have two values for the two dimensions");
return new Vector2i(Integer.valueOf(dims[0]), Integer.valueOf(dims[1]));
}
});
cli.parseWithHandler(new RunAll(), args);
}
/**
* @param maxInc
* @param increment
* Maximum number of chunks between two spawn points, horizontally or vertically
* @param generationMargin
* @param margin
* The radius to each side that will be generated by the server (Not the diameter!)
*/
public static List<Vector2i> generateSpawnpoints(int startX, int startZ, int width, int height,
int maxInc, int generationRadius) {
if (width < generationRadius || height < generationRadius)
throw new IllegalArgumentException("Width and height must both be at least "
+ (generationRadius * 2 + 1) + ", but are " + width + " and " + height);
List<Integer> xPoints = generateLinearSpawnpoints(startX + generationRadius,
width - generationRadius * 2, maxInc);
List<Integer> zPoints = generateLinearSpawnpoints(startZ + generationRadius,
height - generationRadius * 2, maxInc);
int increment) {
int margin = increment / 2;
if (width < margin || height < margin)
throw new IllegalArgumentException("Width and height must both be at least " + increment
+ ", but are " + width + " and " + height);
List<Integer> xPoints =
generateLinearSpawnpoints(startX + margin, width - increment, increment);
log.debug("X grid: " + xPoints);
List<Integer> zPoints =
generateLinearSpawnpoints(startZ + margin, height - increment, increment);
log.debug("Z grid: " + zPoints);
List<Vector2i> spawnPoints = new ArrayList<>(xPoints.size() * zPoints.size());
for (int x : xPoints)
for (int z : zPoints)
@ -187,7 +197,7 @@ public class CommandLineMain implements Runnable {
private static List<Integer> generateLinearSpawnpoints(int start, int length, int maxStep) {
int stepCount = (int) Math.ceil((double) length / maxStep);
double realStep = length / stepCount;
return IntStream.range(0, stepCount).mapToObj(i -> start + (int) (realStep * i))
return IntStream.rangeClosed(0, stepCount).mapToObj(i -> start + (int) (realStep * i))
.collect(Collectors.toList());
}
}

View File

@ -40,6 +40,8 @@ public class Server {
public Server(boolean debugServer, String[] javaOpts, Path serverFile) {
this.debugServer = debugServer;
if (!Files.exists(serverFile)) throw new IllegalArgumentException(serverFile.toString()
+ " must be an existing file pointing to the minecraft server");
List<String> opts = new ArrayList<>(
Arrays.asList(javaOpts != null ? javaOpts : new String[] { "java", "-jar" }));
opts.add(serverFile.toString());