Search in sources :

Example 11 with Configuration

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

the class LargeOceanFinder method main.

public static void main(String[] args) throws IOException, ClassNotFoundException {
    Configuration config = Configuration.load();
    if (config == null) {
        config = new Configuration();
    }
    Configuration.setInstance(config);
    final BiomeScheme biomeScheme = BiomeSchemeManager.getSharedBiomeScheme(BIOME_ALGORITHM_1_7_LARGE);
    if (biomeScheme == null) {
        System.err.println("Can't continue without a Minecraft 1.7 - 1.10 minecraft.jar");
        System.exit(1);
    }
    long seed = 0;
    final int[] biomes = new int[TILE_SIZE * TILE_SIZE];
    final SortedSet<World> largeOceanWorlds = new TreeSet<>();
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            largeOceanWorlds.forEach(System.out::println);
        }
    });
    while (true) {
        // System.out.println("***");
        // System.out.println("*** Seed " + seed + " ***");
        // System.out.println("***");
        // System.out.print('.');
        biomeScheme.setSeed(seed);
        final int[] oceanTilesFound = new int[] { 0 };
        int oceanOrMushroomTilesFound = visitTilesInSpiral(new TileVisitor() {

            @Override
            public boolean visitBlock(int x, int z) {
                // System.out.println("Visiting " + x + ", " + z);
                biomeScheme.getBiomes(x * TILE_SIZE, z * TILE_SIZE, TILE_SIZE, TILE_SIZE, biomes);
                boolean mushroomTile = false;
                for (int biome : biomes) {
                    if ((biome == BIOME_MUSHROOM_ISLAND_SHORE) || (biome == BIOME_MUSHROOM_ISLAND)) {
                        mushroomTile = true;
                    } else if ((biome != BIOME_OCEAN) && (biome != BIOME_DEEP_OCEAN)) {
                        return false;
                    }
                }
                if (mushroomTile) {
                    mushroomTileFound = true;
                } else if (!mushroomTileFound) {
                    oceanTilesFound[0]++;
                }
                return true;
            }

            private boolean mushroomTileFound;
        });
        if (largeOceanWorlds.isEmpty() || (oceanOrMushroomTilesFound > largeOceanWorlds.first().oceanOrMushroomTiles)) {
            if (largeOceanWorlds.size() > 100) {
                largeOceanWorlds.remove(largeOceanWorlds.first());
            }
            largeOceanWorlds.add(new World(seed, oceanTilesFound[0], oceanOrMushroomTilesFound));
        }
        seed++;
        if ((seed % 10000L) == 0) {
            System.out.println("Results after " + seed + " seeds:");
            for (World world : largeOceanWorlds) {
                System.out.println("    " + world);
            }
        }
    }
}
Also used : Configuration(org.pepsoft.worldpainter.Configuration) TreeSet(java.util.TreeSet) BiomeScheme(org.pepsoft.worldpainter.BiomeScheme) Minecraft1_7BiomeScheme(org.pepsoft.worldpainter.biomeschemes.Minecraft1_7BiomeScheme)

Example 12 with Configuration

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

the class Bo2LayerEditor method addFilesOrDirectory.

private void addFilesOrDirectory() {
    // Can't use FileUtils.selectFilesForOpen() because it doesn't support
    // selecting directories, or adding custom components to the dialog
    JFileChooser fileChooser = new JFileChooser();
    Configuration config = Configuration.getInstance();
    if ((config.getCustomObjectsDirectory() != null) && config.getCustomObjectsDirectory().isDirectory()) {
        fileChooser.setCurrentDirectory(config.getCustomObjectsDirectory());
    }
    fileChooser.setDialogTitle("Select File(s) or Directory");
    fileChooser.setMultiSelectionEnabled(true);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    CustomObjectManager customObjectManager = CustomObjectManager.getInstance();
    CustomObjectManager.UniversalFileFilter fileFilter = customObjectManager.getFileFilter();
    fileChooser.setFileFilter(fileFilter);
    WPObjectPreviewer previewer = new WPObjectPreviewer();
    previewer.setDimension(App.getInstance().getDimension());
    fileChooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, previewer);
    fileChooser.setAccessory(previewer);
    if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File[] selectedFiles = fileChooser.getSelectedFiles();
        if (selectedFiles.length > 0) {
            config.setCustomObjectsDirectory(selectedFiles[0].getParentFile());
            for (File selectedFile : selectedFiles) {
                if (selectedFile.isDirectory()) {
                    if (fieldName.getText().isEmpty()) {
                        String name = selectedFiles[0].getName();
                        if (name.length() > 12) {
                            name = "..." + name.substring(name.length() - 10);
                        }
                        fieldName.setText(name);
                    }
                    File[] files = selectedFile.listFiles((FilenameFilter) fileFilter);
                    // noinspection ConstantConditions // Cannot happen as we already checked selectedFile is an extant directory
                    if (files.length == 0) {
                        JOptionPane.showMessageDialog(this, "Directory " + selectedFile.getName() + " does not contain any supported custom object files.", "No Custom Object Files", JOptionPane.ERROR_MESSAGE);
                    } else {
                        for (File file : files) {
                            try {
                                listModel.addElement(customObjectManager.loadObject(file));
                            } catch (IOException e) {
                                logger.error("I/O error while trying to load custom object " + file, e);
                                JOptionPane.showMessageDialog(this, "I/O error while loading " + file.getName() + "; it was not added", "I/O Error", JOptionPane.ERROR_MESSAGE);
                            }
                        }
                    }
                } else {
                    if (fieldName.getText().isEmpty()) {
                        String name = selectedFile.getName();
                        int p = name.lastIndexOf('.');
                        if (p != -1) {
                            name = name.substring(0, p);
                        }
                        if (name.length() > 12) {
                            name = "..." + name.substring(name.length() - 10);
                        }
                        fieldName.setText(name);
                    }
                    try {
                        listModel.addElement(customObjectManager.loadObject(selectedFile));
                    } catch (IOException e) {
                        logger.error("I/O error while trying to load custom object " + selectedFile, e);
                        JOptionPane.showMessageDialog(this, "I/O error while loading " + selectedFile.getName() + "; it was not added", "I/O Error", JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
            settingsChanged();
            refreshLeafDecaySettings();
        }
    }
}
Also used : Configuration(org.pepsoft.worldpainter.Configuration) CustomObjectManager(org.pepsoft.worldpainter.plugins.CustomObjectManager) IOException(java.io.IOException) File(java.io.File)

Aggregations

Configuration (org.pepsoft.worldpainter.Configuration)12 File (java.io.File)7 IOException (java.io.IOException)4 CertificateException (java.security.cert.CertificateException)2 CertificateFactory (java.security.cert.CertificateFactory)2 X509Certificate (java.security.cert.X509Certificate)2 TreeSet (java.util.TreeSet)2 BiomeScheme (org.pepsoft.worldpainter.BiomeScheme)2 Minecraft1_7BiomeScheme (org.pepsoft.worldpainter.biomeschemes.Minecraft1_7BiomeScheme)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 MouseEvent (java.awt.event.MouseEvent)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SecureRandom (java.security.SecureRandom)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1