mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-13 11:16:05 +00:00
Implement structure storage format (to be moved to Gaea in the future)
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package com.dfsek.terra.image;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraChunkGenerator;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.WorldConfig;
|
||||
import com.dfsek.terra.config.genconfig.BiomeConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -29,17 +31,22 @@ public class DebugFrame extends JFrame implements ActionListener {
|
||||
public void paint(Graphics g) {
|
||||
super.paintComponents(g);
|
||||
for(Player p : Bukkit.getOnlinePlayers()) {
|
||||
int xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX(), x)/x)*getWidth());
|
||||
int zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ(), z)/z)*getHeight());
|
||||
if(! (p.getWorld().getGenerator() instanceof TerraChunkGenerator)) break;
|
||||
int xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth());
|
||||
int zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ(), z) / z) * getHeight());
|
||||
if(WorldConfig.fromWorld(p.getWorld()).imageLoader.getAlign().equals(ImageLoader.Align.CENTER)) {
|
||||
xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX() - (img.getWidth() / 2), x) / x) * getWidth());
|
||||
zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ() - (img.getHeight() / 2), z) / z) * getHeight());
|
||||
}
|
||||
String str = BiomeConfig.fromBiome((UserDefinedBiome) TerraBiomeGrid.fromWorld(p.getWorld()).getBiome(p.getLocation())).getID();
|
||||
g.setColor(new Color(255, 255, 255, 128));
|
||||
g.fillRect(xp+13, zp-13, (int) (8 + 8.25*str.length()), 33);
|
||||
g.fillRect(xp + 13, zp - 13, (int) (8 + 8.25 * str.length()), 33);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawString(p.getName(), xp+15, zp);
|
||||
g.drawString(str, xp+15, zp+15);
|
||||
g.drawString(p.getName(), xp + 15, zp);
|
||||
g.drawString(str, xp + 15, zp + 15);
|
||||
g.fillOval(xp, zp, 10, 10);
|
||||
g.setColor(Color.RED);
|
||||
g.fillOval(xp+3, zp+3, 5, 5);
|
||||
g.fillOval(xp + 3, zp + 3, 5, 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,20 +18,17 @@ import javax.imageio.ImageIO;
|
||||
|
||||
public class ImageLoader {
|
||||
private final BufferedImage image;
|
||||
private final Align align;
|
||||
double inverseRoot2 = 0.7071067811865475;
|
||||
public ImageLoader(File file) throws IOException {
|
||||
public ImageLoader(File file, Align align) throws IOException {
|
||||
image = ImageIO.read(file);
|
||||
this.align = align;
|
||||
}
|
||||
|
||||
|
||||
public int getChannel(int x, int y, Channel channel) {
|
||||
int rgb;
|
||||
try {
|
||||
rgb = image.getRGB(Math.floorMod(x, image.getWidth()), Math.floorMod(y, image.getHeight()));
|
||||
} catch(ArrayIndexOutOfBoundsException e) {
|
||||
e.printStackTrace();
|
||||
throw new IllegalArgumentException("Index " + x + "/" + x + "out of bounds for size " + image.getWidth() + "/" + image.getHeight());
|
||||
}
|
||||
rgb = align.getRGB(image, x, y);
|
||||
switch(channel) {
|
||||
case RED: return rgb >> 16 & 0xff;
|
||||
case GREEN: return rgb >> 8 & 0xff;
|
||||
@@ -63,7 +60,7 @@ public class ImageLoader {
|
||||
public double getNoiseVal(int x, int y, Channel channel) {
|
||||
return ((double) (getChannel(x, y, channel) - 128)/128)*inverseRoot2;
|
||||
}
|
||||
private static BufferedImage copyImage(BufferedImage source){
|
||||
private static BufferedImage copyImage(BufferedImage source) {
|
||||
BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
|
||||
Graphics g = b.getGraphics();
|
||||
g.drawImage(source, 0, 0, null);
|
||||
@@ -71,7 +68,29 @@ public class ImageLoader {
|
||||
return b;
|
||||
}
|
||||
|
||||
public Align getAlign() {
|
||||
return align;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
},
|
||||
NONE {
|
||||
@Override
|
||||
public int getRGB(BufferedImage image, int x, int y) {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user