mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Finalize commands, add to GUI
This commit is contained in:
parent
f7f98b6dcc
commit
efd52a2002
@ -43,6 +43,10 @@ public class BiomeZone {
|
||||
return grids[NormalizationUtil.normalize(useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z), grids.length)];
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return grids.length;
|
||||
}
|
||||
|
||||
public int getNoise(int x, int z) {
|
||||
return NormalizationUtil.normalize(useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z), grids.length);
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.dfsek.terra.command.image.gui;
|
||||
|
||||
import com.dfsek.terra.command.WorldCommand;
|
||||
import com.dfsek.terra.config.ConfigUtil;
|
||||
import com.dfsek.terra.config.WorldConfig;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -13,7 +15,13 @@ import java.util.List;
|
||||
public class RawGUICommand extends WorldCommand {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
WorldConfig.fromWorld(world).imageLoader.debug(false, sender.getWorld());
|
||||
if(! ConfigUtil.debug) {
|
||||
sender.sendMessage("Debug mode must be enabled to use the debug GUI! The debug GUI is NOT PRODUCTION SAFE!");
|
||||
return true;
|
||||
}
|
||||
ImageLoader loader = WorldConfig.fromWorld(world).imageLoader;
|
||||
if(loader != null) loader.debug(false, sender.getWorld());
|
||||
else ImageLoader.debugWorld(false, world);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.dfsek.terra.command.image.gui;
|
||||
|
||||
import com.dfsek.terra.command.WorldCommand;
|
||||
import com.dfsek.terra.config.ConfigUtil;
|
||||
import com.dfsek.terra.config.WorldConfig;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -13,7 +15,13 @@ import java.util.List;
|
||||
public class StepGUICommand extends WorldCommand {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
WorldConfig.fromWorld(world).imageLoader.debug(true, sender.getWorld());
|
||||
if(! ConfigUtil.debug) {
|
||||
sender.sendMessage("Debug mode must be enabled to use the debug GUI! The debug GUI is NOT PRODUCTION SAFE!");
|
||||
return true;
|
||||
}
|
||||
ImageLoader loader = WorldConfig.fromWorld(world).imageLoader;
|
||||
if(loader != null) loader.debug(true, sender.getWorld());
|
||||
else ImageLoader.debugWorld(true, world);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -32,11 +32,12 @@ public class DebugFrame extends JFrame implements ActionListener {
|
||||
super.paintComponents(g);
|
||||
for(Player p : Bukkit.getOnlinePlayers()) {
|
||||
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());
|
||||
int xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX() - (img.getWidth() / 2), x) / x) * getWidth());
|
||||
int zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ() - (img.getHeight() / 2), z) / z) * getHeight());
|
||||
ImageLoader loader = WorldConfig.fromWorld(p.getWorld()).imageLoader;
|
||||
if(loader != null && loader.getAlign().equals(ImageLoader.Align.NONE)) {
|
||||
xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth());
|
||||
zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ(), z) / z) * getHeight());
|
||||
}
|
||||
String str = BiomeConfig.fromBiome((UserDefinedBiome) TerraBiomeGrid.fromWorld(p.getWorld()).getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID();
|
||||
g.setColor(new Color(255, 255, 255, 128));
|
||||
|
@ -2,7 +2,9 @@ package com.dfsek.terra.image;
|
||||
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.ConfigUtil;
|
||||
import com.dfsek.terra.config.genconfig.BiomeConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.NormalizationUtil;
|
||||
|
||||
@ -38,20 +40,36 @@ public class ImageLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public void debug(boolean genStep, World w) {
|
||||
BufferedImage newImg = copyImage(image);
|
||||
public static void debugWorld(boolean genStep, World w) {
|
||||
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 = TerraBiomeGrid.fromWorld(w);
|
||||
BiomeZone z = BiomeZone.fromWorld(w);
|
||||
if(genStep) {
|
||||
for(int x = 0; x < newImg.getWidth(); x++) {
|
||||
for(int y = 0; y < newImg.getHeight(); y++) {
|
||||
float[] noise = tb.getGrid(x, y).getRawNoise(x, y);
|
||||
newImg.setRGB(x, y, new Color((int) (NormalizationUtil.normalize(noise[0], tb.getGrid(x, y).getSizeX()) * ((double) 255/tb.getGrid(x, y).getSizeX())),
|
||||
(int) (NormalizationUtil.normalize(noise[1], tb.getGrid(x, y).getSizeZ()) * ((double) 255/tb.getGrid(x, y).getSizeZ())),
|
||||
(int) (z.getNoise(x, y) * ((double) 255/32)))
|
||||
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);
|
||||
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()) * ((double) 255 / tb.getGrid(x, y).getSizeX())),
|
||||
(int) (NormalizationUtil.normalize(noise[1], tb.getGrid(x, y).getSizeZ()) * ((double) 255 / tb.getGrid(x, y).getSizeZ())),
|
||||
(int) (NormalizationUtil.normalize(z.getNoise(x, y), z.getSize()) * ((double) 255 / z.getSize())))
|
||||
.getRGB());
|
||||
}
|
||||
}
|
||||
return newImg;
|
||||
}
|
||||
|
||||
public void debug(boolean genStep, World w) {
|
||||
if(!ConfigUtil.debug) return;
|
||||
BufferedImage newImg = copyImage(image);
|
||||
if(genStep) {
|
||||
newImg = redrawStepped(image, w, align);
|
||||
}
|
||||
DebugGUI debugGUI = new DebugGUI(newImg);
|
||||
debugGUI.start();
|
||||
|
@ -19,7 +19,7 @@ public class WorldImageGenerator {
|
||||
draw = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
this.w = w;
|
||||
}
|
||||
public void drawWorld(int centerX, int centerZ) {
|
||||
public WorldImageGenerator drawWorld(int centerX, int centerZ) {
|
||||
TerraBiomeGrid tb = TerraBiomeGrid.fromWorld(w);
|
||||
int imY = 0;
|
||||
for(int y = centerZ - (draw.getHeight()/2); y < centerZ + (draw.getHeight()/2); y++) {
|
||||
@ -33,7 +33,13 @@ public class WorldImageGenerator {
|
||||
}
|
||||
imY++;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public BufferedImage getDraw() {
|
||||
return draw;
|
||||
}
|
||||
|
||||
public void save(File file) {
|
||||
try {
|
||||
ImageIO.write(draw, "png", file);
|
||||
|
Loading…
x
Reference in New Issue
Block a user