Add no save option

This commit is contained in:
Zoe Gidiere 2024-10-11 16:35:26 -06:00
parent d31679e6be
commit 8a028b193a
2 changed files with 27 additions and 14 deletions

View File

@ -36,6 +36,9 @@ public final class TerraCLI implements Callable<Integer> {
@Option(names = { "--min-height"}, description = "Minimum height of the world.")
private int minHeight = -64;
@Option(names = { "--no-save"}, description = "Don't save the world to disk.")
private boolean noSave = false;
@Override
public Integer call() {
Logger LOGGER = LoggerFactory.getLogger(TerraCLI.class);
@ -46,22 +49,24 @@ public final class TerraCLI implements Callable<Integer> {
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.serialize().parallel().forEach(mcaFile -> {
Vector2Int pos = mcaFile.getLeft();
String name = MCAUtil.createNameFromRegionLocation(pos.getX(), pos.getZ());
LOGGER.info("Writing region ({}, {}) to {}", pos.getX(), pos.getZ(), name);
if(!noSave) {
world.serialize().parallel().forEach(mcaFile -> {
Vector2Int pos = mcaFile.getLeft();
String name = MCAUtil.createNameFromRegionLocation(pos.getX(), pos.getZ());
LOGGER.info("Writing region ({}, {}) to {}", pos.getX(), pos.getZ(), name);
try {
MCAUtil.write(mcaFile.getRight(), name);
} catch(IOException e) {
e.printStackTrace();
}
LOGGER.info("Wrote region to file.");
});
try {
MCAUtil.write(mcaFile.getRight(), name);
} catch(IOException e) {
e.printStackTrace();
}
LOGGER.info("Wrote region to file.");
});
}
LOGGER.info("Done.");
return 0;
}

View File

@ -43,6 +43,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
private final ChunkGenerator chunkGenerator;
private final BiomeProvider biomeProvider;
private final ConfigPack pack;
private final boolean noSave;
private final AtomicInteger amount = new AtomicInteger(0);
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,
int maxHeight,
int minHeight,
ConfigPack pack) {
ConfigPack pack, boolean noSave) {
this.size = size;
this.maxHeight = maxHeight;
this.minHeight = minHeight;
@ -59,6 +60,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
this.chunkGenerator = pack.getGeneratorProvider().newInstance(pack);
this.biomeProvider = pack.getBiomeProvider();
this.pack = pack;
this.noSave = noSave;
size += 1;
@ -84,7 +86,13 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
futures.add(executor.submit(() -> {
try {
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();
chunkGenerator.generateChunkData(chunk, this, cachingBiomeProvider, finalX, finalZ);
CLIProtoWorld protoWorld = new CLIProtoWorld(this, cachingBiomeProvider, finalX, finalZ);