use of org.pepsoft.worldpainter.ColourScheme in project WorldPainter by Captain-Chaos.
the class WPObjectRenderer method main.
public static void main(String[] args) throws IOException {
WPObject object = Bo2Object.load(new File("/home/pepijn/NetBeansProjects/Minecraft/BOBPlugins/wessex_tallredwood.bo2"));
// WPObject object = new WPObject() {
// public Point3i getDimensions() {
// return new Point3i(3, 3, 1);
// }
//
// public Point3i getOrigin() {
// return new Point3i(1, 1, 0);
// }
//
// public int getBlockID(int x, int y, int z) {
// // if (x == 2 - y) {
// return Constants.BLK_STONE;
// // } else {
// // return Constants.BLK_AIR;
// // }
// }
//
// public int getData(int x, int y, int z) {
// return 0;
// }
//
// public boolean getMask(int x, int y, int z) {
// // return (x == 2 - y);
// return true;
// }
// };
ColourScheme colourScheme = new DynMapColourScheme("default", true);
WPObjectRenderer renderer = new WPObjectRenderer(object, colourScheme, 10);
BufferedImage image = renderer.render();
ImageIcon icon = new ImageIcon(image);
JLabel label = new JLabel(icon);
JFrame frame = new JFrame("WPObjectRenderer Test");
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
use of org.pepsoft.worldpainter.ColourScheme in project WorldPainter by Captain-Chaos.
the class Mapper method main.
public static void main(String[] args) throws IOException, InterruptedException {
File worldDir = null;
int dim = 0;
String colourSchemeName = "classic";
File output = null;
for (int i = 0; i < args.length; i++) {
String arg = args[i].trim();
switch(arg) {
case "-d":
if (i < args.length - 1) {
i++;
try {
dim = Integer.parseInt(args[i].trim());
} catch (NumberFormatException e) {
error("Invalid argument to -d option: \"" + args[i] + "\"");
}
} else {
error("Missing argument to -d option");
}
break;
case "-c":
if (i < args.length - 1) {
i++;
colourSchemeName = args[i].trim();
} else {
error("Missing argument to -c option");
}
break;
case "-o":
if (i < args.length - 1) {
i++;
String outputName = args[i].trim();
if (!outputName.toLowerCase().endsWith(".png")) {
error("Only PNG format suppored for output file");
}
output = new File(outputName);
if (output.getParentFile() != null) {
if (!output.isDirectory()) {
error("Parent directory of output file does not exist or is not a directory: \"" + output.getParentFile() + "\"");
} else if (!output.canWrite()) {
error("Parent directory of output file is not writeable: \"" + output.getParentFile() + "\"");
}
}
} else {
error("Missing argument to -o option");
}
break;
default:
if (worldDir != null) {
error("Unrecognised option: \"" + arg + "\"");
} else {
worldDir = new File(arg);
}
break;
}
}
if (worldDir == null) {
error("Map directory not specified");
} else if (!worldDir.isDirectory()) {
error("Map directory does not exist or is not a directory: \"" + worldDir + "\"");
}
if ((dim < 0) || (dim > 2)) {
error("Invalid dimension specified: " + dim);
}
System.out.println("WorldPainter Mapper tool - version " + Version.VERSION + " - © 2012 - 2014 pepsoft.org");
ColourScheme colourScheme = new DynMapColourScheme(colourSchemeName, true);
if (output == null) {
output = new File(worldDir.getName().toLowerCase() + ".png");
}
map(worldDir, dim, colourScheme, output);
}
use of org.pepsoft.worldpainter.ColourScheme in project WorldPainter by Captain-Chaos.
the class Mapper method map.
private static void map(final File worldDir, final int dim, final ColourScheme colourScheme, File output) throws IOException, InterruptedException {
File levelDatFile = new File(worldDir, "level.dat");
Level level = Level.load(levelDatFile);
final Platform platform = level.getVersion() == SUPPORTED_VERSION_1 ? DefaultPlugin.JAVA_MCREGION : DefaultPlugin.JAVA_ANVIL;
maxHeight = level.getMaxHeight();
File dimensionDir;
switch(dim) {
case 0:
dimensionDir = worldDir;
break;
case 1:
dimensionDir = new File(worldDir, "DIM-1");
break;
case 2:
dimensionDir = new File(worldDir, "DIM1");
break;
default:
throw new IllegalArgumentException(Integer.toString(dim));
}
final File regionDir = new File(dimensionDir, "region");
if (!regionDir.exists()) {
error("Map does not have dimension " + dim);
}
System.out.println("Mapping " + worldDir);
System.out.println("Name: " + level.getName());
System.out.println("Seed: " + level.getSeed());
if (level.getGeneratorName() != null) {
System.out.println("Generator: " + level.getGeneratorName() + " (version " + level.getGeneratorVersion() + ")");
}
System.out.println("Map height: " + maxHeight);
System.out.println("Storage format: " + (platform.equals(DefaultPlugin.JAVA_MCREGION) ? "McRegion (Minecraft 1.1 or earlier)" : "Anvil (Minecraft 1.2 or later)"));
// Determine size
File[] regionFiles = regionDir.listFiles(platform.equals(DefaultPlugin.JAVA_MCREGION) ? (dir, name) -> name.toLowerCase().endsWith(".mcr") : (FilenameFilter) (dir, name) -> name.toLowerCase().endsWith(".mca"));
int tmpLowestRegionX = Integer.MAX_VALUE, tmpHighestRegionX = Integer.MIN_VALUE;
int tmpLowestRegionZ = Integer.MAX_VALUE, tmpHighestRegionZ = Integer.MIN_VALUE;
for (File regionFile : regionFiles) {
String[] parts = regionFile.getName().split("\\.");
int regionX = Integer.parseInt(parts[1]);
int regionZ = Integer.parseInt(parts[2]);
if (regionX < tmpLowestRegionX) {
tmpLowestRegionX = regionX;
}
if (regionX > tmpHighestRegionX) {
tmpHighestRegionX = regionX;
}
if (regionZ < tmpLowestRegionZ) {
tmpLowestRegionZ = regionZ;
}
if (regionZ > tmpHighestRegionZ) {
tmpHighestRegionZ = regionZ;
}
}
final int lowestRegionX = tmpLowestRegionX, highestRegionX = tmpHighestRegionX;
final int lowestRegionZ = tmpLowestRegionZ, highestRegionZ = tmpHighestRegionZ;
int tmpLowestChunkX = Integer.MAX_VALUE, tmpHighestChunkX = Integer.MIN_VALUE;
int tmpLowestChunkZ = Integer.MAX_VALUE, tmpHighestChunkZ = Integer.MIN_VALUE;
for (int regionX = lowestRegionX; regionX <= highestRegionX; regionX++) {
File file = new File(regionDir, "r." + regionX + "." + lowestRegionZ + (platform.equals(DefaultPlugin.JAVA_MCREGION) ? ".mcr" : ".mca"));
if (file.exists()) {
int regionChunkX = regionX << 5;
int regionChunkZ = lowestRegionZ << 5;
RegionFile region = new RegionFile(file);
try {
for (int chunkX = 0; chunkX < 32; chunkX++) {
for (int chunkZ = 0; chunkZ < 32; chunkZ++) {
if (region.containsChunk(chunkX, chunkZ)) {
int x = regionChunkX + chunkX;
int z = regionChunkZ + chunkZ;
if (x < tmpLowestChunkX) {
tmpLowestChunkX = x;
}
if (x > tmpHighestChunkX) {
tmpHighestChunkX = x;
}
if (z < tmpLowestChunkZ) {
tmpLowestChunkZ = z;
}
if (z > tmpHighestChunkZ) {
tmpHighestChunkZ = z;
}
}
}
}
} finally {
region.close();
}
}
file = new File(regionDir, "r." + regionX + "." + highestRegionZ + (platform.equals(DefaultPlugin.JAVA_MCREGION) ? ".mcr" : ".mca"));
if (file.exists()) {
int regionChunkX = regionX << 5;
int regionChunkZ = highestRegionZ << 5;
RegionFile region = new RegionFile(file);
try {
for (int chunkX = 0; chunkX < 32; chunkX++) {
for (int chunkZ = 0; chunkZ < 32; chunkZ++) {
if (region.containsChunk(chunkX, chunkZ)) {
int x = regionChunkX + chunkX;
int z = regionChunkZ + chunkZ;
if (x < tmpLowestChunkX) {
tmpLowestChunkX = x;
}
if (x > tmpHighestChunkX) {
tmpHighestChunkX = x;
}
if (z < tmpLowestChunkZ) {
tmpLowestChunkZ = z;
}
if (z > tmpHighestChunkZ) {
tmpHighestChunkZ = z;
}
}
}
}
} finally {
region.close();
}
}
}
for (int regionZ = lowestRegionZ + 1; regionZ <= highestRegionZ - 1; regionZ++) {
File file = new File(regionDir, "r." + lowestRegionX + "." + regionZ + (platform.equals(DefaultPlugin.JAVA_MCREGION) ? ".mcr" : ".mca"));
if (file.exists()) {
int regionChunkX = lowestRegionX << 5;
int regionChunkZ = regionZ << 5;
RegionFile region = new RegionFile(file);
try {
for (int chunkX = 0; chunkX < 32; chunkX++) {
for (int chunkZ = 0; chunkZ < 32; chunkZ++) {
if (region.containsChunk(chunkX, chunkZ)) {
int x = regionChunkX + chunkX;
int z = regionChunkZ + chunkZ;
if (x < tmpLowestChunkX) {
tmpLowestChunkX = x;
}
if (x > tmpHighestChunkX) {
tmpHighestChunkX = x;
}
if (z < tmpLowestChunkZ) {
tmpLowestChunkZ = z;
}
if (z > tmpHighestChunkZ) {
tmpHighestChunkZ = z;
}
}
}
}
} finally {
region.close();
}
}
file = new File(regionDir, "r." + highestRegionX + "." + regionZ + (platform.equals(DefaultPlugin.JAVA_MCREGION) ? ".mcr" : ".mca"));
if (file.exists()) {
int regionChunkX = highestRegionX << 5;
int regionChunkZ = regionZ << 5;
RegionFile region = new RegionFile(file);
try {
for (int chunkX = 0; chunkX < 32; chunkX++) {
for (int chunkZ = 0; chunkZ < 32; chunkZ++) {
if (region.containsChunk(chunkX, chunkZ)) {
int x = regionChunkX + chunkX;
int z = regionChunkZ + chunkZ;
if (x < tmpLowestChunkX) {
tmpLowestChunkX = x;
}
if (x > tmpHighestChunkX) {
tmpHighestChunkX = x;
}
if (z < tmpLowestChunkZ) {
tmpLowestChunkZ = z;
}
if (z > tmpHighestChunkZ) {
tmpHighestChunkZ = z;
}
}
}
}
} finally {
region.close();
}
}
}
final int lowestChunkX = tmpLowestChunkX;
final int lowestChunkZ = tmpLowestChunkZ;
int widthChunks = (tmpHighestChunkX - tmpLowestChunkX + 1);
int heightChunks = (tmpHighestChunkZ - tmpLowestChunkZ + 1);
System.out.println("Width: " + (widthChunks << 4));
System.out.println("Height: " + (heightChunks << 4));
final BufferedImage image = new BufferedImage(widthChunks << 4, heightChunks << 4, BufferedImage.TYPE_INT_ARGB);
final int imageOffsetX = lowestChunkX << 4;
final int imageOffsetY = lowestChunkZ << 4;
final int waterColour = colourScheme.getColour(Material.WATER);
final int lavaColour = colourScheme.getColour(Material.LAVA);
final int snowColour = colourScheme.getColour(Material.SNOW);
int threads = Runtime.getRuntime().availableProcessors();
System.out.print("Mapping");
ExecutorService executorService = Executors.newFixedThreadPool(threads);
for (File file : regionFiles) {
final File finalFile = file;
executorService.submit(() -> {
try {
String[] parts = finalFile.getName().split("\\.");
int regionX = Integer.parseInt(parts[1]);
int regionY = Integer.parseInt(parts[2]);
WorldRegion world = new WorldRegion(worldDir, dim, regionX, regionY, maxHeight, platform);
int[][] heightCache = new int[544][544];
for (int i = 0; i < 544; i++) {
Arrays.fill(heightCache[i], -1);
}
for (int chunkX = 0; chunkX < 32; chunkX++) {
for (int chunkY = 0; chunkY < 32; chunkY++) {
int worldChunkX = (regionX << 5) | chunkX;
int worldChunkY = (regionY << 5) | chunkY;
if (world.isChunkPresent(worldChunkX, worldChunkY)) {
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
int worldX = (worldChunkX << 4) | x;
int worldY = (worldChunkY << 4) | y;
boolean snow = false, water = false, lava = false;
int waterLevel = 0;
for (int height = maxHeight - 1; height >= 0; height--) {
int blockType = world.getBlockTypeAt(worldX, worldY, height);
if (blockType != BLK_AIR) {
if (blockType == BLK_SNOW) {
snow = true;
} else if ((blockType == BLK_STATIONARY_WATER) || (blockType == BLK_WATER) || (blockType == BLK_STATIONARY_LAVA) || (blockType == BLK_LAVA)) {
if ((world.getDataAt(worldX, worldY, height) == 0) && (waterLevel == 0)) {
waterLevel = height;
if ((blockType == BLK_LAVA) || (blockType == BLK_STATIONARY_LAVA)) {
lava = true;
} else {
water = true;
}
}
} else if (TERRAIN_BLOCKS.contains(blockType)) {
// Terrain found
int data = world.getDataAt(worldX, worldY, height);
int depth = waterLevel - height;
int fluidAlpha = 0xff >> Math.min(depth, 3);
int colour = colourScheme.getColour(blockType, data);
if (depth > 0) {
colour = ColourUtils.multiply(colour, getBrightenAmount(world, heightCache, ((chunkX + 1) << 4) | x, ((chunkY + 1) << 4) | y, regionX, regionY));
}
if (water) {
colour = ColourUtils.mix(colour, waterColour, fluidAlpha);
} else if (lava) {
colour = ColourUtils.mix(colour, lavaColour, fluidAlpha);
}
if (snow) {
colour = ColourUtils.mix(colour, snowColour, 64);
}
if (depth <= 0) {
colour = ColourUtils.multiply(colour, getBrightenAmount(world, heightCache, ((chunkX + 1) << 4) | x, ((chunkY + 1) << 4) | y, regionX, regionY));
}
image.setRGB(worldX - imageOffsetX, worldY - imageOffsetY, 0xff000000 | colour);
break;
} else {
// Non-terrain block found (not shaded)
int data = world.getDataAt(worldX, worldY, height);
int depth = waterLevel - height;
int fluidAlpha = 0xff >> Math.min(depth, 3);
int colour = colourScheme.getColour(blockType, data);
if (water) {
colour = ColourUtils.mix(colour, waterColour, fluidAlpha);
} else if (lava) {
colour = ColourUtils.mix(colour, lavaColour, fluidAlpha);
}
if (snow) {
colour = ColourUtils.mix(colour, snowColour);
}
image.setRGB(worldX - imageOffsetX, worldY - imageOffsetY, 0xff000000 | colour);
break;
}
}
}
}
}
}
}
}
System.out.print('.');
System.out.flush();
} catch (Throwable t) {
t.printStackTrace();
System.exit(1);
}
});
}
executorService.shutdown();
executorService.awaitTermination(1, TimeUnit.DAYS);
System.out.println();
// Save image
System.out.println("Saving image to " + output + "...");
ImageIO.write(image, "PNG", output);
System.out.println("Finished");
}
use of org.pepsoft.worldpainter.ColourScheme in project WorldPainter by Captain-Chaos.
the class CombinedLayerEditor method setContext.
@Override
public void setContext(LayerEditorContext context) {
super.setContext(context);
CustomBiomeManager customBiomeManager = context.getCustomBiomeManager();
ColourScheme colourScheme = context.getColourScheme();
comboBoxTerrain.setRenderer(new TerrainListCellRenderer(colourScheme, "none"));
comboBoxBiome.setRenderer(new BiomeListCellRenderer(colourScheme, customBiomeManager, "none"));
List<Integer> allBiomes = new ArrayList<>();
allBiomes.add(-1);
for (int i = 0; i < Minecraft1_7Biomes.BIOME_NAMES.length; i++) {
if (Minecraft1_7Biomes.BIOME_NAMES[i] != null) {
allBiomes.add(i);
}
}
List<CustomBiome> customBiomes = customBiomeManager.getCustomBiomes();
if (customBiomes != null) {
allBiomes.addAll(customBiomes.stream().map(CustomBiome::getId).collect(Collectors.toList()));
}
comboBoxBiome.setModel(new DefaultComboBoxModel(allBiomes.toArray()));
allLayers = context.getAllLayers();
}
use of org.pepsoft.worldpainter.ColourScheme in project WorldPainter by Captain-Chaos.
the class BiomesPanel method initComponents.
private void initComponents(ColourScheme colourScheme) {
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
label1.setHorizontalTextPosition(JLabel.LEADING);
label1.setAlignmentX(0.0f);
add(label1);
label2.setAlignmentX(0.0f);
add(label2);
for (final int biome : BIOME_ORDER) {
if (biome != -1) {
final JToggleButton button = new JToggleButton(new ImageIcon(BiomeSchemeManager.createImage(BIOME_SCHEME, biome, colourScheme)));
button.putClientProperty(KEY_BIOME, biome);
button.setMargin(App.BUTTON_INSETS);
StringBuilder tooltip = new StringBuilder();
tooltip.append(AutoBiomeScheme.BIOME_NAMES[biome]);
tooltip.append(" (");
List<Integer> variantIds = findVariants(biome);
boolean first = true;
for (Integer variantId : variantIds) {
if (first) {
first = false;
} else {
tooltip.append(", ");
}
tooltip.append(variantId);
}
tooltip.append(')');
button.setToolTipText(tooltip.toString());
buttonGroup.add(button);
button.addActionListener(e -> {
if (button.isSelected()) {
selectBaseBiome(biome);
}
});
grid.add(button);
} else {
grid.add(new JLabel());
}
}
JButton addCustomBiomeButton = new JButton(IconUtils.loadScaledIcon("org/pepsoft/worldpainter/icons/plus.png"));
addCustomBiomeButton.setMargin(App.BUTTON_INSETS);
addCustomBiomeButton.setToolTipText("Add a custom biome");
addCustomBiomeButton.addActionListener(e -> {
final Window parent = SwingUtilities.getWindowAncestor(BiomesPanel.this);
final int id = customBiomeManager.getNextId();
if (id == -1) {
JOptionPane.showMessageDialog(parent, "Maximum number of custom biomes reached", "Maximum Reached", JOptionPane.ERROR_MESSAGE);
return;
}
CustomBiome customBiome = new CustomBiome("Custom", id, Color.ORANGE.getRGB());
CustomBiomeDialog dialog = new CustomBiomeDialog(parent, customBiome, true);
dialog.setVisible(true);
if (!dialog.isCancelled()) {
customBiomeManager.addCustomBiome(parent, customBiome);
}
});
grid.add(addCustomBiomeButton);
grid.setAlignmentX(0.0f);
add(grid);
checkBoxHillsShore.setEnabled(false);
checkBoxEdgePlateau.setEnabled(false);
checkBoxM.setEnabled(false);
checkBoxF.setEnabled(false);
checkBoxVariant.setEnabled(false);
ActionListener optionActionListener = e -> updateOptions();
checkBoxHillsShore.addActionListener(optionActionListener);
checkBoxEdgePlateau.addActionListener(optionActionListener);
checkBoxM.addActionListener(optionActionListener);
checkBoxF.addActionListener(optionActionListener);
checkBoxVariant.addActionListener(optionActionListener);
add(checkBoxHillsShore);
checkBoxEdgePlateau.setAlignmentX(0.0f);
add(checkBoxEdgePlateau);
JPanel lowerRowPanel = new JPanel();
lowerRowPanel.setLayout(new BoxLayout(lowerRowPanel, BoxLayout.LINE_AXIS));
lowerRowPanel.add(checkBoxM);
lowerRowPanel.add(checkBoxF);
lowerRowPanel.add(checkBoxVariant);
lowerRowPanel.setAlignmentX(0.0f);
add(lowerRowPanel);
}
Aggregations