auto-spawnpoints should work too
This commit is contained in:
parent
0be54d1fcc
commit
d79061f722
@ -19,6 +19,7 @@ import picocli.CommandLine;
|
|||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
import picocli.CommandLine.Help.Visibility;
|
import picocli.CommandLine.Help.Visibility;
|
||||||
import picocli.CommandLine.HelpCommand;
|
import picocli.CommandLine.HelpCommand;
|
||||||
|
import picocli.CommandLine.ITypeConverter;
|
||||||
import picocli.CommandLine.Option;
|
import picocli.CommandLine.Option;
|
||||||
import picocli.CommandLine.Parameters;
|
import picocli.CommandLine.Parameters;
|
||||||
import picocli.CommandLine.ParentCommand;
|
import picocli.CommandLine.ParentCommand;
|
||||||
@ -56,8 +57,9 @@ public class CommandLineMain implements Runnable {
|
|||||||
private CommandLineMain parent;
|
private CommandLineMain parent;
|
||||||
|
|
||||||
@Option(names = "-i", description = "override the iteration spawn offset increment",
|
@Option(names = "-i", description = "override the iteration spawn offset increment",
|
||||||
defaultValue = "380", showDefaultValue = CommandLine.Help.Visibility.ALWAYS)
|
defaultValue = "25", showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
|
||||||
private int increment = 380;
|
hidden = true)
|
||||||
|
private int increment = 25;
|
||||||
|
|
||||||
@Parameters(index = "0", description = "X-coordinate")
|
@Parameters(index = "0", description = "X-coordinate")
|
||||||
private int x;
|
private int x;
|
||||||
@ -83,7 +85,7 @@ public class CommandLineMain implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info("Generating world");
|
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");
|
log.info("Cleaning up temporary files");
|
||||||
try {
|
try {
|
||||||
world.resetSpawn();
|
world.resetSpawn();
|
||||||
@ -104,6 +106,8 @@ public class CommandLineMain implements Runnable {
|
|||||||
@ParentCommand
|
@ParentCommand
|
||||||
private CommandLineMain parent;
|
private CommandLineMain parent;
|
||||||
|
|
||||||
|
@Parameters(index = "0..*")
|
||||||
|
private Vector2i[] spawnPoints;
|
||||||
// @Option(names = { "-s", "--customspawn" }, description = "Customized SpawnPoints")
|
// @Option(names = { "-s", "--customspawn" }, description = "Customized SpawnPoints")
|
||||||
// private String[] customSpawnPoints;
|
// private String[] customSpawnPoints;
|
||||||
|
|
||||||
@ -121,10 +125,6 @@ public class CommandLineMain implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<Vector2i> spawnpoints = new ArrayList<>();
|
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");
|
log.info("Generating world");
|
||||||
server.runMinecraft(world, spawnpoints);
|
server.runMinecraft(world, spawnpoints);
|
||||||
log.info("Cleaning up temporary files");
|
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 */
|
/* 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");
|
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());
|
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);
|
cli.parseWithHandler(new RunAll(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param maxInc
|
* @param increment
|
||||||
* Maximum number of chunks between two spawn points, horizontally or vertically
|
* 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!)
|
* 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,
|
public static List<Vector2i> generateSpawnpoints(int startX, int startZ, int width, int height,
|
||||||
int maxInc, int generationRadius) {
|
int increment) {
|
||||||
if (width < generationRadius || height < generationRadius)
|
int margin = increment / 2;
|
||||||
throw new IllegalArgumentException("Width and height must both be at least "
|
if (width < margin || height < margin)
|
||||||
+ (generationRadius * 2 + 1) + ", but are " + width + " and " + height);
|
throw new IllegalArgumentException("Width and height must both be at least " + increment
|
||||||
List<Integer> xPoints = generateLinearSpawnpoints(startX + generationRadius,
|
+ ", but are " + width + " and " + height);
|
||||||
width - generationRadius * 2, maxInc);
|
List<Integer> xPoints =
|
||||||
List<Integer> zPoints = generateLinearSpawnpoints(startZ + generationRadius,
|
generateLinearSpawnpoints(startX + margin, width - increment, increment);
|
||||||
height - generationRadius * 2, maxInc);
|
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());
|
List<Vector2i> spawnPoints = new ArrayList<>(xPoints.size() * zPoints.size());
|
||||||
for (int x : xPoints)
|
for (int x : xPoints)
|
||||||
for (int z : zPoints)
|
for (int z : zPoints)
|
||||||
@ -187,7 +197,7 @@ public class CommandLineMain implements Runnable {
|
|||||||
private static List<Integer> generateLinearSpawnpoints(int start, int length, int maxStep) {
|
private static List<Integer> generateLinearSpawnpoints(int start, int length, int maxStep) {
|
||||||
int stepCount = (int) Math.ceil((double) length / maxStep);
|
int stepCount = (int) Math.ceil((double) length / maxStep);
|
||||||
double realStep = length / stepCount;
|
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());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,8 @@ public class Server {
|
|||||||
|
|
||||||
public Server(boolean debugServer, String[] javaOpts, Path serverFile) {
|
public Server(boolean debugServer, String[] javaOpts, Path serverFile) {
|
||||||
this.debugServer = debugServer;
|
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<>(
|
List<String> opts = new ArrayList<>(
|
||||||
Arrays.asList(javaOpts != null ? javaOpts : new String[] { "java", "-jar" }));
|
Arrays.asList(javaOpts != null ? javaOpts : new String[] { "java", "-jar" }));
|
||||||
opts.add(serverFile.toString());
|
opts.add(serverFile.toString());
|
||||||
|
Reference in New Issue
Block a user