Search in sources :

Example 1 with World2

use of org.pepsoft.worldpainter.World2 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");
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) Random(java.util.Random) SecureRandom(java.security.SecureRandom) JavaWorldExporter(org.pepsoft.worldpainter.exporting.JavaWorldExporter) World2(org.pepsoft.worldpainter.World2) SecureRandom(java.security.SecureRandom) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with World2

use of org.pepsoft.worldpainter.World2 in project WorldPainter by Captain-Chaos.

the class IntegrityChecker method main.

public static void main(String[] args) throws IOException, ClassNotFoundException {
    System.out.println("Loading " + args[0]);
    World2 world;
    try (ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new FileInputStream(args[0])))) {
        world = (World2) in.readObject();
    }
    for (Dimension dimension : world.getDimensions()) {
        float maxHeight = (dimension.getMaxHeight() - 1) + 0.5f;
        System.out.println("Checking integrity of " + dimension.getName() + " dimension");
        for (Tile tile : dimension.getTiles()) {
            boolean tileReported = false;
            for (int x = 0; x < Constants.TILE_SIZE; x++) {
                for (int y = 0; y < Constants.TILE_SIZE; y++) {
                    float height = tile.getHeight(x, y);
                    if (height < -0.5f) {
                        if (!tileReported) {
                            System.out.println("Tile " + tile.getX() + "," + tile.getY());
                            tileReported = true;
                        }
                        System.out.println("Height " + height + " < -0.5 @ " + x + "," + y);
                    } else if (height > maxHeight) {
                        if (!tileReported) {
                            System.out.println("Tile " + tile.getX() + "," + tile.getY());
                            tileReported = true;
                        }
                        System.out.println("Height " + height + " > " + maxHeight + " @ " + x + "," + y);
                    }
                }
            }
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) World2(org.pepsoft.worldpainter.World2) Tile(org.pepsoft.worldpainter.Tile) Dimension(org.pepsoft.worldpainter.Dimension) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with World2

use of org.pepsoft.worldpainter.World2 in project WorldPainter by Captain-Chaos.

the class ResetLava method main.

public static void main(String[] args) throws IOException, ClassNotFoundException {
    System.out.println("Loading world " + args[0]);
    File worldFile = new File(args[0]);
    int waterLevel = Integer.parseInt(args[1]);
    World2 world;
    try (ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new FileInputStream(worldFile)))) {
        world = (World2) in.readObject();
    }
    System.out.println("World loaded");
    Dimension dim0 = world.getDimension(0);
    for (Tile tile : dim0.getTiles()) {
        for (int x = 0; x < TILE_SIZE; x++) {
            for (int y = 0; y < TILE_SIZE; y++) {
                // if ((tile.getWaterLevel(x, y) > (tile.getIntHeight(x, y))) && tile.getBitLayerValue(FloodWithLava.INSTANCE, x, y)) {
                tile.setBitLayerValue(FloodWithLava.INSTANCE, x, y, false);
                tile.setWaterLevel(x, y, waterLevel);
            // }
            }
        }
        System.out.print('.');
    }
    System.out.println();
    System.out.println("Saving world " + args[0]);
    try (ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(worldFile)))) {
        out.writeObject(world);
    }
    System.out.println("World saved");
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) World2(org.pepsoft.worldpainter.World2) FileOutputStream(java.io.FileOutputStream) Tile(org.pepsoft.worldpainter.Tile) Dimension(org.pepsoft.worldpainter.Dimension) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with World2

use of org.pepsoft.worldpainter.World2 in project WorldPainter by Captain-Chaos.

the class RepairHeightMap method main.

public static final void main(String[] args) throws IOException, ClassNotFoundException {
    System.out.println("Scanning world " + args[0]);
    World2 world;
    try (ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new FileInputStream(args[0])))) {
        world = (World2) in.readObject();
    }
    boolean repairsPerformed = false;
    for (Dimension dimension : world.getDimensions()) {
        repairsPerformed |= repairDimension(dimension);
    }
    if (repairsPerformed) {
        System.out.println("Repairs performed. Writing world out to " + args[0] + ".repaired");
        try (ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(args[0] + ".repaired")))) {
            out.writeObject(world);
        }
    } else {
        System.out.println("No repairs performed.");
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) World2(org.pepsoft.worldpainter.World2) FileOutputStream(java.io.FileOutputStream) Dimension(org.pepsoft.worldpainter.Dimension) ObjectOutputStream(java.io.ObjectOutputStream) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 5 with World2

use of org.pepsoft.worldpainter.World2 in project WorldPainter by Captain-Chaos.

the class PruneTiles method main.

public static void main(String[] args) throws IOException, ClassNotFoundException {
    File worldFile = new File(args[0]);
    int maxTileDistance = Integer.parseInt(args[1]);
    World2 world;
    try (ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new FileInputStream(worldFile)))) {
        world = (World2) in.readObject();
    }
    for (Dimension dimension : world.getDimensions()) {
        for (Tile tile : dimension.getTiles()) {
            int dx = Math.abs(tile.getX()), dy = Math.abs(tile.getY());
            if ((dx > maxTileDistance) || (dy > maxTileDistance)) {
                // It's an outlier. Remove it
                System.out.println("Removing tile at " + tile.getX() + ", " + tile.getY());
                dimension.removeTile(tile);
            }
        }
    }
    try (ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(worldFile)))) {
        out.writeObject(world);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) World2(org.pepsoft.worldpainter.World2) FileOutputStream(java.io.FileOutputStream) Tile(org.pepsoft.worldpainter.Tile) Dimension(org.pepsoft.worldpainter.Dimension) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

World2 (org.pepsoft.worldpainter.World2)6 FileInputStream (java.io.FileInputStream)5 ObjectInputStream (java.io.ObjectInputStream)5 GZIPInputStream (java.util.zip.GZIPInputStream)5 Dimension (org.pepsoft.worldpainter.Dimension)5 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 Tile (org.pepsoft.worldpainter.Tile)3 Point (java.awt.Point)1 SecureRandom (java.security.SecureRandom)1 Random (java.util.Random)1 JavaWorldExporter (org.pepsoft.worldpainter.exporting.JavaWorldExporter)1