diff --git a/common/src/main/java/com/dfsek/terra/api/math/interpolation/ChunkInterpolator3.java b/common/src/main/java/com/dfsek/terra/api/math/interpolation/ChunkInterpolator3.java index a5f3f9b9b..048e61c64 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/interpolation/ChunkInterpolator3.java +++ b/common/src/main/java/com/dfsek/terra/api/math/interpolation/ChunkInterpolator3.java @@ -15,9 +15,6 @@ public class ChunkInterpolator3 { private final Generator[][] gens = new Generator[7][7]; private final boolean[][] needsBiomeInterp = new boolean[5][5]; private final double[][][] noiseStorage = new double[7][7][65]; - private final int xOrigin; - private final int zOrigin; - private final World w; /** * Instantiates a 3D ChunkInterpolator at a pair of chunk coordinates, with a BiomeGrid and FastNoiseLite instance. @@ -27,9 +24,8 @@ public class ChunkInterpolator3 { * @param grid BiomeGrid to use for noise fetching. */ public ChunkInterpolator3(World w, int chunkX, int chunkZ, BiomeGrid grid) { - this.xOrigin = chunkX << 4; - this.zOrigin = chunkZ << 4; - this.w = w; + int xOrigin = chunkX << 4; + int zOrigin = chunkZ << 4; for(int x = -1; x < 6; x++) { @@ -39,11 +35,17 @@ public class ChunkInterpolator3 { } for(int x = 0; x < 5; x++) { for(int z = 0; z < 5; z++) { - needsBiomeInterp[x][z] = compareGens(x+1, z+1); + needsBiomeInterp[x][z] = compareGens(x + 1, z + 1); } } - storeNoise(); + for(byte x = -1; x < 6; x++) { + for(byte z = -1; z < 6; z++) { + for(int y = 0; y < 65; y++) { + noiseStorage[x + 1][z + 1][y] = gens[x + 1][z + 1].getNoise(w, (x << 2) + xOrigin, y << 2, (z << 2) + zOrigin); + } + } + } for(byte x = 0; x < 4; x++) { for(byte z = 0; z < 4; z++) { @@ -56,7 +58,7 @@ public class ChunkInterpolator3 { biomeAvg(x, y, z + 1), biomeAvg(x + 1, y, z + 1), biomeAvg(x, y + 1, z + 1), - biomeAvg(x + 1, y + 1, z + 1), gens[x+1][z+1].getInterpolationType()); + biomeAvg(x + 1, y + 1, z + 1)); } } } @@ -80,15 +82,6 @@ public class ChunkInterpolator3 { return !comp.equals(gens[x - 1][z + 1]); } - private void storeNoise() { - for(byte x = - 1; x < 6; x++) { - for(byte z = - 1; z < 6; z++) { - for(int y = 0; y < 64; y++) { - noiseStorage[x + 1][z + 1][y] = gens[x + 1][z + 1].getNoise(w, (x << 2) + xOrigin, y << 2, (z << 2) + zOrigin); - } - } - } - } private double biomeAvg(int x, int y, int z) { if(needsBiomeInterp[x][z]) return (noiseStorage[x + 2][z + 1][y] diff --git a/common/src/main/java/com/dfsek/terra/api/math/interpolation/Interpolator.java b/common/src/main/java/com/dfsek/terra/api/math/interpolation/Interpolator.java index 00466b9b9..493168981 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/interpolation/Interpolator.java +++ b/common/src/main/java/com/dfsek/terra/api/math/interpolation/Interpolator.java @@ -1,13 +1,10 @@ package com.dfsek.terra.api.math.interpolation; -import net.jafama.FastMath; - /** * Class for bilinear interpolation of values arranged on a unit square. */ public class Interpolator { private final double v0, v1, v2, v3; - private final Type type; /** * Constructs an interpolator with given values as vertices of a unit square. @@ -17,12 +14,11 @@ public class Interpolator { * @param v2 - (0,1) * @param v3 - (1,1) */ - public Interpolator(double v0, double v1, double v2, double v3, Type type) { + public Interpolator(double v0, double v1, double v2, double v3) { this.v0 = v0; this.v1 = v1; this.v2 = v2; this.v3 = v3; - this.type = type; } /** @@ -33,12 +29,9 @@ public class Interpolator { * @param v1 - Value at v1. * @return double - The interpolated value. */ - public static double lerp(double t, double v0, double v1, Type type) { - switch(type) { - case LINEAR: return v0 + t * (v1 - v0); - case NEAREST_NEIGHBOR: return FastMath.abs(v0-t) > FastMath.abs(v1-t) ? v1 : v0; - default: throw new IllegalStateException(); - } + public static double lerp(double t, double v0, double v1) { + return v0 + t * (v1 - v0); + } /** @@ -49,13 +42,8 @@ public class Interpolator { * @return double - The interpolated value. */ public double bilerp(double s, double t) { - double v01 = lerp(s, v0, v1, type); - double v23 = lerp(s, v2, v3, type); - double v = lerp(t, v01, v23, type); - return v; - } - - public enum Type { - LINEAR, NEAREST_NEIGHBOR + double v01 = lerp(s, v0, v1); + double v23 = lerp(s, v2, v3); + return lerp(t, v01, v23); } } \ No newline at end of file diff --git a/common/src/main/java/com/dfsek/terra/api/math/interpolation/Interpolator3.java b/common/src/main/java/com/dfsek/terra/api/math/interpolation/Interpolator3.java index 4ef669a59..5b54c0f9a 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/interpolation/Interpolator3.java +++ b/common/src/main/java/com/dfsek/terra/api/math/interpolation/Interpolator3.java @@ -5,7 +5,6 @@ package com.dfsek.terra.api.math.interpolation; */ public class Interpolator3 { private final double _000, _100, _010, _110, _001, _101, _011, _111; - private final Interpolator.Type type; /** * Constructs an interpolator with given values as vertices of a unit cube. @@ -20,7 +19,7 @@ public class Interpolator3 { */ public Interpolator3(double _000, double _100, double _010, double _110, double _001, double _101, - double _011, double _111, Interpolator.Type type) { + double _011, double _111) { this._000 = _000; this._001 = _001; this._010 = _010; @@ -29,12 +28,11 @@ public class Interpolator3 { this._101 = _101; this._110 = _110; this._111 = _111; - this.type = type; } public double trilerp(double x, double y, double z) { - Interpolator top = new Interpolator(_000, _010, _001, _011, type); - Interpolator bottom = new Interpolator(_100, _110, _101, _111, type); - return Interpolator.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z), type); + Interpolator top = new Interpolator(_000, _010, _001, _011); + Interpolator bottom = new Interpolator(_100, _110, _101, _111); + return Interpolator.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z)); } } \ No newline at end of file diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/Biome.java b/common/src/main/java/com/dfsek/terra/api/world/biome/Biome.java index 0bdfba763..25ad009dc 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/Biome.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/Biome.java @@ -23,13 +23,6 @@ public interface Biome { */ Generator getGenerator(); - /** - * Returns the Decorator instance containing information about the population in the biome. - * - * @return Decorator - the Decorator instance. - */ - Decorator getDecorator(); - /** * Gets the BiomeTerrain instance used to generate the biome in this world. * diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/Decorator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/Decorator.java deleted file mode 100644 index ff0bf1ab1..000000000 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/Decorator.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.dfsek.terra.api.world.biome; - -import com.dfsek.terra.api.math.ProbabilityCollection; -import com.dfsek.terra.api.world.flora.Flora; -import com.dfsek.terra.api.world.tree.Tree; - -public abstract class Decorator { - - - public abstract ProbabilityCollection getTrees(); - - public abstract int getTreeDensity(); - - public abstract boolean overrideStructureChance(); - - public abstract ProbabilityCollection getFlora(); - - public abstract int getFloraChance(); - -} diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/Generator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/Generator.java index 1dd2b7310..5f3336348 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/Generator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/Generator.java @@ -1,11 +1,10 @@ package com.dfsek.terra.api.world.biome; -import com.dfsek.terra.api.math.interpolation.Interpolator; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.world.palette.Palette; -public abstract class Generator { +public interface Generator { /** * Gets the 3D noise at a pair of coordinates using the provided FastNoiseLite instance. * @@ -14,27 +13,19 @@ public abstract class Generator { * @param z - The z coordinate. * @return double - Noise value at the specified coordinates. */ - public abstract double getNoise(World w, int x, int y, int z); + double getNoise(World w, int x, int y, int z); /** * Gets the BlocPalette to generate the biome with. * * @return BlocPalette - The biome's palette. */ - public abstract Palette getPalette(int y); + Palette getPalette(int y); /** * Returns true if the biome should be interpolated just once, false to use advanced interpolation + blending. + * * @return Whether biome should use minimal interpolation */ - public abstract boolean useMinimalInterpolation(); - - - /** - * Get the type of interpolation to use in this biome. - * @return Interpolation type - */ - public Interpolator.Type getInterpolationType() { - return Interpolator.Type.LINEAR; - } + boolean useMinimalInterpolation(); } diff --git a/common/src/main/java/com/dfsek/terra/biome/UserDefinedBiome.java b/common/src/main/java/com/dfsek/terra/biome/UserDefinedBiome.java index 4b74662e5..2be4e0ff8 100644 --- a/common/src/main/java/com/dfsek/terra/biome/UserDefinedBiome.java +++ b/common/src/main/java/com/dfsek/terra/biome/UserDefinedBiome.java @@ -2,19 +2,16 @@ package com.dfsek.terra.biome; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.world.biome.Biome; -import com.dfsek.terra.api.world.biome.Decorator; import com.dfsek.terra.api.world.biome.Generator; import com.dfsek.terra.config.base.ConfigPack; import com.dfsek.terra.config.builder.GeneratorBuilder; import com.dfsek.terra.config.templates.BiomeTemplate; -import com.dfsek.terra.generation.UserDefinedDecorator; /** * Class representing a config-defined biome */ public class UserDefinedBiome implements Biome { private final GeneratorBuilder gen; - private final UserDefinedDecorator decorator; private final com.dfsek.terra.api.platform.world.Biome vanilla; private final String id; private final BiomeTemplate config; @@ -22,9 +19,8 @@ public class UserDefinedBiome implements Biome { private UserDefinedBiome erode; - public UserDefinedBiome(com.dfsek.terra.api.platform.world.Biome vanilla, UserDefinedDecorator dec, GeneratorBuilder gen, BiomeTemplate config, ConfigPack pack) { + public UserDefinedBiome(com.dfsek.terra.api.platform.world.Biome vanilla, GeneratorBuilder gen, BiomeTemplate config, ConfigPack pack) { this.vanilla = vanilla; - this.decorator = dec; this.gen = gen; this.id = config.getID(); this.config = config; @@ -52,16 +48,6 @@ public class UserDefinedBiome implements Biome { } - /** - * Returns the Decorator instance containing information about the population in the biome. - * - * @return Decorator - the Decorator instance. - */ - @Override - public Decorator getDecorator() { - return decorator; - } - public String getID() { return id; } diff --git a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java index b06a9e0ae..b0c41c1f4 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java @@ -1,12 +1,10 @@ package com.dfsek.terra.config.factories; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.TerraPlugin; import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.config.base.ConfigPack; import com.dfsek.terra.config.builder.GeneratorBuilder; import com.dfsek.terra.config.templates.BiomeTemplate; -import com.dfsek.terra.generation.UserDefinedDecorator; public class BiomeFactory implements TerraFactory { private final ConfigPack pack; @@ -17,7 +15,6 @@ public class BiomeFactory implements TerraFactory(), new ProbabilityCollection<>(), 0, 0); GeneratorBuilder generatorBuilder = new GeneratorBuilder(); generatorBuilder.setElevationEquation(template.getElevationEquation()); generatorBuilder.setNoiseEquation(template.getNoiseEquation()); @@ -28,6 +25,6 @@ public class BiomeFactory implements TerraFactory flora; - private final ProbabilityCollection trees; - private final int floraChance; - private final int treeDensity; - - public UserDefinedDecorator(ProbabilityCollection flora, ProbabilityCollection trees, int floraChance, int treeDensity) { - this.flora = flora; - this.trees = trees; - - this.floraChance = floraChance; - this.treeDensity = treeDensity; - } - - @Override - public ProbabilityCollection getTrees() { - return trees; - } - - @Override - public int getTreeDensity() { - return treeDensity; - } - - @Override - public boolean overrideStructureChance() { - return false; - } - - @Override - public ProbabilityCollection getFlora() { - return flora; - } - - @Override - public int getFloraChance() { - return floraChance; - } -} diff --git a/common/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java b/common/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java index b05e8eb11..5c99c61d0 100644 --- a/common/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java +++ b/common/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java @@ -1,6 +1,5 @@ package com.dfsek.terra.generation.config; -import com.dfsek.terra.api.math.interpolation.Interpolator; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.world.biome.Generator; @@ -17,7 +16,7 @@ import parsii.tokenizer.ParseException; import java.util.Map; -public class WorldGenerator extends Generator { +public class WorldGenerator implements Generator { @SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"}) private final PaletteHolder palettes; @SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"}) @@ -33,7 +32,6 @@ public class WorldGenerator extends Generator { private final Variable elevationZVar; private final boolean elevationInterpolation; - @SuppressWarnings({"rawtypes", "unchecked"}) public WorldGenerator(long seed, String equation, String elevateEquation, Scope vScope, Map noiseBuilders, PaletteHolder palettes, PaletteHolder slantPalettes, boolean preventSmooth, boolean elevationInterpolation) { Parser p = new Parser(); p.registerFunction("rand", new RandomFunction()); @@ -117,11 +115,6 @@ public class WorldGenerator extends Generator { return preventSmooth; } - @Override - public Interpolator.Type getInterpolationType() { - return Interpolator.Type.LINEAR; - } - public boolean interpolateElevation() { return elevationInterpolation; } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/ExportCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/ExportCommand.java index ebf246d2f..5c7ec65e8 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/ExportCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/ExportCommand.java @@ -8,6 +8,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.Sign; +import org.bukkit.block.data.BlockData; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -59,6 +60,7 @@ public class ExportCommand extends PlayerCommand { for(int x = l1.getBlockX(); x <= l2.getBlockX(); x++) { for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) { for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) { + String data; Block block = new Location(l1.getWorld(), x, y, z).getBlock(); if(block.getType().equals(Material.STRUCTURE_VOID)) continue; scriptBuilder.append("block(").append(x - l1.getBlockX() - centerX).append(", y + ").append(y - l1.getBlockY() - centerY).append(", ").append(z - l1.getBlockZ() - centerZ).append(", ") @@ -67,12 +69,17 @@ public class ExportCommand extends PlayerCommand { if(state instanceof Sign) { Sign sign = (Sign) state; if(sign.getLine(0).equals("[TERRA]")) { - scriptBuilder.append(Bukkit.createBlockData(sign.getLine(2) + sign.getLine(3)).getAsString(false)); - } else scriptBuilder.append(block.getBlockData().getAsString(false)); + data = sign.getLine(2) + sign.getLine(3); + BlockData data1 = Bukkit.createBlockData(sign.getLine(2) + sign.getLine(3)); + if(data1.getMaterial().equals(Material.STRUCTURE_VOID)) continue; + scriptBuilder.append(data1.getAsString(false)); + } else { + data = block.getBlockData().getAsString(false); + } } else { - scriptBuilder.append(block.getBlockData().getAsString(false)); + data = block.getBlockData().getAsString(false); } - scriptBuilder.append("\");\n"); + scriptBuilder.append(data).append("\");\n"); } } }