for some reason these werent in the changelist

This commit is contained in:
dfsek
2020-12-11 17:31:06 -07:00
parent 5bf699cba9
commit 0261ecdcbb
2 changed files with 5 additions and 1 deletions

View File

@@ -0,0 +1,70 @@
package com.dfsek.terra.api.generic.generator;
import com.dfsek.terra.api.generic.Handle;
import com.dfsek.terra.api.generic.world.BiomeGrid;
import com.dfsek.terra.api.generic.world.World;
import com.dfsek.terra.api.generic.world.block.BlockData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Random;
public interface ChunkGenerator extends Handle {
boolean isParallelCapable();
boolean shouldGenerateCaves();
boolean shouldGenerateDecorations();
boolean shouldGenerateMobs();
boolean shouldGenerateStructures();
ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome);
List<BlockPopulator> getDefaultPopulators(World world);
@Nullable
TerraChunkGenerator getTerraGenerator();
interface ChunkData {
Object getHandle();
/**
* Get the maximum height for the chunk.
* <p>
* Setting blocks at or above this height will do nothing.
*
* @return the maximum height
*/
int getMaxHeight();
/**
* Set the block at x,y,z in the chunk data to material.
* <p>
* Setting blocks outside the chunk's bounds does nothing.
*
* @param x the x location in the chunk from 0-15 inclusive
* @param y the y location in the chunk from 0 (inclusive) - maxHeight (exclusive)
* @param z the z location in the chunk from 0-15 inclusive
* @param blockData the type to set the block to
*/
void setBlock(int x, int y, int z, @NotNull BlockData blockData);
/**
* Get the type and data of the block at x, y, z.
* <p>
* Getting blocks outside the chunk's bounds returns air.
*
* @param x the x location in the chunk from 0-15 inclusive
* @param y the y location in the chunk from 0 (inclusive) - maxHeight (exclusive)
* @param z the z location in the chunk from 0-15 inclusive
* @return the data of the block or the BlockData for air if x, y or z are outside the chunk's bounds
*/
@NotNull BlockData getBlockData(int x, int y, int z);
}
}

View File

@@ -0,0 +1,240 @@
package com.dfsek.terra.config.templates;
import com.dfsek.tectonic.annotations.Abstractable;
import com.dfsek.tectonic.annotations.Default;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
import com.dfsek.tectonic.exception.ValidationException;
import com.dfsek.terra.api.gaea.util.GlueList;
import com.dfsek.terra.api.gaea.world.palette.Palette;
import com.dfsek.terra.api.generic.world.Biome;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.MaterialData;
import com.dfsek.terra.biome.palette.PaletteHolder;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.generation.items.TerraStructure;
import com.dfsek.terra.generation.items.flora.FloraLayer;
import com.dfsek.terra.generation.items.ores.OreHolder;
import com.dfsek.terra.generation.items.tree.TreeLayer;
import com.dfsek.terra.math.BlankFunction;
import parsii.eval.Parser;
import parsii.eval.Scope;
import parsii.tokenizer.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings({"FieldMayBeFinal", "unused"})
public class BiomeTemplate extends AbstractableTemplate implements ValidatedConfigTemplate {
private final ConfigPack pack;
@Value("id")
private String id;
@Value("extends")
@Default
private String extend = null;
@Value("palette")
@Abstractable
private PaletteHolder palette;
@Value("slant.palette")
@Abstractable
@Default
private PaletteHolder slantPalette = null;
@Value("vanilla")
@Abstractable
private Biome vanilla;
@Value("erode")
@Abstractable
@Default
private String erode = null;
@Value("structures")
@Abstractable
@Default
private List<TerraStructure> structures = new GlueList<>();
@Value("carving")
@Abstractable
@Default
private Map<UserDefinedCarver, Integer> carvers = new HashMap<>();
@Value("noise-equation")
@Abstractable
private String noiseEquation;
@Value("ores")
@Abstractable
@Default
private OreHolder oreHolder = new OreHolder();
@Value("ocean.level")
@Abstractable
@Default
private int seaLevel = 62;
@Value("ocean.palette")
@Abstractable
@Default
private Palette<BlockData> oceanPalette = null;
@Value("elevation.equation")
@Default
@Abstractable
private String elevationEquation = null;
@Value("flora")
@Abstractable
@Default
private List<FloraLayer> flora = new GlueList<>();
//@Value("trees")
@Abstractable
@Default
private List<TreeLayer> trees = new GlueList<>();
@Value("slabs.enable")
@Abstractable
@Default
private boolean doSlabs = false;
@Value("slabs.threshold")
@Abstractable
@Default
private double slabThreshold = 0.0075D;
@Value("slabs.palettes")
@Abstractable
@Default
private Map<MaterialData, Palette<BlockData>> slabPalettes;
@Value("slabs.stair-palettes")
@Abstractable
@Default
private Map<MaterialData, Palette<BlockData>> stairPalettes;
@Value("slant.threshold")
@Abstractable
@Default
private double slantThreshold = 0.1;
@Value("interpolate-elevation")
@Abstractable
@Default
private boolean interpolateElevation = true;
public boolean interpolateElevation() {
return interpolateElevation;
}
public String getExtend() {
return extend;
}
public double getSlantThreshold() {
return slantThreshold;
}
public double getSlabThreshold() {
return slabThreshold;
}
public List<FloraLayer> getFlora() {
return flora;
}
public boolean doSlabs() {
return doSlabs;
}
public Map<MaterialData, Palette<BlockData>> getSlabPalettes() {
return slabPalettes;
}
public Map<MaterialData, Palette<BlockData>> getStairPalettes() {
return stairPalettes;
}
public BiomeTemplate(ConfigPack pack) {
this.pack = pack;
}
public String getElevationEquation() {
return elevationEquation;
}
public ConfigPack getPack() {
return pack;
}
public int getSeaLevel() {
return seaLevel;
}
public Palette<BlockData> getOceanPalette() {
return oceanPalette;
}
public String getID() {
return id;
}
public PaletteHolder getPalette() {
return palette;
}
public List<TreeLayer> getTrees() {
return trees;
}
public PaletteHolder getSlantPalette() {
return slantPalette;
}
public Biome getVanilla() {
return vanilla;
}
public String getErode() {
return erode;
}
public List<TerraStructure> getStructures() {
return structures;
}
public Map<UserDefinedCarver, Integer> getCarvers() {
return carvers;
}
public String getNoiseEquation() {
return noiseEquation;
}
public OreHolder getOreHolder() {
return oreHolder;
}
@Override
public boolean validate() throws ValidationException {
Parser tester = new Parser();
Scope testScope = new Scope().withParent(pack.getVarScope());
testScope.create("x");
testScope.create("y");
testScope.create("z");
testScope.create("seed");
pack.getTemplate().getNoiseBuilderMap().forEach((id, builder) -> tester.registerFunction(id, new BlankFunction(builder.getDimensions()))); // Register dummy functions
try {
tester.parse(noiseEquation, testScope);
} catch(ParseException e) {
throw new ValidationException("Invalid noise equation: ", e);
}
try {
if(elevationEquation != null) tester.parse(elevationEquation, testScope);
} catch(ParseException e) {
throw new ValidationException("Invalid elevation equation: ", e);
}
return true;
}
}