use of org.pepsoft.worldpainter.exporting.JavaWorldExporter in project WorldPainter by Captain-Chaos.
the class Timings method main.
public static void main(String[] args) throws IOException, ProgressReceiver.OperationCancelled, ClassNotFoundException {
Random random = new SecureRandom();
// final Configuration defaultConfig = new Configuration();
final World2 world;
try (ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new FileInputStream(args[0])))) {
world = (World2) in.readObject();
}
long totalDuration = 0;
for (int i = 0; i < 5; i++) {
// final World2 world = WorldFactory.createDefaultWorld(defaultConfig, random.nextLong());
world.getDimension(0).getTileFactory().setSeed(random.nextLong());
if (world.getPlatform() == null) {
if (world.getMaxHeight() == Constants.DEFAULT_MAX_HEIGHT_2) {
world.setPlatform(DefaultPlugin.JAVA_ANVIL);
} else {
world.setPlatform(DefaultPlugin.JAVA_MCREGION);
}
}
final JavaWorldExporter exporter = new JavaWorldExporter(world);
System.out.println("Starting export of world " + world.getName() + " " + i + " (seed: " + world.getDimension(0).getSeed() + ")");
File baseDir = new File(System.getProperty("user.dir"));
String name = world.getName() + ' ' + i;
File worldDir = new File(baseDir, FileUtils.sanitiseName(name));
if (worldDir.isDirectory()) {
FileUtils.deleteDir(worldDir);
}
long start = System.currentTimeMillis();
exporter.export(baseDir, name, null, null);
long duration = System.currentTimeMillis() - start;
System.out.println("Exporting world took " + (duration / 1000f) + " s");
totalDuration += duration;
}
System.out.println("Average duration: " + (totalDuration / 5000f) + " s");
}
use of org.pepsoft.worldpainter.exporting.JavaWorldExporter in project WorldPainter by Captain-Chaos.
the class Export method main.
public static void main(String[] args) throws IOException, ClassNotFoundException, OperationCancelled, CertificateException {
// Logger rootLogger = Logger.getLogger("");
// rootLogger.setLevel(Level.OFF);
// Load or initialise configuration
// This will migrate the configuration directory if necessary
Configuration config = Configuration.load();
if (config == null) {
System.out.println("Creating new configuration");
config = new Configuration();
}
Configuration.setInstance(config);
System.out.println("Installation ID: " + config.getUuid());
// Load trusted WorldPainter root certificate
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
X509Certificate trustedCert = (X509Certificate) certificateFactory.generateCertificate(ClassLoader.getSystemResourceAsStream("wproot.pem"));
// Load the plugins
File pluginsDir = new File(Configuration.getConfigDir(), "plugins");
if (pluginsDir.isDirectory()) {
PluginManager.loadPlugins(pluginsDir, trustedCert.getPublicKey());
}
WPPluginManager.initialise(config.getUuid());
File worldFile = new File(args[0]);
System.out.println("Loading " + worldFile);
World2 world;
try (ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new FileInputStream(worldFile)))) {
world = (World2) in.readObject();
}
for (int i = 0; i < Terrain.CUSTOM_TERRAIN_COUNT; i++) {
MixedMaterial material = world.getMixedMaterial(i);
Terrain.setCustomMaterial(i, material);
}
if (world.getPlatform() == null) {
if (world.getMaxHeight() == Constants.DEFAULT_MAX_HEIGHT_2) {
world.setPlatform(DefaultPlugin.JAVA_ANVIL);
} else {
world.setPlatform(DefaultPlugin.JAVA_MCREGION);
}
}
File exportDir;
if (args.length > 1) {
exportDir = new File(args[1]);
} else {
File minecraftDir = MinecraftUtil.findMinecraftDir();
exportDir = new File(minecraftDir, "saves");
}
System.out.println("Exporting to " + exportDir);
System.out.println("+---------+---------+---------+---------+---------+");
JavaWorldExporter exporter = new JavaWorldExporter(world);
exporter.export(exportDir, world.getName(), exporter.selectBackupDir(new File(exportDir, FileUtils.sanitiseName(world.getName()))), new ProgressReceiver() {
@Override
public void setProgress(float progressFraction) throws OperationCancelled {
int progress = (int) (progressFraction * 50);
while (progress > previousProgress) {
System.out.print('.');
previousProgress++;
}
}
@Override
public void exceptionThrown(Throwable exception) {
exception.printStackTrace();
System.exit(1);
}
@Override
public void reset() {
System.out.println();
previousProgress = -1;
}
@Override
public void done() {
}
@Override
public void setMessage(String message) throws OperationCancelled {
}
@Override
public void checkForCancellation() throws OperationCancelled {
}
@Override
public void subProgressStarted(SubProgressReceiver subProgressReceiver) throws OperationCancelled {
}
private int previousProgress = -1;
});
System.out.println();
System.out.println("World " + world.getName() + " exported successfully");
}
use of org.pepsoft.worldpainter.exporting.JavaWorldExporter in project WorldPainter by Captain-Chaos.
the class TestTool method main.
public static void main(String[] args) throws IOException, OperationCancelled {
Random random = new Random();
long seed = random.nextLong();
// TileFactory tileFactory = new NoiseTileFactory(Terrain.GRASS, DEFAULT_MAX_HEIGHT_2, 58, 62, false, false);
TileFactory tileFactory = TileFactoryFactory.createFlatTileFactory(seed, Terrain.GRASS, DEFAULT_MAX_HEIGHT_2, 62, 0, false, false);
World2 world = new World2(JAVA_ANVIL, seed, tileFactory, DEFAULT_MAX_HEIGHT_2);
world.setName("TestWorld");
world.setSpawnPoint(new Point(64, 64));
world.setGameType(GameType.CREATIVE);
Dimension dimension = world.getDimension(0);
dimension.addTile(tileFactory.createTile(0, 0));
Garden garden = dimension.getGarden();
// garden.plantSeed(inn);
while (!garden.tick()) ;
JavaWorldExporter worldExporter = new JavaWorldExporter(world);
File exportDir = new File(args[0]);
worldExporter.export(exportDir, "TestWorld", worldExporter.selectBackupDir(new File(exportDir, "TestWorld")), null);
}
use of org.pepsoft.worldpainter.exporting.JavaWorldExporter in project WorldPainter by Captain-Chaos.
the class ExportWorldOp method go.
@Override
public Void go() throws ScriptException {
goCalled();
// not exported before)
if (world.getPlatform() == null) {
world.setPlatform((world.getMaxHeight() == DEFAULT_MAX_HEIGHT_2) ? DefaultPlugin.JAVA_ANVIL : DefaultPlugin.JAVA_MCREGION);
}
// Load any custom materials defined in the world
for (int i = 0; i < Terrain.CUSTOM_TERRAIN_COUNT; i++) {
MixedMaterial material = world.getMixedMaterial(i);
Terrain.setCustomMaterial(i, material);
}
// Select and create (if necessary) the backups directory
File baseDir = new File(directory);
if (!baseDir.isDirectory()) {
throw new ScriptException("Directory " + directory + " does not exist or is not a directory");
}
File worldDir = new File(baseDir, FileUtils.sanitiseName(world.getName()));
JavaWorldExporter exporter = new JavaWorldExporter(world);
try {
File backupDir = exporter.selectBackupDir(worldDir);
// Export the world
exporter.export(baseDir, world.getName(), backupDir, null);
} catch (ProgressReceiver.OperationCancelled e) {
// Can never happen since we don't pass a progress receiver in
throw new InternalError();
} catch (IOException e) {
throw new ScriptException("I/O error while exporting world", e);
}
return null;
}
use of org.pepsoft.worldpainter.exporting.JavaWorldExporter in project WorldPainter by Captain-Chaos.
the class RegressionIT method exportJavaWorld.
protected File exportJavaWorld(World2 world, File baseDir) throws IOException, ProgressReceiver.OperationCancelled {
// Prepare for export
for (int i = 0; i < Terrain.CUSTOM_TERRAIN_COUNT; i++) {
MixedMaterial material = world.getMixedMaterial(i);
Terrain.setCustomMaterial(i, material);
}
// Export
logger.info("Exporting world {}", world.getName());
JavaWorldExporter worldExporter = new JavaWorldExporter(world);
worldExporter.export(baseDir, world.getName(), null, null);
// Return the directory into which the world was exported
return new File(baseDir, FileUtils.sanitiseName(world.getName()));
}
Aggregations