mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Implement slant palettes
This commit is contained in:
parent
9ecefb754c
commit
d75cd81408
@ -27,7 +27,7 @@ public enum FailType {
|
|||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Returns null, hard crashing the server, but not generating any corrupted terrain.<br>
|
* Returns null, hard crashing the server, but not generating any corrupted terrain.<br>
|
||||||
* This option is <br>NOT</br> stable, but it has the least risk of blank chunks being generated.
|
* This option is <b>NOT</b> stable, but it has the least risk of blank chunks being generated.
|
||||||
* However, it has the highest risk of corruption!
|
* However, it has the highest risk of corruption!
|
||||||
*/
|
*/
|
||||||
CRASH {
|
CRASH {
|
||||||
|
@ -10,10 +10,12 @@ import com.dfsek.terra.config.exception.NotFoundException;
|
|||||||
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
||||||
import com.dfsek.terra.generation.UserDefinedDecorator;
|
import com.dfsek.terra.generation.UserDefinedDecorator;
|
||||||
import com.dfsek.terra.generation.UserDefinedGenerator;
|
import com.dfsek.terra.generation.UserDefinedGenerator;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.polydev.gaea.math.Range;
|
import org.polydev.gaea.math.Range;
|
||||||
import org.polydev.gaea.tree.Tree;
|
import org.polydev.gaea.tree.Tree;
|
||||||
import org.polydev.gaea.world.Flora;
|
import org.polydev.gaea.world.Flora;
|
||||||
|
import org.polydev.gaea.world.palette.Palette;
|
||||||
import parsii.tokenizer.ParseException;
|
import parsii.tokenizer.ParseException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -36,6 +38,7 @@ public class BiomeConfig extends TerraConfig {
|
|||||||
private final BiomeSnowConfig snow;
|
private final BiomeSnowConfig snow;
|
||||||
private final List<StructureConfig> structures;
|
private final List<StructureConfig> structures;
|
||||||
private final ConfigPack config;
|
private final ConfigPack config;
|
||||||
|
private final Palette<BlockData> slant;
|
||||||
private String eq;
|
private String eq;
|
||||||
|
|
||||||
public BiomeConfig(File file, ConfigPack config) throws InvalidConfigurationException, IOException {
|
public BiomeConfig(File file, ConfigPack config) throws InvalidConfigurationException, IOException {
|
||||||
@ -120,6 +123,14 @@ public class BiomeConfig extends TerraConfig {
|
|||||||
Debug.info("Using super snow");
|
Debug.info("Using super snow");
|
||||||
} else snow = new BiomeSnowConfig(this);
|
} else snow = new BiomeSnowConfig(this);
|
||||||
|
|
||||||
|
// Get slant palette
|
||||||
|
if(contains("slant-palette")) {
|
||||||
|
String slantS = getString("slant-palette");
|
||||||
|
slant = config.getPalette(slantS).getPalette();
|
||||||
|
Debug.info("Using slant palette: " + slantS);
|
||||||
|
if(slant == null) throw new NotFoundException("Slant Palette", slantS, getID());
|
||||||
|
} else slant = null;
|
||||||
|
|
||||||
//Make sure equation is non-null
|
//Make sure equation is non-null
|
||||||
if(eq == null || eq.equals(""))
|
if(eq == null || eq.equals(""))
|
||||||
throw new ConfigException("Could not find noise equation! Biomes must include a noise equation, or extend an abstract biome with one.", getID());
|
throw new ConfigException("Could not find noise equation! Biomes must include a noise equation, or extend an abstract biome with one.", getID());
|
||||||
@ -175,6 +186,10 @@ public class BiomeConfig extends TerraConfig {
|
|||||||
return flora.getFloraHeights().computeIfAbsent(f, input -> new Range(-1, -1));
|
return flora.getFloraHeights().computeIfAbsent(f, input -> new Range(-1, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Palette<BlockData> getSlant() {
|
||||||
|
return slant;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Biome with ID " + getID() + " and noise equation " + eq;
|
return "Biome with ID " + getID() + " and noise equation " + eq;
|
||||||
|
@ -80,46 +80,23 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
|||||||
popMan.attachProfiler(p);
|
popMan.attachProfiler(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static Palette<BlockData> getPalette(int x, int y, int z, BiomeConfig c, ChunkInterpolator interpolator) {
|
||||||
public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, ChunkInterpolator interpolator) {
|
Palette<BlockData> slant = c.getSlant();
|
||||||
if(needsLoad) load(world); // Load population data for world.
|
if(slant != null) {
|
||||||
ChunkData chunk = createChunkData(world);
|
boolean north = interpolator.getNoise(x, y, z + 1) > 0;
|
||||||
TerraWorld tw = TerraWorld.getWorld(world);
|
boolean south = interpolator.getNoise(x, y, z - 1) > 0;
|
||||||
if(!tw.isSafe()) return chunk;
|
boolean east = interpolator.getNoise(x + 1, y, z) > 0;
|
||||||
ConfigPack config = tw.getConfig();
|
boolean west = interpolator.getNoise(x - 1, y, z) > 0;
|
||||||
int xOrig = (chunkX << 4);
|
|
||||||
int zOrig = (chunkZ << 4);
|
boolean top = interpolator.getNoise(x, y + 0.25, z) > 0;
|
||||||
org.polydev.gaea.biome.BiomeGrid grid = getBiomeGrid(world);
|
boolean bottom = interpolator.getNoise(x, y - 0.25, z) > 0;
|
||||||
for(byte x = 0; x < 16; x++) {
|
|
||||||
for(byte z = 0; z < 16; z++) {
|
if((top && bottom) && (north || south || east || west) && (!(north && south && east && west))) return slant;
|
||||||
int paletteLevel = 0;
|
|
||||||
int cx = xOrig + x;
|
|
||||||
int cz = zOrig + z;
|
|
||||||
Biome b = grid.getBiome(xOrig + x, zOrig + z, GenerationPhase.PALETTE_APPLY);
|
|
||||||
BiomeConfig c = config.getBiome((UserDefinedBiome) b);
|
|
||||||
BiomeSlabConfig slab = c.getSlabs();
|
|
||||||
int sea = c.getOcean().getSeaLevel();
|
|
||||||
Palette<BlockData> seaPalette = c.getOcean().getOcean();
|
|
||||||
for(int y = world.getMaxHeight() - 1; y >= 0; y--) {
|
|
||||||
if(interpolator.getNoise(x, y, z) > 0) {
|
|
||||||
BlockData data = b.getGenerator().getPalette(y).get(paletteLevel, cx, cz);
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
paletteLevel++;
|
return c.getBiome().getGenerator().getPalette(y);
|
||||||
} else if(y <= sea) {
|
|
||||||
chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, z + zOrig));
|
|
||||||
paletteLevel = 0;
|
|
||||||
} else paletteLevel = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return chunk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareBlockPart(BlockData down, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs,
|
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) {
|
Map<Material, Palette<BlockData>> stairs, double thresh, ChunkInterpolator interpolator) {
|
||||||
if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) {
|
if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) {
|
||||||
if(stairs != null) {
|
if(stairs != null) {
|
||||||
@ -151,6 +128,45 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
TerraWorld tw = TerraWorld.getWorld(world);
|
||||||
|
if(!tw.isSafe()) return chunk;
|
||||||
|
ConfigPack config = tw.getConfig();
|
||||||
|
int xOrig = (chunkX << 4);
|
||||||
|
int zOrig = (chunkZ << 4);
|
||||||
|
org.polydev.gaea.biome.BiomeGrid grid = getBiomeGrid(world);
|
||||||
|
for(byte x = 0; x < 16; x++) {
|
||||||
|
for(byte z = 0; z < 16; z++) {
|
||||||
|
int paletteLevel = 0;
|
||||||
|
int cx = xOrig + x;
|
||||||
|
int cz = zOrig + z;
|
||||||
|
Biome b = grid.getBiome(xOrig + x, zOrig + z, GenerationPhase.PALETTE_APPLY);
|
||||||
|
BiomeConfig c = config.getBiome((UserDefinedBiome) b);
|
||||||
|
BiomeSlabConfig slab = c.getSlabs();
|
||||||
|
int sea = c.getOcean().getSeaLevel();
|
||||||
|
Palette<BlockData> seaPalette = c.getOcean().getOcean();
|
||||||
|
for(int y = world.getMaxHeight() - 1; y >= 0; y--) {
|
||||||
|
if(interpolator.getNoise(x, y, z) > 0) {
|
||||||
|
BlockData data = getPalette(x, y, z, c, interpolator).get(paletteLevel, cx, cz);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
paletteLevel++;
|
||||||
|
} else if(y <= sea) {
|
||||||
|
chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, z + zOrig));
|
||||||
|
paletteLevel = 0;
|
||||||
|
} else paletteLevel = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
private void load(World w) {
|
private void load(World w) {
|
||||||
try {
|
try {
|
||||||
popMan.loadBlocks(w);
|
popMan.loadBlocks(w);
|
||||||
|
@ -13,6 +13,8 @@ palette:
|
|||||||
vanilla: SAVANNA
|
vanilla: SAVANNA
|
||||||
|
|
||||||
erodible: false
|
erodible: false
|
||||||
|
prevent-smooth: true
|
||||||
|
slant-palette: STONE
|
||||||
|
|
||||||
flora:
|
flora:
|
||||||
chance: 40
|
chance: 40
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
layers:
|
||||||
|
- materials:
|
||||||
|
- "minecraft:diamond_block": 1
|
||||||
|
layers: 1
|
||||||
|
id: "STONE"
|
Loading…
x
Reference in New Issue
Block a user