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)];
|
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) {
|
public int getNoise(int x, int z) {
|
||||||
return NormalizationUtil.normalize(useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z), grids.length);
|
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;
|
package com.dfsek.terra.command.image.gui;
|
||||||
|
|
||||||
import com.dfsek.terra.command.WorldCommand;
|
import com.dfsek.terra.command.WorldCommand;
|
||||||
|
import com.dfsek.terra.config.ConfigUtil;
|
||||||
import com.dfsek.terra.config.WorldConfig;
|
import com.dfsek.terra.config.WorldConfig;
|
||||||
|
import com.dfsek.terra.image.ImageLoader;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -13,7 +15,13 @@ import java.util.List;
|
|||||||
public class RawGUICommand extends WorldCommand {
|
public class RawGUICommand extends WorldCommand {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.dfsek.terra.command.image.gui;
|
package com.dfsek.terra.command.image.gui;
|
||||||
|
|
||||||
import com.dfsek.terra.command.WorldCommand;
|
import com.dfsek.terra.command.WorldCommand;
|
||||||
|
import com.dfsek.terra.config.ConfigUtil;
|
||||||
import com.dfsek.terra.config.WorldConfig;
|
import com.dfsek.terra.config.WorldConfig;
|
||||||
|
import com.dfsek.terra.image.ImageLoader;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -13,7 +15,13 @@ import java.util.List;
|
|||||||
public class StepGUICommand extends WorldCommand {
|
public class StepGUICommand extends WorldCommand {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,11 +32,12 @@ public class DebugFrame extends JFrame implements ActionListener {
|
|||||||
super.paintComponents(g);
|
super.paintComponents(g);
|
||||||
for(Player p : Bukkit.getOnlinePlayers()) {
|
for(Player p : Bukkit.getOnlinePlayers()) {
|
||||||
if(! (p.getWorld().getGenerator() instanceof TerraChunkGenerator)) break;
|
if(! (p.getWorld().getGenerator() instanceof TerraChunkGenerator)) break;
|
||||||
int xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth());
|
int xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX() - (img.getWidth() / 2), x) / x) * getWidth());
|
||||||
int zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ(), z) / z) * getHeight());
|
int zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ() - (img.getHeight() / 2), z) / z) * getHeight());
|
||||||
if(WorldConfig.fromWorld(p.getWorld()).imageLoader.getAlign().equals(ImageLoader.Align.CENTER)) {
|
ImageLoader loader = WorldConfig.fromWorld(p.getWorld()).imageLoader;
|
||||||
xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX() - (img.getWidth() / 2), x) / x) * getWidth());
|
if(loader != null && loader.getAlign().equals(ImageLoader.Align.NONE)) {
|
||||||
zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ() - (img.getHeight() / 2), z) / z) * getHeight());
|
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();
|
String str = BiomeConfig.fromBiome((UserDefinedBiome) TerraBiomeGrid.fromWorld(p.getWorld()).getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID();
|
||||||
g.setColor(new Color(255, 255, 255, 128));
|
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.BiomeZone;
|
||||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||||
|
import com.dfsek.terra.config.ConfigUtil;
|
||||||
import com.dfsek.terra.config.genconfig.BiomeConfig;
|
import com.dfsek.terra.config.genconfig.BiomeConfig;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.polydev.gaea.biome.NormalizationUtil;
|
import org.polydev.gaea.biome.NormalizationUtil;
|
||||||
|
|
||||||
@ -38,20 +40,36 @@ public class ImageLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(boolean genStep, World w) {
|
public static void debugWorld(boolean genStep, World w) {
|
||||||
BufferedImage newImg = copyImage(image);
|
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);
|
TerraBiomeGrid tb = TerraBiomeGrid.fromWorld(w);
|
||||||
BiomeZone z = BiomeZone.fromWorld(w);
|
BiomeZone z = BiomeZone.fromWorld(w);
|
||||||
if(genStep) {
|
|
||||||
for(int x = 0; x < newImg.getWidth(); x++) {
|
for(int x = 0; x < newImg.getWidth(); x++) {
|
||||||
for(int y = 0; y < newImg.getHeight(); y++) {
|
for(int y = 0; y < newImg.getHeight(); y++) {
|
||||||
float[] noise = tb.getGrid(x, y).getRawNoise(x, 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);
|
||||||
|
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())),
|
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(noise[1], tb.getGrid(x, y).getSizeZ()) * ((double) 255 / tb.getGrid(x, y).getSizeZ())),
|
||||||
(int) (z.getNoise(x, y) * ((double) 255/32)))
|
(int) (NormalizationUtil.normalize(z.getNoise(x, y), z.getSize()) * ((double) 255 / z.getSize())))
|
||||||
.getRGB());
|
.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 debugGUI = new DebugGUI(newImg);
|
||||||
debugGUI.start();
|
debugGUI.start();
|
||||||
|
@ -19,7 +19,7 @@ public class WorldImageGenerator {
|
|||||||
draw = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
draw = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||||
this.w = w;
|
this.w = w;
|
||||||
}
|
}
|
||||||
public void drawWorld(int centerX, int centerZ) {
|
public WorldImageGenerator drawWorld(int centerX, int centerZ) {
|
||||||
TerraBiomeGrid tb = TerraBiomeGrid.fromWorld(w);
|
TerraBiomeGrid tb = TerraBiomeGrid.fromWorld(w);
|
||||||
int imY = 0;
|
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++) {
|
||||||
@ -33,7 +33,13 @@ public class WorldImageGenerator {
|
|||||||
}
|
}
|
||||||
imY++;
|
imY++;
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BufferedImage getDraw() {
|
||||||
|
return draw;
|
||||||
|
}
|
||||||
|
|
||||||
public void save(File file) {
|
public void save(File file) {
|
||||||
try {
|
try {
|
||||||
ImageIO.write(draw, "png", file);
|
ImageIO.write(draw, "png", file);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user