Search in sources :

Example 1 with BiomeScheme

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

the class BiomeSchemeManager method getBiomeScheme.

public static BiomeScheme getBiomeScheme(final int biomeAlgorithm, final boolean shared) {
    if (logger.isTraceEnabled()) {
        logger.trace("Thread {} requesting biome scheme {}", Thread.currentThread().getName(), biomeAlgorithm, new Throwable("Invoked from"));
    }
    synchronized (initialisationLock) {
        if (!initialised) {
            initialise();
        }
    }
    if (shared && BIOME_SCHEMES.containsKey(biomeAlgorithm)) {
        // this algorithm, so reuse it
        return BIOME_SCHEMES.get(biomeAlgorithm);
    } else {
        final String version;
        switch(biomeAlgorithm) {
            case BIOME_ALGORITHM_1_1:
                version = "1.1";
                break;
            case BIOME_ALGORITHM_1_2_AND_1_3_DEFAULT:
                version = "1.6.4 or 1.2.3 - 1.6.2";
                break;
            case BIOME_ALGORITHM_1_3_LARGE:
                version = "1.6.4 or 1.3.1 - 1.6.2";
                break;
            case BIOME_ALGORITHM_1_7_DEFAULT:
                version = "1.12.2 or 1.7.2 - 1.10.2";
                break;
            case BIOME_ALGORITHM_1_7_LARGE:
                version = "1.12.2 or 1.7.2 - 1.10.2";
                break;
            default:
                throw new IllegalArgumentException();
        }
        SortedMap<Version, BiomeJar> biomeJars = BIOME_JARS.get(biomeAlgorithm);
        if ((biomeJars != null) && (!biomeJars.isEmpty())) {
            // We have a jar for this biome scheme
            final BiomeJar biomeJar = biomeJars.get(biomeJars.lastKey());
            logger.info("Creating biome scheme " + version + " from " + biomeJar.file.getAbsolutePath());
            BiomeScheme biomeScheme = biomeJar.descriptor.instantiate(biomeJar.file, minecraftDir, biomeJar.checksum);
            if (shared) {
                BIOME_SCHEMES.put(biomeAlgorithm, biomeScheme);
            }
            return biomeScheme;
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find compatible jar for biome scheme " + version);
            }
            return null;
        }
    }
}
Also used : Version(org.pepsoft.util.Version) BiomeScheme(org.pepsoft.worldpainter.BiomeScheme)

Example 2 with BiomeScheme

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

the class LargeContinentFinder 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> largeContinentWorlds = new TreeSet<>();
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            largeContinentWorlds.forEach(System.out::println);
        }
    });
    while (true) {
        // System.out.println("***");
        // System.out.println("*** Seed " + seed + " ***");
        // System.out.println("***");
        // System.out.print('.');
        biomeScheme.setSeed(seed);
        int continentTilesFound = visitTilesInSpiral((x, z) -> {
            // System.out.println("Visiting " + x + ", " + z);
            biomeScheme.getBiomes(x * TILE_SIZE, z * TILE_SIZE, TILE_SIZE, TILE_SIZE, biomes);
            for (int biome : biomes) {
                if ((biome == BIOME_OCEAN) || (biome == BIOME_DEEP_OCEAN)) {
                    return false;
                }
            }
            return true;
        });
        if (largeContinentWorlds.isEmpty() || (continentTilesFound > largeContinentWorlds.first().continentTiles)) {
            if (largeContinentWorlds.size() > 100) {
                largeContinentWorlds.remove(largeContinentWorlds.first());
            }
            largeContinentWorlds.add(new World(seed, continentTilesFound));
        }
        seed++;
        if ((seed % 100L) == 0) {
            System.out.println("Results after " + seed + " seeds:");
            for (World world : largeContinentWorlds) {
                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 3 with BiomeScheme

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

the class BiomesTileProvider method paintTile.

@Override
public boolean paintTile(Image image, int tileX, int tileY, int imageX, int imageY) {
    if (!enabled) {
        return false;
    }
    try {
        BiomeScheme biomeScheme = getBiomeScheme();
        if (biomeScheme == null) {
            return false;
        }
        final int scale = 1 << -zoom;
        int[] buffer = bufferRef.get();
        if (buffer == null) {
            buffer = new int[TILE_SIZE * TILE_SIZE * scale * scale];
            bufferRef.set(buffer);
        }
        biomeScheme.getBiomes(tileX * TILE_SIZE * scale, tileY * TILE_SIZE * scale, TILE_SIZE * scale, TILE_SIZE * scale, buffer);
        BufferedImage tile = renderBufferRef.get();
        int[][] biomeCounts = biomeCountsRef.get();
        if (biomeCounts == null) {
            biomeCounts = new int[][] { new int[256], new int[256], new int[256] };
            biomeCountsRef.set(biomeCounts);
        }
        for (int x = 0; x < TILE_SIZE; x++) {
            for (int y = 0; y < TILE_SIZE; y++) {
                for (int i = 0; i < 3; i++) {
                    for (int j = 0; j < biomeCounts[i].length; j++) {
                        biomeCounts[i][j] = 0;
                    }
                }
                for (int dx = 0; dx < scale; dx++) {
                    for (int dz = 0; dz < scale; dz++) {
                        int biome = buffer[x * scale + dx + (y * scale + dz) * TILE_SIZE * scale];
                        biomeCounts[BIOME_PRIORITIES[biome]][biome]++;
                    }
                }
                int mostCommonBiome = -1;
                for (int i = 2; i >= 0; i--) {
                    int mostCommonBiomeCount = 0;
                    for (int j = 0; j < biomeCounts[i].length; j++) {
                        if (biomeCounts[i][j] > mostCommonBiomeCount) {
                            mostCommonBiome = j;
                            mostCommonBiomeCount = biomeCounts[i][j];
                        }
                    }
                    if (mostCommonBiome != -1) {
                        break;
                    }
                }
                if ((biomePatterns[mostCommonBiome] != null) && (biomePatterns[mostCommonBiome][x % 16][y % 16])) {
                    tile.setRGB(x, y, patternColour);
                } else {
                    tile.setRGB(x, y, biomeColours[mostCommonBiome]);
                }
            }
        }
        Graphics2D g2 = (Graphics2D) image.getGraphics();
        try {
            g2.drawImage(tile, imageX, imageY, null);
        } finally {
            g2.dispose();
        }
    } catch (Throwable t) {
        logger.error("Exception while generating image for tile at {}, {}", tileX, tileY, t);
    }
    return true;
}
Also used : BiomeScheme(org.pepsoft.worldpainter.BiomeScheme) BufferedImage(java.awt.image.BufferedImage)

Example 4 with BiomeScheme

use of org.pepsoft.worldpainter.BiomeScheme 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)

Aggregations

BiomeScheme (org.pepsoft.worldpainter.BiomeScheme)4 TreeSet (java.util.TreeSet)2 Configuration (org.pepsoft.worldpainter.Configuration)2 Minecraft1_7BiomeScheme (org.pepsoft.worldpainter.biomeschemes.Minecraft1_7BiomeScheme)2 BufferedImage (java.awt.image.BufferedImage)1 Version (org.pepsoft.util.Version)1