mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-09 17:26:07 +00:00
Continue work on slant palettes and elevation.
This commit is contained in:
@@ -19,7 +19,7 @@ public class TerraProfiler extends WorldProfiler {
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "OreTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "CaveTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "StructureTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "StructurePasteTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "ElevationTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "SnowTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "CaveBlockUpdate");
|
||||
}
|
||||
|
||||
@@ -19,6 +19,6 @@ public final class FailoverGenerator extends UserDefinedGenerator {
|
||||
}
|
||||
|
||||
public FailoverGenerator() throws ParseException {
|
||||
super("0", null, Collections.emptyList(), palette, false);
|
||||
super("0", null, Collections.emptyList(), palette, new TreeMap<>(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class AbstractBiomeConfig extends TerraConfig {
|
||||
|
||||
if(contains("carving")) carving = new BiomeCarverConfig(this);
|
||||
|
||||
if(contains("palette")) palette = new BiomePaletteConfig(this);
|
||||
if(contains("palette")) palette = new BiomePaletteConfig(this, "palette");
|
||||
|
||||
if(contains("flora")) flora = new BiomeFloraConfig(this);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class BiomeConfig extends TerraConfig {
|
||||
|
||||
@@ -38,7 +39,6 @@ public class BiomeConfig extends TerraConfig {
|
||||
private final BiomeSnowConfig snow;
|
||||
private final List<StructureConfig> structures;
|
||||
private final ConfigPack config;
|
||||
private final Palette<BlockData> slant;
|
||||
private final double ySlantOffsetTop;
|
||||
private final double ySlantOffsetBottom;
|
||||
|
||||
@@ -78,7 +78,7 @@ public class BiomeConfig extends TerraConfig {
|
||||
if(extending && abstractBiome.getPaletteData() != null && !contains("palette")) {
|
||||
palette = abstractBiome.getPaletteData();
|
||||
Debug.info("Using super palette");
|
||||
} else palette = new BiomePaletteConfig(this);
|
||||
} else palette = new BiomePaletteConfig(this, "palette");
|
||||
|
||||
// Palette must not be null
|
||||
if(palette.getPaletteMap() == null)
|
||||
@@ -127,12 +127,13 @@ public class BiomeConfig extends TerraConfig {
|
||||
} else snow = new BiomeSnowConfig(this);
|
||||
|
||||
// Get slant stuff
|
||||
TreeMap<Integer, Palette<BlockData>> slant = new TreeMap<>();
|
||||
if(contains("slant")) {
|
||||
String slantS = getString("slant.palette");
|
||||
slant = config.getPalette(slantS).getPalette();
|
||||
slant = new BiomePaletteConfig(this, "slant.palette").getPaletteMap();
|
||||
Debug.info("Using slant palette: " + slantS);
|
||||
if(slant == null) throw new NotFoundException("Slant Palette", slantS, getID());
|
||||
} else slant = null;
|
||||
}
|
||||
ySlantOffsetTop = getDouble("slant.y-offset.top", 0.25);
|
||||
ySlantOffsetBottom = getDouble("slant.y-offset.bottom", 0.25);
|
||||
|
||||
@@ -166,11 +167,13 @@ public class BiomeConfig extends TerraConfig {
|
||||
}
|
||||
}
|
||||
|
||||
String elevation = getString("elevation-equation", null);
|
||||
String elevation = getString("elevation.equation", null);
|
||||
boolean doElevationInterpolation = getBoolean("elevation.interpolation", true);
|
||||
|
||||
try {
|
||||
// Get UserDefinedBiome instance representing this config.
|
||||
UserDefinedGenerator gen = new UserDefinedGenerator(eq, elevation, Collections.emptyList(), palette.getPaletteMap(), getBoolean("prevent-smooth", false));
|
||||
UserDefinedGenerator gen = new UserDefinedGenerator(eq, elevation, Collections.emptyList(), palette.getPaletteMap(), slant, getBoolean("prevent-smooth", false));
|
||||
gen.setElevationInterpolation(doElevationInterpolation);
|
||||
this.biome = new UserDefinedBiome(vanillaBiome, dec, gen, getBoolean("erodible", false), biomeID);
|
||||
} catch(ParseException e) {
|
||||
e.printStackTrace();
|
||||
@@ -194,10 +197,6 @@ public class BiomeConfig extends TerraConfig {
|
||||
return flora.getFloraHeights().computeIfAbsent(f, input -> new Range(-1, -1));
|
||||
}
|
||||
|
||||
public Palette<BlockData> getSlant() {
|
||||
return slant;
|
||||
}
|
||||
|
||||
public double getYSlantOffsetTop() {
|
||||
return ySlantOffsetTop;
|
||||
}
|
||||
|
||||
@@ -19,10 +19,9 @@ import java.util.TreeMap;
|
||||
public class BiomePaletteConfig extends TerraConfigSection {
|
||||
private TreeMap<Integer, Palette<BlockData>> paletteMap;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public BiomePaletteConfig(TerraConfig parent) throws InvalidConfigurationException {
|
||||
public BiomePaletteConfig(TerraConfig parent, String key) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
List<Map<?, ?>> cfg = parent.getMapList("palette");
|
||||
List<Map<?, ?>> cfg = parent.getMapList(key);
|
||||
if(cfg.size() == 0) return;
|
||||
paletteMap = new TreeMap<>();
|
||||
for(Map<?, ?> e : cfg) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.dfsek.terra.generation;
|
||||
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Generator;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
import org.polydev.gaea.math.Interpolator;
|
||||
@@ -13,11 +12,13 @@ public class ElevationInterpolator {
|
||||
private final FastNoiseLite noise;
|
||||
private final int xOrigin;
|
||||
private final int zOrigin;
|
||||
private final TerraBiomeGrid grid;
|
||||
|
||||
public ElevationInterpolator(World w, int chunkX, int chunkZ, TerraBiomeGrid grid, FastNoiseLite noise) {
|
||||
this.xOrigin = chunkX << 4;
|
||||
this.zOrigin = chunkZ << 4;
|
||||
this.noise = noise;
|
||||
this.grid = grid;
|
||||
|
||||
for(int x = -1; x < 7; x++) {
|
||||
for(int z = -1; z < 7; z++) {
|
||||
@@ -27,20 +28,26 @@ public class ElevationInterpolator {
|
||||
|
||||
for(byte x = -1; x <= 16; x++) {
|
||||
for(byte z = -1; z <= 16; z++) {
|
||||
if(compareGens((x / 4) + 1, (z / 4) + 1)) {
|
||||
UserDefinedGenerator generator = getGenerator(x, z);
|
||||
if(compareGens((x / 4) + 1, (z / 4) + 1) && generator.interpolateElevation()) {
|
||||
Interpolator interpolator = new Interpolator(biomeAvg(x / 4, z / 4),
|
||||
biomeAvg((x / 4) + 1, z / 4),
|
||||
biomeAvg(x / 4, (z / 4) + 1),
|
||||
biomeAvg((x / 4) + 1, (z / 4) + 1),
|
||||
Interpolator.Type.LINEAR);
|
||||
values[x + 1][z + 1] = interpolator.bilerp((double) (x % 4) / 4, (double) (z % 4) / 4);
|
||||
} else values[x + 1][z + 1] = elevate(gens[x / 4][z / 4], xOrigin + x, zOrigin + z);
|
||||
} else values[x + 1][z + 1] = elevate(generator, xOrigin + x, zOrigin + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private UserDefinedGenerator getGenerator(int x, int z) {
|
||||
return (UserDefinedGenerator) grid.getBiome(xOrigin + x, zOrigin + z, GenerationPhase.BASE).getGenerator();
|
||||
}
|
||||
|
||||
private boolean compareGens(int x, int z) {
|
||||
Generator comp = gens[x][z];
|
||||
UserDefinedGenerator comp = gens[x][z];
|
||||
|
||||
if(!comp.equals(gens[x + 1][z])) return true;
|
||||
|
||||
if(!comp.equals(gens[x][z + 1])) return true;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.generation;
|
||||
|
||||
import com.dfsek.terra.Debug;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
@@ -30,6 +31,7 @@ import org.polydev.gaea.generation.GenerationPhase;
|
||||
import org.polydev.gaea.generation.GenerationPopulator;
|
||||
import org.polydev.gaea.math.ChunkInterpolator;
|
||||
import org.polydev.gaea.population.PopulationManager;
|
||||
import org.polydev.gaea.profiler.ProfileFuture;
|
||||
import org.polydev.gaea.profiler.WorldProfiler;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
|
||||
@@ -81,7 +83,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
}
|
||||
|
||||
private static Palette<BlockData> getPalette(int x, int y, int z, BiomeConfig c, ChunkInterpolator interpolator, ElevationInterpolator elevationInterpolator) {
|
||||
Palette<BlockData> slant = c.getSlant();
|
||||
Palette<BlockData> slant = ((UserDefinedGenerator) c.getBiome().getGenerator()).getSlantPalette(y);
|
||||
if(slant != null) {
|
||||
boolean north = interpolator.getNoise(x, y - elevationInterpolator.getElevation(x, z + 1), z + 1) > 0;
|
||||
boolean south = interpolator.getNoise(x, y - elevationInterpolator.getElevation(x, z - 1), z - 1) > 0;
|
||||
@@ -99,20 +101,25 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
}
|
||||
|
||||
private static void prepareBlockPart(BlockData down, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs,
|
||||
Map<Material, Palette<BlockData>> stairs, double thresh, ChunkInterpolator interpolator) {
|
||||
if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) {
|
||||
Map<Material, Palette<BlockData>> stairs, double thresh, ChunkInterpolator interpolator, ElevationInterpolator elevationInterpolator) {
|
||||
double elevation = elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ());
|
||||
if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - 0.4 - elevation, block.getBlockZ()) > thresh) {
|
||||
if(stairs != null) {
|
||||
Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
|
||||
if(stairPalette != null) {
|
||||
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ());
|
||||
Stairs stairNew = (Stairs) stair.clone();
|
||||
if(interpolator.getNoise(block.getBlockX() - 0.5, block.getBlockY(), block.getBlockZ()) > thresh) {
|
||||
double elevationN = elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ() - 1); // Northern elevation
|
||||
double elevationS = elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ() + 1); // Southern elevation
|
||||
double elevationE = elevationInterpolator.getElevation(block.getBlockX() + 1, block.getBlockZ()); // Eastern elevation
|
||||
double elevationW = elevationInterpolator.getElevation(block.getBlockX() - 1, block.getBlockZ()); // Western elevation
|
||||
if(interpolator.getNoise(block.getBlockX() - 0.5, block.getBlockY() - elevationW, block.getBlockZ()) > thresh) {
|
||||
stairNew.setFacing(BlockFace.WEST);
|
||||
} else if(interpolator.getNoise(block.getBlockX(), block.getBlockY(), block.getBlockZ() - 0.5) > thresh) {
|
||||
} else if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - elevationN, block.getBlockZ() - 0.5) > thresh) {
|
||||
stairNew.setFacing(BlockFace.NORTH);
|
||||
} else if(interpolator.getNoise(block.getBlockX(), block.getBlockY(), block.getBlockZ() + 0.5) > thresh) {
|
||||
} else if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - elevationS, block.getBlockZ() + 0.5) > thresh) {
|
||||
stairNew.setFacing(BlockFace.SOUTH);
|
||||
} else if(interpolator.getNoise(block.getBlockX() + 0.5, block.getBlockY(), block.getBlockZ()) > thresh) {
|
||||
} else if(interpolator.getNoise(block.getBlockX() + 0.5, block.getBlockY() - elevationE, block.getBlockZ()) > thresh) {
|
||||
stairNew.setFacing(BlockFace.EAST);
|
||||
} else stairNew = null;
|
||||
if(stairNew != null) {
|
||||
@@ -131,6 +138,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, ChunkInterpolator interpolator) {
|
||||
if(needsLoad) load(world); // Load population data for world.
|
||||
ChunkData chunk = createChunkData(world);
|
||||
@@ -141,7 +149,10 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
int zOrig = (chunkZ << 4);
|
||||
org.polydev.gaea.biome.BiomeGrid grid = getBiomeGrid(world);
|
||||
|
||||
ElevationInterpolator elevationInterpolator = new ElevationInterpolator(world, chunkX, chunkZ, tw.getGrid(), getNoiseGenerator());
|
||||
ElevationInterpolator elevationInterpolator;
|
||||
try(ProfileFuture ignore = TerraProfiler.fromWorld(world).measure("ElevationTime")) {
|
||||
elevationInterpolator = new ElevationInterpolator(world, chunkX, chunkZ, tw.getGrid(), getNoiseGenerator());
|
||||
}
|
||||
|
||||
for(byte x = 0; x < 16; x++) {
|
||||
for(byte z = 0; z < 16; z++) {
|
||||
@@ -153,7 +164,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
Biome b = grid.getBiome(xOrig + x, zOrig + z, GenerationPhase.PALETTE_APPLY);
|
||||
BiomeConfig c = config.getBiome((UserDefinedBiome) b);
|
||||
|
||||
int elevate = (int) elevationInterpolator.getElevation(x, z);
|
||||
double elevate = elevationInterpolator.getElevation(x, z);
|
||||
|
||||
BiomeSlabConfig slab = c.getSlabs();
|
||||
int sea = c.getOcean().getSeaLevel();
|
||||
@@ -164,7 +175,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
chunk.setBlock(x, y, z, data);
|
||||
if(paletteLevel == 0 && slab != null && y < 255) {
|
||||
prepareBlockPart(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector(x, y + 1, z), slab.getSlabs(),
|
||||
slab.getStairs(), slab.getSlabThreshold(), interpolator);
|
||||
slab.getStairs(), slab.getSlabThreshold(), interpolator, elevationInterpolator);
|
||||
}
|
||||
paletteLevel++;
|
||||
} else if(y <= sea) {
|
||||
|
||||
@@ -30,13 +30,16 @@ public class UserDefinedGenerator extends Generator {
|
||||
private final Variable zVar = s.getVariable("z");
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||
private final Palette<BlockData>[] palettes = new Palette[256];
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||
private final Palette<BlockData>[] slantPalettes = new Palette[256];
|
||||
private final NoiseFunction2 n2 = new NoiseFunction2();
|
||||
private final NoiseFunction3 n3 = new NoiseFunction3();
|
||||
private final ElevationEquation elevationEquation;
|
||||
private final boolean preventSmooth;
|
||||
private boolean elevationInterpolation;
|
||||
|
||||
|
||||
public UserDefinedGenerator(String equation, @Nullable String elevateEquation, List<Variable> userVariables, Map<Integer, Palette<BlockData>> paletteMap, boolean preventSmooth)
|
||||
public UserDefinedGenerator(String equation, @Nullable String elevateEquation, List<Variable> userVariables, Map<Integer, Palette<BlockData>> paletteMap, Map<Integer, Palette<BlockData>> slantPaletteMap, boolean preventSmooth)
|
||||
throws ParseException {
|
||||
Parser p = new Parser();
|
||||
p.registerFunction("noise2", n2);
|
||||
@@ -50,6 +53,14 @@ public class UserDefinedGenerator extends Generator {
|
||||
}
|
||||
}
|
||||
palettes[y] = d;
|
||||
Palette<BlockData> slantPalette = null;
|
||||
for(Map.Entry<Integer, Palette<BlockData>> e : slantPaletteMap.entrySet()) {
|
||||
if(e.getKey() >= y) {
|
||||
slantPalette = e.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
slantPalettes[y] = slantPalette;
|
||||
}
|
||||
if(elevateEquation != null) {
|
||||
Debug.info("Using elevation equation");
|
||||
@@ -110,6 +121,11 @@ public class UserDefinedGenerator extends Generator {
|
||||
return palettes[y];
|
||||
}
|
||||
|
||||
public Palette<BlockData> getSlantPalette(int y) {
|
||||
return slantPalettes[y];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean useMinimalInterpolation() {
|
||||
return preventSmooth;
|
||||
@@ -123,4 +139,12 @@ public class UserDefinedGenerator extends Generator {
|
||||
public ElevationEquation getElevationEquation() {
|
||||
return elevationEquation;
|
||||
}
|
||||
|
||||
public boolean interpolateElevation() {
|
||||
return elevationInterpolation;
|
||||
}
|
||||
|
||||
public void setElevationInterpolation(boolean elevationInterpolation) {
|
||||
this.elevationInterpolation = elevationInterpolation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,30 +49,28 @@ public class StructurePopulator extends BlockPopulator {
|
||||
if(!struc.checkSpawns(spawn, rotation)) continue;
|
||||
double horizontal = struc.getStructureInfo().getMaxHorizontal();
|
||||
if(Math.abs((cx + 8) - spawn.getBlockX()) <= horizontal && Math.abs((cz + 8) - spawn.getBlockZ()) <= horizontal) {
|
||||
try(ProfileFuture ignore = TerraProfiler.fromWorld(world).measure("StructurePasteTime")) {
|
||||
struc.paste(spawn, chunk, rotation);
|
||||
for(StructureContainedInventory i : struc.getInventories()) {
|
||||
try {
|
||||
Debug.info("Attempting to populate loot: " + i.getUid());
|
||||
Vector2 lootCoords = RotationUtil.getRotatedCoords(new Vector2(i.getX() - struc.getStructureInfo().getCenterX(), i.getZ() - struc.getStructureInfo().getCenterZ()), rotation.inverse());
|
||||
Location inv = spawn.clone().add(lootCoords.getX(), i.getY(), lootCoords.getZ());
|
||||
Debug.info(Math.floorDiv(inv.getBlockX(), 16) + ":" + chunk.getX() + ", " + Math.floorDiv(inv.getBlockZ(), 16) + ":" + chunk.getZ());
|
||||
if(Math.floorDiv(inv.getBlockX(), 16) != chunk.getX() || Math.floorDiv(inv.getBlockZ(), 16) != chunk.getZ())
|
||||
continue;
|
||||
Debug.info("Target is in chunk.");
|
||||
Debug.info(spawn.toString() + " became: " + inv.toString() + " (" + rotation + ", " + inv.getBlock().getType() + ")");
|
||||
LootTable table = conf.getLoot(i.getUid());
|
||||
if(table == null) continue;
|
||||
Debug.info("Target has table assigned.");
|
||||
table.fillInventory(((BlockInventoryHolder) inv.getBlock().getState()).getInventory(), random);
|
||||
} catch(ClassCastException e) {
|
||||
Debug.error("Could not populate structure loot!");
|
||||
Debug.stack(e);
|
||||
}
|
||||
struc.paste(spawn, chunk, rotation);
|
||||
for(StructureContainedInventory i : struc.getInventories()) {
|
||||
try {
|
||||
Debug.info("Attempting to populate loot: " + i.getUid());
|
||||
Vector2 lootCoords = RotationUtil.getRotatedCoords(new Vector2(i.getX() - struc.getStructureInfo().getCenterX(), i.getZ() - struc.getStructureInfo().getCenterZ()), rotation.inverse());
|
||||
Location inv = spawn.clone().add(lootCoords.getX(), i.getY(), lootCoords.getZ());
|
||||
Debug.info(Math.floorDiv(inv.getBlockX(), 16) + ":" + chunk.getX() + ", " + Math.floorDiv(inv.getBlockZ(), 16) + ":" + chunk.getZ());
|
||||
if(Math.floorDiv(inv.getBlockX(), 16) != chunk.getX() || Math.floorDiv(inv.getBlockZ(), 16) != chunk.getZ())
|
||||
continue;
|
||||
Debug.info("Target is in chunk.");
|
||||
Debug.info(spawn.toString() + " became: " + inv.toString() + " (" + rotation + ", " + inv.getBlock().getType() + ")");
|
||||
LootTable table = conf.getLoot(i.getUid());
|
||||
if(table == null) continue;
|
||||
Debug.info("Target has table assigned.");
|
||||
table.fillInventory(((BlockInventoryHolder) inv.getBlock().getState()).getInventory(), random);
|
||||
} catch(ClassCastException e) {
|
||||
Debug.error("Could not populate structure loot!");
|
||||
Debug.stack(e);
|
||||
}
|
||||
for(Feature f : conf.getFeatures()) f.apply(struc, spawn, chunk); // Apply features.
|
||||
break;
|
||||
}
|
||||
for(Feature f : conf.getFeatures()) f.apply(struc, spawn, chunk); // Apply features.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user