Search in sources :

Example 1 with MinecraftMapTileProvider

use of org.pepsoft.minecraft.MinecraftMapTileProvider in project WorldPainter by Captain-Chaos.

the class MapViewer method main.

public static void main(String[] args) throws IOException {
    File mySavesDir = null;
    File minecraftDir = MinecraftUtil.findMinecraftDir();
    if (minecraftDir != null) {
        mySavesDir = new File(minecraftDir, "saves");
    }
    File levelDatFile = FileUtils.selectFileForOpen(null, "Select Minecraft map level.dat file", mySavesDir, new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().equalsIgnoreCase("level.dat");
        }

        @Override
        public String getDescription() {
            return "Minecraft levels (level.dat)";
        }
    });
    if (levelDatFile != null) {
        final File worldDir = levelDatFile.getParentFile();
        TileProvider tileProvider = new MinecraftMapTileProvider(worldDir);
        JFrame frame = new JFrame("Map Viewer");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        final TiledImageViewer viewer = new TiledImageViewer(true, Math.max(Runtime.getRuntime().availableProcessors() - 1, 1), true);
        viewer.setTileProvider(tileProvider);
        viewer.addMouseWheelListener(e -> {
            int zoom = viewer.getZoom();
            zoom -= e.getWheelRotation();
            // System.out.println("Setting zoom to " + zoom);
            viewer.setZoom(zoom);
        });
        frame.getContentPane().add(viewer, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}
Also used : MinecraftMapTileProvider(org.pepsoft.minecraft.MinecraftMapTileProvider) TiledImageViewer(org.pepsoft.util.swing.TiledImageViewer) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) TileProvider(org.pepsoft.util.swing.TileProvider) MinecraftMapTileProvider(org.pepsoft.minecraft.MinecraftMapTileProvider)

Aggregations

File (java.io.File)1 FileFilter (javax.swing.filechooser.FileFilter)1 MinecraftMapTileProvider (org.pepsoft.minecraft.MinecraftMapTileProvider)1 TileProvider (org.pepsoft.util.swing.TileProvider)1 TiledImageViewer (org.pepsoft.util.swing.TiledImageViewer)1