Merge branch 'dev/cli' into dev/caching

This commit is contained in:
Zoe Gidiere 2024-10-11 16:40:26 -06:00
commit 819be16d83
2 changed files with 28 additions and 15 deletions

View File

@ -36,8 +36,11 @@ public final class TerraCLI implements Callable<Integer> {
@Option(names = { "--min-height"}, description = "Minimum height of the world.") @Option(names = { "--min-height"}, description = "Minimum height of the world.")
private int minHeight = -64; private int minHeight = -64;
@Option(names = { "--no-save"}, description = "Don't save the world to disk.")
private boolean noSave = false;
@Override @Override
public Integer call() throws Exception { // your business logic goes here... public Integer call() {
Logger LOGGER = LoggerFactory.getLogger(TerraCLI.class); Logger LOGGER = LoggerFactory.getLogger(TerraCLI.class);
LOGGER.info("Starting Terra CLI..."); LOGGER.info("Starting Terra CLI...");
@ -46,10 +49,11 @@ public final class TerraCLI implements Callable<Integer> {
ConfigPack generate = platform.getConfigRegistry().getByID(pack).orElseThrow(); ConfigPack generate = platform.getConfigRegistry().getByID(pack).orElseThrow();
CLIWorld world = new CLIWorld(size, seed, maxHeight, minHeight, generate); CLIWorld world = new CLIWorld(size, seed, maxHeight, minHeight, generate, noSave);
world.generate(); world.generate();
if(!noSave) {
world.serialize().parallel().forEach(mcaFile -> { world.serialize().parallel().forEach(mcaFile -> {
Vector2Int pos = mcaFile.getLeft(); Vector2Int pos = mcaFile.getLeft();
String name = MCAUtil.createNameFromRegionLocation(pos.getX(), pos.getZ()); String name = MCAUtil.createNameFromRegionLocation(pos.getX(), pos.getZ());
@ -62,6 +66,7 @@ public final class TerraCLI implements Callable<Integer> {
} }
LOGGER.info("Wrote region to file."); LOGGER.info("Wrote region to file.");
}); });
}
LOGGER.info("Done."); LOGGER.info("Done.");
return 0; return 0;
} }

View File

@ -43,6 +43,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
private final ChunkGenerator chunkGenerator; private final ChunkGenerator chunkGenerator;
private final BiomeProvider biomeProvider; private final BiomeProvider biomeProvider;
private final ConfigPack pack; private final ConfigPack pack;
private final boolean noSave;
private final AtomicInteger amount = new AtomicInteger(0); private final AtomicInteger amount = new AtomicInteger(0);
private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() - 1); private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() - 1);
@ -51,7 +52,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
long seed, long seed,
int maxHeight, int maxHeight,
int minHeight, int minHeight,
ConfigPack pack) { ConfigPack pack, boolean noSave) {
this.size = size; this.size = size;
this.maxHeight = maxHeight; this.maxHeight = maxHeight;
this.minHeight = minHeight; this.minHeight = minHeight;
@ -59,6 +60,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
this.chunkGenerator = pack.getGeneratorProvider().newInstance(pack); this.chunkGenerator = pack.getGeneratorProvider().newInstance(pack);
this.biomeProvider = pack.getBiomeProvider(); this.biomeProvider = pack.getBiomeProvider();
this.pack = pack; this.pack = pack;
this.noSave = noSave;
size += 1; size += 1;
@ -84,7 +86,13 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
futures.add(executor.submit(() -> { futures.add(executor.submit(() -> {
try { try {
int num = amount.getAndIncrement(); int num = amount.getAndIncrement();
CLIChunk chunk = getChunkAt(finalX, finalZ); CLIChunk chunk;
if (!noSave) {
chunk = getChunkAt(finalX, finalZ);
} else {
chunk = new CLIChunk(Math.floorMod(finalX, 32), Math.floorMod(finalZ, 32), this);
}
BiomeProvider cachingBiomeProvider = pack.getBiomeProvider(); BiomeProvider cachingBiomeProvider = pack.getBiomeProvider();
chunkGenerator.generateChunkData(chunk, this, cachingBiomeProvider, finalX, finalZ); chunkGenerator.generateChunkData(chunk, this, cachingBiomeProvider, finalX, finalZ);
CLIProtoWorld protoWorld = new CLIProtoWorld(this, cachingBiomeProvider, finalX, finalZ); CLIProtoWorld protoWorld = new CLIProtoWorld(this, cachingBiomeProvider, finalX, finalZ);