mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
rework image stuff
This commit is contained in:
parent
308ba887a3
commit
28b6fe49bb
@ -1,6 +1,6 @@
|
|||||||
package com.dfsek.terra.api.math;
|
package com.dfsek.terra.api.math;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||||
import com.dfsek.terra.api.world.biome.NormalizationUtil;
|
import com.dfsek.terra.api.world.biome.NormalizationUtil;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -35,7 +35,7 @@ public class ProbabilityCollection<E> {
|
|||||||
return (E) array[r.nextInt(array.length)];
|
return (E) array[r.nextInt(array.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public E get(FastNoiseLite n, double x, double z) {
|
public E get(NoiseSampler n, double x, double z) {
|
||||||
if(array.length == 0) return null;
|
if(array.length == 0) return null;
|
||||||
return (E) array[NormalizationUtil.normalize(n.getNoise(x, z), array.length, 1)];
|
return (E) array[NormalizationUtil.normalize(n.getNoise(x, z), array.length, 1)];
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.dfsek.terra.api.math.noise;
|
package com.dfsek.terra.api.math.noise;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||||
import com.dfsek.terra.util.hash.HashMapDoubleDouble;
|
import com.dfsek.terra.util.hash.HashMapDoubleDouble;
|
||||||
import parsii.eval.Expression;
|
import parsii.eval.Expression;
|
||||||
@ -7,7 +8,7 @@ import parsii.eval.Expression;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NoiseFunction2 implements NoiseFunction {
|
public class NoiseFunction2 implements NoiseFunction {
|
||||||
private final FastNoiseLite gen;
|
private final NoiseSampler gen;
|
||||||
private final Cache cache = new Cache();
|
private final Cache cache = new Cache();
|
||||||
|
|
||||||
public NoiseFunction2(long seed, NoiseBuilder builder) {
|
public NoiseFunction2(long seed, NoiseBuilder builder) {
|
||||||
@ -43,7 +44,7 @@ public class NoiseFunction2 implements NoiseFunction {
|
|||||||
private static final long serialVersionUID = 8915092734723467010L;
|
private static final long serialVersionUID = 8915092734723467010L;
|
||||||
private static final int cacheSize = 384;
|
private static final int cacheSize = 384;
|
||||||
|
|
||||||
public double get(FastNoiseLite noise, double x, double z) {
|
public double get(NoiseSampler noise, double x, double z) {
|
||||||
double xx = x >= 0 ? x * 2 : x * -2 - 1;
|
double xx = x >= 0 ? x * 2 : x * -2 - 1;
|
||||||
double zz = z >= 0 ? z * 2 : z * -2 - 1;
|
double zz = z >= 0 ? z * 2 : z * -2 - 1;
|
||||||
double key = (xx >= zz) ? (xx * xx + xx + zz) : (zz * zz + xx);
|
double key = (xx >= zz) ? (xx * xx + xx + zz) : (zz * zz + xx);
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package com.dfsek.terra.api.math.noise;
|
package com.dfsek.terra.api.math.noise;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||||
import parsii.eval.Expression;
|
import parsii.eval.Expression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NoiseFunction3 implements NoiseFunction {
|
public class NoiseFunction3 implements NoiseFunction {
|
||||||
private final FastNoiseLite gen;
|
private final NoiseSampler gen;
|
||||||
|
|
||||||
public NoiseFunction3(long seed, NoiseBuilder builder) {
|
public NoiseFunction3(long seed, NoiseBuilder builder) {
|
||||||
this.gen = builder.build((int) seed);
|
this.gen = builder.build((int) seed);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
|
|||||||
|
package com.dfsek.terra.api.math.noise.samplers;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.math.vector.Vector2;
|
||||||
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
|
|
||||||
|
public interface NoiseSampler {
|
||||||
|
/**
|
||||||
|
* 2D noise at given position using current settings
|
||||||
|
* <p>
|
||||||
|
* Noise output bounded between -1...1
|
||||||
|
*/
|
||||||
|
double getNoise(/*FNLdouble*/ double x, /*FNLdouble*/ double y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 3D noise at given position using current settings
|
||||||
|
* <p>
|
||||||
|
* Noise output bounded between -1...1
|
||||||
|
*/
|
||||||
|
double getNoise(/*FNLdouble*/ double x, /*FNLdouble*/ double y, /*FNLdouble*/ double z);
|
||||||
|
|
||||||
|
default double getNoise(Vector3 vector3) {
|
||||||
|
return getNoise(vector3.getX(), vector3.getY(), vector3.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
default double getNoise(Vector2 vector2) {
|
||||||
|
return getNoise(vector2.getX(), vector2.getZ());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.dfsek.terra.api.math.noise.samplers;
|
||||||
|
|
||||||
|
public abstract class Normalizer implements NoiseSampler {
|
||||||
|
private final NoiseSampler sampler;
|
||||||
|
|
||||||
|
protected Normalizer(NoiseSampler sampler) {
|
||||||
|
this.sampler = sampler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract double normalize(double in);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getNoise(double x, double y) {
|
||||||
|
return normalize(sampler.getNoise(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getNoise(double x, double y, double z) {
|
||||||
|
return normalize(sampler.getNoise(x, y, z));
|
||||||
|
}
|
||||||
|
}
|
@ -172,6 +172,12 @@ public class Vector2 implements Cloneable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector2 add(double x, double z) {
|
||||||
|
this.x += x;
|
||||||
|
this.z += z;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "(" + x + ", " + z + ")";
|
return "(" + x + ", " + z + ")";
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.dfsek.terra.api.math.voxel;
|
package com.dfsek.terra.api.math.voxel;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||||
import com.dfsek.terra.api.math.vector.Vector3;
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
|
|
||||||
public class DeformedSphere extends VoxelGeometry {
|
public class DeformedSphere extends VoxelGeometry {
|
||||||
public DeformedSphere(Vector3 start, int rad, double deform, FastNoiseLite noise) {
|
public DeformedSphere(Vector3 start, int rad, double deform, NoiseSampler noise) {
|
||||||
for(int x = -rad; x <= rad; x++) {
|
for(int x = -rad; x <= rad; x++) {
|
||||||
for(int y = -rad; y <= rad; y++) {
|
for(int y = -rad; y <= rad; y++) {
|
||||||
for(int z = -rad; z <= rad; z++) {
|
for(int z = -rad; z <= rad; z++) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.dfsek.terra.api.world.biome;
|
package com.dfsek.terra.api.world.biome;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||||
import com.dfsek.terra.api.math.vector.Location;
|
import com.dfsek.terra.api.math.vector.Location;
|
||||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.dfsek.terra.api.world.palette;
|
package com.dfsek.terra.api.world.palette;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||||
import com.dfsek.terra.api.util.GlueList;
|
import com.dfsek.terra.api.util.GlueList;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -104,7 +104,7 @@ public abstract class Palette<E> {
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public E get(FastNoiseLite random, int x, int z) {
|
public E get(NoiseSampler random, int x, int z) {
|
||||||
if(col) return this.collection.get(random, x, z);
|
if(col) return this.collection.get(random, x, z);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package com.dfsek.terra.api.world.palette;
|
package com.dfsek.terra.api.world.palette;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SimplexPalette<E> extends Palette<E> {
|
public class SimplexPalette<E> extends Palette<E> {
|
||||||
private final FastNoiseLite r;
|
private final NoiseSampler r;
|
||||||
|
|
||||||
public SimplexPalette(FastNoiseLite r) {
|
public SimplexPalette(NoiseSampler r) {
|
||||||
this.r = r;
|
this.r = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.dfsek.terra.biome;
|
package com.dfsek.terra.biome;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||||
import com.dfsek.terra.api.world.biome.BiomeGrid;
|
import com.dfsek.terra.api.world.biome.BiomeGrid;
|
||||||
import com.dfsek.terra.api.world.biome.NormalizationUtil;
|
import com.dfsek.terra.api.world.biome.NormalizationUtil;
|
||||||
import com.dfsek.terra.config.base.ConfigPack;
|
import com.dfsek.terra.config.base.ConfigPack;
|
||||||
@ -42,7 +42,7 @@ public class BiomeZone {
|
|||||||
* @return BiomeGrid at coordinates.
|
* @return BiomeGrid at coordinates.
|
||||||
*/
|
*/
|
||||||
public BiomeGrid getGrid(int x, int z) {
|
public BiomeGrid getGrid(int x, int z) {
|
||||||
return grids[NormalizationUtil.normalize(useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z), grids.length, 4)];
|
return grids[getNoise(x, z)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,7 +62,7 @@ public class BiomeZone {
|
|||||||
* @return Normalized noise at coordinates
|
* @return Normalized noise at coordinates
|
||||||
*/
|
*/
|
||||||
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, 4);
|
return useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, getSize() - 1, channel) : NormalizationUtil.normalize(noise.getNoise(x, z), grids.length, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,6 +73,6 @@ public class BiomeZone {
|
|||||||
* @return Raw noise at coordinates
|
* @return Raw noise at coordinates
|
||||||
*/
|
*/
|
||||||
public double getRawNoise(int x, int z) {
|
public double getRawNoise(int x, int z) {
|
||||||
return useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z);
|
return useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, getSize() - 1, channel) : noise.getNoise(x, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package com.dfsek.terra.biome.grid;
|
|||||||
import com.dfsek.terra.api.math.vector.Location;
|
import com.dfsek.terra.api.math.vector.Location;
|
||||||
import com.dfsek.terra.api.world.biome.Biome;
|
import com.dfsek.terra.api.world.biome.Biome;
|
||||||
import com.dfsek.terra.api.world.biome.BiomeGrid;
|
import com.dfsek.terra.api.world.biome.BiomeGrid;
|
||||||
import com.dfsek.terra.api.world.biome.NormalizationUtil;
|
|
||||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||||
import com.dfsek.terra.config.base.ConfigPack;
|
import com.dfsek.terra.config.base.ConfigPack;
|
||||||
import com.dfsek.terra.config.base.ConfigPackTemplate;
|
import com.dfsek.terra.config.base.ConfigPackTemplate;
|
||||||
@ -28,9 +27,9 @@ public class UserDefinedGrid extends BiomeGrid {
|
|||||||
@Override
|
@Override
|
||||||
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
||||||
if(fromImage) {
|
if(fromImage) {
|
||||||
double xi = imageLoader.getNoiseVal(x, z, channelX);
|
int xi = imageLoader.getNoiseVal(x, z, getSizeX() - 1, channelX);
|
||||||
double zi = imageLoader.getNoiseVal(x, z, channelZ);
|
int zi = imageLoader.getNoiseVal(x, z, getSizeZ() - 1, channelZ);
|
||||||
return super.getGrid()[NormalizationUtil.normalize(xi, getSizeX(), 4)][NormalizationUtil.normalize(zi, getSizeZ(), 4)];
|
return super.getGrid()[xi][zi];
|
||||||
}
|
}
|
||||||
return super.getBiome(x, z, phase);
|
return super.getBiome(x, z, phase);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.dfsek.terra.biome.postprocessing;
|
package com.dfsek.terra.biome.postprocessing;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||||
import com.dfsek.terra.api.math.vector.Vector2;
|
import com.dfsek.terra.api.math.vector.Vector2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.dfsek.terra.biome.postprocessing;
|
package com.dfsek.terra.biome.postprocessing;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||||
|
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||||
import net.jafama.FastMath;
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,7 +9,7 @@ import net.jafama.FastMath;
|
|||||||
*/
|
*/
|
||||||
public class ErosionNoise {
|
public class ErosionNoise {
|
||||||
private final double thresh;
|
private final double thresh;
|
||||||
private final FastNoiseLite noise;
|
private final NoiseSampler noise;
|
||||||
|
|
||||||
public ErosionNoise(double freq1, double thresh, int octaves, long seed) {
|
public ErosionNoise(double freq1, double thresh, int octaves, long seed) {
|
||||||
FastNoiseLite main = new FastNoiseLite((int) (seed + 1));
|
FastNoiseLite main = new FastNoiseLite((int) (seed + 1));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.dfsek.terra.config.factories;
|
package com.dfsek.terra.config.factories;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||||
import com.dfsek.terra.api.platform.block.BlockData;
|
import com.dfsek.terra.api.platform.block.BlockData;
|
||||||
import com.dfsek.terra.api.util.FastRandom;
|
import com.dfsek.terra.api.util.FastRandom;
|
||||||
|
@ -5,7 +5,7 @@ import com.dfsek.tectonic.loading.ConfigLoader;
|
|||||||
import com.dfsek.tectonic.loading.TypeLoader;
|
import com.dfsek.tectonic.loading.TypeLoader;
|
||||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||||
import com.dfsek.terra.api.math.Range;
|
import com.dfsek.terra.api.math.Range;
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||||
import com.dfsek.terra.api.world.flora.Flora;
|
import com.dfsek.terra.api.world.flora.Flora;
|
||||||
import com.dfsek.terra.config.loaders.Types;
|
import com.dfsek.terra.config.loaders.Types;
|
||||||
import com.dfsek.terra.population.items.flora.FloraLayer;
|
import com.dfsek.terra.population.items.flora.FloraLayer;
|
||||||
|
@ -5,7 +5,7 @@ import com.dfsek.tectonic.exception.ConfigException;
|
|||||||
import com.dfsek.tectonic.exception.LoadException;
|
import com.dfsek.tectonic.exception.LoadException;
|
||||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||||
import com.dfsek.tectonic.loading.TypeLoader;
|
import com.dfsek.tectonic.loading.TypeLoader;
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
@ -5,7 +5,7 @@ import com.dfsek.tectonic.loading.ConfigLoader;
|
|||||||
import com.dfsek.tectonic.loading.TypeLoader;
|
import com.dfsek.tectonic.loading.TypeLoader;
|
||||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||||
import com.dfsek.terra.api.math.Range;
|
import com.dfsek.terra.api.math.Range;
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||||
import com.dfsek.terra.api.world.tree.Tree;
|
import com.dfsek.terra.api.world.tree.Tree;
|
||||||
import com.dfsek.terra.config.loaders.Types;
|
import com.dfsek.terra.config.loaders.Types;
|
||||||
import com.dfsek.terra.population.items.tree.TreeLayer;
|
import com.dfsek.terra.population.items.tree.TreeLayer;
|
||||||
|
@ -3,7 +3,8 @@ package com.dfsek.terra.generation.config;
|
|||||||
import com.dfsek.tectonic.annotations.Default;
|
import com.dfsek.tectonic.annotations.Default;
|
||||||
import com.dfsek.tectonic.annotations.Value;
|
import com.dfsek.tectonic.annotations.Value;
|
||||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||||
|
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||||
|
|
||||||
public class NoiseBuilder implements ConfigTemplate {
|
public class NoiseBuilder implements ConfigTemplate {
|
||||||
@Value("type")
|
@Value("type")
|
||||||
@ -70,7 +71,7 @@ public class NoiseBuilder implements ConfigTemplate {
|
|||||||
@Default
|
@Default
|
||||||
private int dimensions = 2;
|
private int dimensions = 2;
|
||||||
|
|
||||||
public FastNoiseLite build(int seed) {
|
public NoiseSampler build(int seed) {
|
||||||
FastNoiseLite noise = new FastNoiseLite(seed + seedOffset);
|
FastNoiseLite noise = new FastNoiseLite(seed + seedOffset);
|
||||||
if(!fractalType.equals(FastNoiseLite.FractalType.None)) {
|
if(!fractalType.equals(FastNoiseLite.FractalType.None)) {
|
||||||
noise.setFractalType(fractalType);
|
noise.setFractalType(fractalType);
|
||||||
|
@ -15,7 +15,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class ImageLoader {
|
public class ImageLoader {
|
||||||
private static final double INVERSE_ROOT_2 = 0.7071067811865475;
|
|
||||||
private final BufferedImage image;
|
private final BufferedImage image;
|
||||||
private final Align align;
|
private final Align align;
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ public class ImageLoader {
|
|||||||
private static BufferedImage redrawStepped(BufferedImage original, World w, Align align, TerraPlugin main) {
|
private static BufferedImage redrawStepped(BufferedImage original, World w, Align align, TerraPlugin main) {
|
||||||
BufferedImage newImg = copyImage(original);
|
BufferedImage newImg = copyImage(original);
|
||||||
TerraBiomeGrid tb = main.getWorld(w).getGrid();
|
TerraBiomeGrid tb = main.getWorld(w).getGrid();
|
||||||
BiomeZone z = main.getWorld(w).getZone();
|
BiomeZone zone = main.getWorld(w).getZone();
|
||||||
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++) {
|
||||||
double[] noise;
|
double[] noise;
|
||||||
@ -44,13 +43,17 @@ public class ImageLoader {
|
|||||||
else noise = tb.getGrid(x, y).getRawNoise(x, y);
|
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())),
|
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())),
|
(int) (NormalizationUtil.normalize(noise[1], tb.getGrid(x, y).getSizeZ(), 4) * ((double) 255 / tb.getGrid(x, y).getSizeZ())),
|
||||||
(int) (NormalizationUtil.normalize(z.getNoise(x, y), z.getSize(), 4) * ((double) 255 / z.getSize())))
|
(int) (NormalizationUtil.normalize(zone.getNoise(x, y), zone.getSize(), 4) * ((double) 255 / zone.getSize())))
|
||||||
.getRGB());
|
.getRGB());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newImg;
|
return newImg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int normal(double val) {
|
||||||
|
return FastMath.floorToInt(FastMath.min(FastMath.max(val, 255), 0));
|
||||||
|
}
|
||||||
|
|
||||||
private static BufferedImage copyImage(BufferedImage source) {
|
private static BufferedImage copyImage(BufferedImage source) {
|
||||||
BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
|
BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
|
||||||
Graphics g = b.getGraphics();
|
Graphics g = b.getGraphics();
|
||||||
@ -69,8 +72,8 @@ public class ImageLoader {
|
|||||||
debugGUI.start();
|
debugGUI.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getNoiseVal(int x, int y, Channel channel) {
|
public int getNoiseVal(int x, int y, int size, Channel channel) {
|
||||||
return ((double) (getChannel(x, y, channel) - 128) / 128) * INVERSE_ROOT_2;
|
return (size * getChannel(x, y, channel)) / 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getChannel(int x, int y, Channel channel) {
|
public int getChannel(int x, int y, Channel channel) {
|
||||||
|
@ -2,7 +2,7 @@ package com.dfsek.terra.population.items;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||||
import com.dfsek.terra.api.math.Range;
|
import com.dfsek.terra.api.math.Range;
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||||
import com.dfsek.terra.api.math.vector.Vector2;
|
import com.dfsek.terra.api.math.vector.Vector2;
|
||||||
import com.dfsek.terra.api.platform.world.Chunk;
|
import com.dfsek.terra.api.platform.world.Chunk;
|
||||||
|
|
||||||
@ -12,16 +12,16 @@ public abstract class PlaceableLayer<T> {
|
|||||||
protected final double density;
|
protected final double density;
|
||||||
protected final Range level;
|
protected final Range level;
|
||||||
protected final ProbabilityCollection<T> layer;
|
protected final ProbabilityCollection<T> layer;
|
||||||
protected final FastNoiseLite noise;
|
protected final NoiseSampler noise;
|
||||||
|
|
||||||
public PlaceableLayer(double density, Range level, ProbabilityCollection<T> layer, FastNoiseLite noise) {
|
public PlaceableLayer(double density, Range level, ProbabilityCollection<T> layer, NoiseSampler noise) {
|
||||||
this.density = density;
|
this.density = density;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.layer = layer;
|
this.layer = layer;
|
||||||
this.noise = noise;
|
this.noise = noise;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FastNoiseLite getNoise() {
|
public NoiseSampler getNoise() {
|
||||||
return noise;
|
return noise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package com.dfsek.terra.population.items.flora;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||||
import com.dfsek.terra.api.math.Range;
|
import com.dfsek.terra.api.math.Range;
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||||
import com.dfsek.terra.api.math.vector.Vector2;
|
import com.dfsek.terra.api.math.vector.Vector2;
|
||||||
import com.dfsek.terra.api.platform.world.Chunk;
|
import com.dfsek.terra.api.platform.world.Chunk;
|
||||||
import com.dfsek.terra.api.world.flora.Flora;
|
import com.dfsek.terra.api.world.flora.Flora;
|
||||||
@ -12,7 +12,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class FloraLayer extends PlaceableLayer<Flora> {
|
public class FloraLayer extends PlaceableLayer<Flora> {
|
||||||
|
|
||||||
public FloraLayer(double density, Range level, ProbabilityCollection<Flora> layer, FastNoiseLite noise) {
|
public FloraLayer(double density, Range level, ProbabilityCollection<Flora> layer, NoiseSampler noise) {
|
||||||
super(density, level, layer, noise);
|
super(density, level, layer, noise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.dfsek.terra.population.items.ores;
|
package com.dfsek.terra.population.items.ores;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.Range;
|
import com.dfsek.terra.api.math.Range;
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||||
import com.dfsek.terra.api.math.vector.Vector3;
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||||
import com.dfsek.terra.api.platform.block.Block;
|
import com.dfsek.terra.api.platform.block.Block;
|
||||||
|
@ -2,7 +2,7 @@ package com.dfsek.terra.population.items.tree;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||||
import com.dfsek.terra.api.math.Range;
|
import com.dfsek.terra.api.math.Range;
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||||
import com.dfsek.terra.api.math.vector.Vector2;
|
import com.dfsek.terra.api.math.vector.Vector2;
|
||||||
import com.dfsek.terra.api.platform.block.Block;
|
import com.dfsek.terra.api.platform.block.Block;
|
||||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||||
@ -14,7 +14,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class TreeLayer extends PlaceableLayer<Tree> {
|
public class TreeLayer extends PlaceableLayer<Tree> {
|
||||||
|
|
||||||
public TreeLayer(double density, Range level, ProbabilityCollection<Tree> layer, FastNoiseLite noise) {
|
public TreeLayer(double density, Range level, ProbabilityCollection<Tree> layer, NoiseSampler noise) {
|
||||||
super(density, level, layer, noise);
|
super(density, level, layer, noise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.dfsek.terra.bukkit.command.command.geometry;
|
package com.dfsek.terra.bukkit.command.command.geometry;
|
||||||
|
|
||||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||||
import com.dfsek.terra.api.math.vector.Vector3;
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
import com.dfsek.terra.api.math.voxel.DeformedSphere;
|
import com.dfsek.terra.api.math.voxel.DeformedSphere;
|
||||||
import com.dfsek.terra.bukkit.BukkitCommandSender;
|
import com.dfsek.terra.bukkit.BukkitCommandSender;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.dfsek.terra.bukkit.command.command.image.gui;
|
package com.dfsek.terra.bukkit.command.command.image.gui;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.command.DebugCommand;
|
||||||
import com.dfsek.terra.bukkit.command.WorldCommand;
|
import com.dfsek.terra.bukkit.command.WorldCommand;
|
||||||
|
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||||
|
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.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -10,23 +13,16 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RawGUICommand extends WorldCommand {
|
public class RawGUICommand extends WorldCommand implements DebugCommand {
|
||||||
public RawGUICommand(com.dfsek.terra.bukkit.command.Command parent) {
|
public RawGUICommand(com.dfsek.terra.bukkit.command.Command parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||||
/*
|
ImageLoader loader = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getTemplate().getImageLoader();
|
||||||
if(!getMain().isDebug()) {
|
if(loader != null) loader.debug(false, BukkitAdapter.adapt(sender.getWorld()), getMain());
|
||||||
LangUtil.send("command.image.gui.debug", sender);
|
else ImageLoader.debugWorld(false, BukkitAdapter.adapt(world), getMain());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
ImageLoader loader = ((TerraBukkitPlugin) getMain()).getWorld(world).getConfig().getTemplate().getImageLoader();
|
|
||||||
if(loader != null) loader.debug(false, sender.getWorld(), (TerraBukkitPlugin) getMain());
|
|
||||||
else ImageLoader.debugWorld(false, world, (TerraBukkitPlugin) getMain());
|
|
||||||
|
|
||||||
*/
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.dfsek.terra.bukkit.command.command.image.gui;
|
package com.dfsek.terra.bukkit.command.command.image.gui;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.command.DebugCommand;
|
||||||
import com.dfsek.terra.bukkit.command.WorldCommand;
|
import com.dfsek.terra.bukkit.command.WorldCommand;
|
||||||
|
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||||
|
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.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -10,23 +13,16 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StepGUICommand extends WorldCommand {
|
public class StepGUICommand extends WorldCommand implements DebugCommand {
|
||||||
public StepGUICommand(com.dfsek.terra.bukkit.command.Command parent) {
|
public StepGUICommand(com.dfsek.terra.bukkit.command.Command parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||||
/*
|
ImageLoader loader = (getMain()).getWorld(BukkitAdapter.adapt(world)).getConfig().getTemplate().getImageLoader();
|
||||||
if(!getMain().isDebug()) {
|
if(loader != null) loader.debug(true, BukkitAdapter.adapt(sender.getWorld()), getMain());
|
||||||
LangUtil.send("command.image.gui.debug", sender);
|
else ImageLoader.debugWorld(true, BukkitAdapter.adapt(world), getMain());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
ImageLoader loader = ((TerraBukkitPlugin) getMain()).getWorld(world).getConfig().getTemplate().getImageLoader();
|
|
||||||
if(loader != null) loader.debug(true, sender.getWorld(), (TerraBukkitPlugin) getMain());
|
|
||||||
else ImageLoader.debugWorld(true, world, (TerraBukkitPlugin) getMain());
|
|
||||||
|
|
||||||
*/
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user