mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-17 05:40:16 +00:00
Clean up imports
This commit is contained in:
@@ -8,18 +8,17 @@ import com.dfsek.terra.debug.gui.DebugGUI;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.NormalizationUtil;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class ImageLoader {
|
||||
private final BufferedImage image;
|
||||
private final Align align;
|
||||
double inverseRoot2 = 0.7071067811865475;
|
||||
|
||||
public ImageLoader(File file, Align align) throws IOException {
|
||||
image = ImageIO.read(file);
|
||||
this.align = align;
|
||||
@@ -30,21 +29,27 @@ public class ImageLoader {
|
||||
int rgb;
|
||||
rgb = align.getRGB(image, x, y);
|
||||
switch(channel) {
|
||||
case RED: return rgb >> 16 & 0xff;
|
||||
case GREEN: return rgb >> 8 & 0xff;
|
||||
case BLUE: return rgb & 0xff;
|
||||
case ALPHA: return rgb >> 32 & 0xff;
|
||||
default: throw new IllegalArgumentException();
|
||||
case RED:
|
||||
return rgb >> 16 & 0xff;
|
||||
case GREEN:
|
||||
return rgb >> 8 & 0xff;
|
||||
case BLUE:
|
||||
return rgb & 0xff;
|
||||
case ALPHA:
|
||||
return rgb >> 32 & 0xff;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void debugWorld(boolean genStep, World w) {
|
||||
if(!ConfigUtil.debug) return;
|
||||
if(! ConfigUtil.debug) return;
|
||||
BufferedImage newImg = new WorldImageGenerator(w, 1024, 1024).drawWorld(0, 0).getDraw();
|
||||
if(genStep) newImg = redrawStepped(newImg, w, Align.CENTER);
|
||||
DebugGUI debugGUI = new DebugGUI(newImg);
|
||||
debugGUI.start();
|
||||
}
|
||||
|
||||
private static BufferedImage redrawStepped(BufferedImage original, World w, Align align) {
|
||||
BufferedImage newImg = copyImage(original);
|
||||
TerraBiomeGrid tb = TerraWorld.getWorld(w).getGrid();
|
||||
@@ -52,7 +57,8 @@ public class ImageLoader {
|
||||
for(int x = 0; x < newImg.getWidth(); x++) {
|
||||
for(int y = 0; y < newImg.getHeight(); y++) {
|
||||
float[] noise;
|
||||
if(align.equals(Align.CENTER)) noise = tb.getGrid(x - original.getWidth()/2, y - original.getHeight()/2).getRawNoise(x - original.getWidth()/2, y - original.getHeight()/2);
|
||||
if(align.equals(Align.CENTER))
|
||||
noise = tb.getGrid(x - original.getWidth() / 2, y - original.getHeight() / 2).getRawNoise(x - original.getWidth() / 2, y - original.getHeight() / 2);
|
||||
else noise = tb.getGrid(x, y).getRawNoise(x, y);
|
||||
newImg.setRGB(x, y, new Color((int) (NormalizationUtil.normalize(noise[0], tb.getGrid(x, y).getSizeX(), 4) * ((double) 255 / tb.getGrid(x, y).getSizeX())),
|
||||
(int) (NormalizationUtil.normalize(noise[1], tb.getGrid(x, y).getSizeZ(), 4) * ((double) 255 / tb.getGrid(x, y).getSizeZ())),
|
||||
@@ -64,7 +70,7 @@ public class ImageLoader {
|
||||
}
|
||||
|
||||
public void debug(boolean genStep, World w) {
|
||||
if(!ConfigUtil.debug) return;
|
||||
if(! ConfigUtil.debug) return;
|
||||
BufferedImage newImg = copyImage(image);
|
||||
if(genStep) {
|
||||
newImg = redrawStepped(image, w, align);
|
||||
@@ -74,8 +80,9 @@ public class ImageLoader {
|
||||
}
|
||||
|
||||
public double getNoiseVal(int x, int y, Channel channel) {
|
||||
return ((double) (getChannel(x, y, channel) - 128)/128)*inverseRoot2;
|
||||
return ((double) (getChannel(x, y, channel) - 128) / 128) * inverseRoot2;
|
||||
}
|
||||
|
||||
private static BufferedImage copyImage(BufferedImage source) {
|
||||
BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
|
||||
Graphics g = b.getGraphics();
|
||||
@@ -91,11 +98,12 @@ public class ImageLoader {
|
||||
public enum Channel {
|
||||
RED, GREEN, BLUE, ALPHA
|
||||
}
|
||||
|
||||
public enum Align {
|
||||
CENTER {
|
||||
@Override
|
||||
public int getRGB(BufferedImage image, int x, int y) {
|
||||
return Align.getRGBNoAlign(image, x-(image.getWidth()/2), y-(image.getHeight()/2));
|
||||
return Align.getRGBNoAlign(image, x - (image.getWidth() / 2), y - (image.getHeight() / 2));
|
||||
}
|
||||
},
|
||||
NONE {
|
||||
@@ -104,7 +112,9 @@ public class ImageLoader {
|
||||
return image.getRGB(Math.floorMod(x, image.getWidth()), Math.floorMod(y, image.getHeight()));
|
||||
}
|
||||
};
|
||||
|
||||
public abstract int getRGB(BufferedImage image, int x, int y);
|
||||
|
||||
private static int getRGBNoAlign(BufferedImage image, int x, int y) {
|
||||
return image.getRGB(Math.floorMod(x, image.getWidth()), Math.floorMod(y, image.getHeight()));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.dfsek.terra.image;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.NormalizationUtil;
|
||||
|
||||
@@ -16,17 +14,19 @@ import java.io.IOException;
|
||||
public class WorldImageGenerator {
|
||||
private final World w;
|
||||
private final BufferedImage draw;
|
||||
|
||||
public WorldImageGenerator(World w, int width, int height) {
|
||||
draw = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
public WorldImageGenerator drawWorld(int centerX, int centerZ) {
|
||||
TerraWorld tw = TerraWorld.getWorld(w);
|
||||
TerraBiomeGrid tb = tw.getGrid();
|
||||
int imY = 0;
|
||||
for(int y = centerZ - (draw.getHeight()/2); y < centerZ + (draw.getHeight()/2); y++) {
|
||||
for(int y = centerZ - (draw.getHeight() / 2); y < centerZ + (draw.getHeight() / 2); y++) {
|
||||
int imX = 0;
|
||||
for(int x = centerX - (draw.getWidth()/2); x < centerX + (draw.getWidth()/2); x++) {
|
||||
for(int x = centerX - (draw.getWidth() / 2); x < centerX + (draw.getWidth() / 2); x++) {
|
||||
int zone = NormalizationUtil.normalize(tw.getZone().getRawNoise(x, y), 256, 4);
|
||||
float[] noise = tb.getGrid(x, y).getRawNoise(x, y);
|
||||
Color c = new Color(NormalizationUtil.normalize(noise[0], 256, 4), NormalizationUtil.normalize(noise[1], 256, 4), zone);
|
||||
|
||||
Reference in New Issue
Block a user