mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Merge branch 'ver/6.6.0' into dev/1.21.2
This commit is contained in:
@@ -10,6 +10,9 @@ dependencies {
|
||||
shadedApi("commons-io", "commons-io", Versions.Libraries.Internal.apacheIO)
|
||||
shadedApi("com.github.Querz", "NBT", Versions.Libraries.Internal.nbt)
|
||||
|
||||
shadedImplementation("info.picocli", "picocli", Versions.CLI.picocli)
|
||||
annotationProcessor("info.picocli", "picocli-codegen", Versions.CLI.picocli)
|
||||
|
||||
shadedImplementation("com.google.guava", "guava", Versions.Libraries.Internal.guava)
|
||||
|
||||
shadedImplementation("ch.qos.logback", "logback-classic", Versions.CLI.logback)
|
||||
@@ -26,6 +29,12 @@ tasks.withType<Jar> {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
doFirst {
|
||||
options.compilerArgs.add("-Aproject=${project.group}/${project.name}")
|
||||
}
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set(javaMainClass)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ public class CLIPlatform extends AbstractPlatform {
|
||||
private final CLIWorldHandle worldHandle = new CLIWorldHandle();
|
||||
private final CLIItemHandle itemHandle = new CLIItemHandle();
|
||||
|
||||
private final int generationThreads = Runtime.getRuntime().availableProcessors() - 1;
|
||||
|
||||
public CLIPlatform() {
|
||||
LOGGER.info("Root directory: {}", getDataFolder().getAbsoluteFile());
|
||||
load();
|
||||
@@ -58,4 +60,9 @@ public class CLIPlatform extends AbstractPlatform {
|
||||
super.register(registry);
|
||||
registry.registerLoader(PlatformBiome.class, (TypeLoader<PlatformBiome>) (annotatedType, o, configLoader, depthTracker) -> () -> o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenerationThreads() {
|
||||
return generationThreads;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,41 +5,74 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.api.util.vector.Vector2Int;
|
||||
import com.dfsek.terra.cli.world.CLIWorld;
|
||||
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.Option;
|
||||
|
||||
public final class TerraCLI {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TerraCLI.class);
|
||||
|
||||
public static void main(String... args) {
|
||||
//TODO auto pull in version
|
||||
@Command(name = "TerraCLI", mixinStandardHelpOptions = true, version = "6.6.0",
|
||||
description = "Generates a Terra World and saves it in minecraft region format.")
|
||||
public final class TerraCLI implements Callable<Integer> {
|
||||
@Option(names = { "-s", "--size"}, description = "Number of regions to generate.")
|
||||
private int size = 2;
|
||||
|
||||
@Option(names = { "-p", "--pack"}, description = "Config pack to use.")
|
||||
private String pack = "OVERWORLD";
|
||||
|
||||
@Option(names = { "--seed"}, description = "Seed for world generation.")
|
||||
private long seed = 0;
|
||||
|
||||
@Option(names = { "--max-height"}, description = "Maximum height of the world.")
|
||||
private int maxHeight = 320;
|
||||
|
||||
@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);
|
||||
LOGGER.info("Starting Terra CLI...");
|
||||
|
||||
CLIPlatform platform = new CLIPlatform();
|
||||
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
|
||||
ConfigPack generate = platform.getConfigRegistry().getByID("OVERWORLD").orElseThrow(); // TODO: make this a cli argument
|
||||
ConfigPack generate = platform.getConfigRegistry().getByID(pack).orElseThrow();
|
||||
|
||||
CLIWorld world = new CLIWorld(2, 2, 384, -64, 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.");
|
||||
System.exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void main(String... args) {
|
||||
int exitCode = new CommandLine(new TerraCLI()).execute(args);
|
||||
System.exit(exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -73,6 +75,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
ArrayList<Double> CPSHistory = new ArrayList<>();
|
||||
int sizeChunks = size * 32;
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
final AtomicLong start = new AtomicLong(System.nanoTime());
|
||||
@@ -83,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);
|
||||
@@ -91,6 +100,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
if(num % 240 == 239) {
|
||||
long time = System.nanoTime();
|
||||
double cps = num / ((double) (time - start.get()) / 1000000000);
|
||||
CPSHistory.add(cps);
|
||||
LOGGER.info("Generating chunk at ({}, {}), generated {} chunks at {}cps", finalX, finalZ, num, cps);
|
||||
amount.set(0);
|
||||
start.set(System.nanoTime());
|
||||
@@ -109,6 +119,8 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info("Average CPS: {}", CPSHistory.stream().mapToDouble(d -> d).average().orElse(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user