mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-05-20 16:50:28 +00:00
Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e0d7b03820 | |||
| 68aa38a51a | |||
| beb07337ae | |||
| 2010c48664 | |||
| 7473119238 | |||
| 733b9fab4b | |||
| 64cf6538cb | |||
| 9c86d015f0 | |||
| 008084fae9 | |||
| 139f67af52 | |||
| 2020ef31e4 | |||
| c6636a72da | |||
| 97b3042357 | |||
| 3aaedcf74f | |||
| f0655d1bb9 | |||
| bdce485ca5 | |||
| 78991c667c | |||
| df45aecdab | |||
| 571a5fdf3a | |||
| 1610d4e0c9 | |||
| 1e43365bbf | |||
| 587cb8755f | |||
| f90f7bd063 | |||
| d95239a5dd | |||
| 91703c4fc9 | |||
| 1b05ca8e96 | |||
| 33288c057c | |||
| 6027c282ab | |||
| 0068f69982 | |||
| 9df379644b | |||
| 492939b5d1 | |||
| 20d45a4b1e | |||
| db70b6c88c | |||
| 1cee01a36c | |||
| a9c252f91c | |||
| 86ad5b5041 | |||
| 7061328cc7 | |||
| 3f56da3a65 | |||
| 16fcf09c78 | |||
| cba3388cb1 | |||
| 94611913c3 | |||
| 709180de13 | |||
| 5182651947 | |||
| 7f33fb20ed | |||
| c9f49fb06f | |||
| d065f78c0a |
@@ -15,7 +15,7 @@ fun Project.configureCompilation() {
|
||||
|
||||
configure<JavaPluginConvention> {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.dfsek.terra.api.config.meta;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* Context from which to pull {@link MetaValue}s
|
||||
*/
|
||||
public interface MetaContext {
|
||||
default <T> T load(String meta, Class<T> clazz) throws LoadException {
|
||||
return load(meta, (Type) clazz);
|
||||
}
|
||||
|
||||
<T> T load(String meta, Type type) throws LoadException;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.dfsek.terra.api.config.meta;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface MetaValue<T> extends Supplier<T> {
|
||||
static <T1> MetaValue<T1> of(T1 value) {
|
||||
return () -> value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.api.config.meta.type;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MetaList<T> extends MetaValue<List<T>> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.api.config.meta.type;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface MetaMap<K, V> extends MetaValue<Map<K, V>> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.api.config.meta.type;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface MetaSet<T> extends MetaValue<Set<T>> {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.dfsek.terra.api.config.meta.type.number;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
|
||||
public interface MetaNumber<T extends Number> extends MetaValue<T> {
|
||||
}
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class ZeroArgFunctionBuilder<T> implements FunctionBuilder<Function<T>> {
|
||||
|
||||
@Override
|
||||
public int argNumber() {
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ public class BufferedPulledBlock implements BufferedItem {
|
||||
@Override
|
||||
public void paste(Location origin) {
|
||||
Block pos = origin.getBlock();
|
||||
while(pos.getY() > 0) {
|
||||
while(pos.getY() > origin.getWorld().getMinHeight()) {
|
||||
if(!pos.isEmpty()) {
|
||||
pos.setBlockData(data, false);
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.dfsek.terra.api.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class MapUtil {
|
||||
public static <K1, V1, K2, V2, M extends Map<K2, V2>> M remap(Function<K1, K2> keys, Function<V1, V2> values, Map<K1, V1> in, Supplier<M> newMap) {
|
||||
M map = newMap.get();
|
||||
in.forEach((k, v) -> map.put(keys.apply(k), values.apply(v)));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static <K1, V1, K2, V2> Map<K2, V2> remap(Function<K1, K2> keys, Function<V1, V2> values, Map<K1, V1> in) {
|
||||
return remap(keys, values, in, HashMap::new);
|
||||
}
|
||||
|
||||
public static <K, V1, V2> Map<K, V2> remapValues(Function<V1, V2> values, Map<K, V1> in) {
|
||||
return remap(Function.identity(), values, in);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.dfsek.terra.api.util;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MetaTokenizer {
|
||||
public MetaTokenizer(Reader in) {
|
||||
|
||||
}
|
||||
}
|
||||
+8
-2
@@ -23,7 +23,7 @@ public class ProbabilityCollection<E> implements Collection<E> {
|
||||
|
||||
public ProbabilityCollection<E> add(E item, int probability) {
|
||||
if(!cont.containsKey(item)) size++;
|
||||
cont.computeIfAbsent(item, i -> new MutableInteger(0)).increment();
|
||||
cont.computeIfAbsent(item, i -> new MutableInteger(0)).add(probability);
|
||||
int oldLength = array.length;
|
||||
Object[] newArray = new Object[array.length + probability];
|
||||
System.arraycopy(array, 0, newArray, 0, array.length); // Expand array.
|
||||
@@ -51,13 +51,19 @@ public class ProbabilityCollection<E> implements Collection<E> {
|
||||
ProbabilityCollection<T> newCollection = new ProbabilityCollection<>();
|
||||
newCollection.array = new Object[array.length];
|
||||
|
||||
Map<E, T> cache = new HashMap<>();
|
||||
|
||||
for(int i = 0; i < array.length; i++) {
|
||||
if(carryNull && array[i] == null) continue;
|
||||
newCollection.array[i] = mapper.apply((E) array[i]);
|
||||
newCollection.array[i] = cache.computeIfAbsent((E) array[i], mapper);
|
||||
}
|
||||
return newCollection;
|
||||
}
|
||||
|
||||
public <T> ProbabilityCollection<T> map(Function<E, T> mapper) {
|
||||
return map(mapper, true);
|
||||
}
|
||||
|
||||
public int getTotalProbability() {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.dfsek.terra.api.util.generic;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class Lazy<T> {
|
||||
private final Supplier<T> fetch;
|
||||
|
||||
private T value;
|
||||
|
||||
private boolean needsInit = true;
|
||||
|
||||
public Lazy(Supplier<T> fetch) {
|
||||
this.fetch = fetch;
|
||||
}
|
||||
|
||||
public T get() {
|
||||
if(needsInit) {
|
||||
value = fetch.get();
|
||||
needsInit = false;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.api.world.carving;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -85,7 +86,7 @@ public abstract class Worm {
|
||||
return rad[index];
|
||||
}
|
||||
|
||||
public void carve(int chunkX, int chunkZ, BiConsumer<Vector3, Carver.CarvingType> consumer) {
|
||||
public void carve(int chunkX, int chunkZ, BiConsumer<Vector3, Carver.CarvingType> consumer, World world) {
|
||||
int xRad = getRadius(0);
|
||||
int yRad = getRadius(1);
|
||||
int zRad = getRadius(2);
|
||||
@@ -97,7 +98,7 @@ public abstract class Worm {
|
||||
if(!(FastMath.floorDiv(origin.getBlockZ() + z, 16) == chunkZ)) continue;
|
||||
for(int y = -yRad - 1; y <= yRad + 1; y++) {
|
||||
Vector3 position = origin.clone().add(new Vector3(x, y, z));
|
||||
if(position.getY() < 0 || position.getY() > 255) continue;
|
||||
if(position.getY() < world.getMinHeight() || position.getY() > world.getMaxHeight()) continue;
|
||||
double eq = ellipseEquation(x, y, z, xRad, yRad, zRad);
|
||||
if(eq <= 1 &&
|
||||
y >= -yRad - 1 + bottomCut && y <= yRad + 1 - topCut) {
|
||||
|
||||
@@ -5,12 +5,19 @@ import com.dfsek.terra.api.world.palette.Palette;
|
||||
|
||||
public class PaletteHolder {
|
||||
private final Palette<BlockData>[] palettes;
|
||||
private final int offset;
|
||||
|
||||
protected PaletteHolder(Palette<BlockData>[] palettes) {
|
||||
protected PaletteHolder(Palette<BlockData>[] palettes, int offset) {
|
||||
this.palettes = palettes;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public Palette<BlockData> getPalette(int y) {
|
||||
return palettes[y];
|
||||
int index = y + offset;
|
||||
return index >= 0
|
||||
? index < palettes.length
|
||||
? palettes[index]
|
||||
: palettes[palettes.length - 1]
|
||||
: palettes[0];
|
||||
}
|
||||
}
|
||||
|
||||
+8
-4
@@ -17,8 +17,12 @@ public class PaletteHolderBuilder {
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||
public PaletteHolder build() {
|
||||
Palette<BlockData>[] palettes = new Palette[paletteMap.lastKey() + 1];
|
||||
for(int y = 0; y <= FastMath.max(paletteMap.lastKey(), 255); y++) {
|
||||
|
||||
int min = FastMath.min(paletteMap.keySet().stream().min(Integer::compareTo).orElse(0), 0);
|
||||
int max = FastMath.max(paletteMap.keySet().stream().max(Integer::compareTo).orElse(255), 255);
|
||||
|
||||
Palette<BlockData>[] palettes = new Palette[paletteMap.lastKey() + 1 - min];
|
||||
for(int y = min; y <= FastMath.max(paletteMap.lastKey(), max); y++) {
|
||||
Palette<BlockData> d = null;
|
||||
for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) {
|
||||
if(e.getKey() >= y) {
|
||||
@@ -27,8 +31,8 @@ public class PaletteHolderBuilder {
|
||||
}
|
||||
}
|
||||
if(d == null) throw new IllegalArgumentException("No palette for Y=" + y);
|
||||
palettes[y] = d;
|
||||
palettes[y - min] = d;
|
||||
}
|
||||
return new PaletteHolder(palettes);
|
||||
return new PaletteHolder(palettes, -min);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@@ -41,13 +42,13 @@ public class CarverCache {
|
||||
carving.step();
|
||||
TerraBiome biome = provider.getBiome(carving.getRunning().toLocation(w));
|
||||
if(!((UserDefinedBiome) biome).getConfig().getCarvers().containsKey(CarverCache.this.carver)) { // Stop if we enter a biome this carver is not present in
|
||||
return new GlueList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
points.add(carving.getPoint());
|
||||
}
|
||||
return points;
|
||||
}
|
||||
return new GlueList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@@ -14,6 +15,7 @@ public class CarverPalette {
|
||||
private final MaterialSet replace;
|
||||
private final TreeMap<Integer, ProbabilityCollection<BlockData>> map = new TreeMap<>();
|
||||
private ProbabilityCollection<BlockData>[] layers;
|
||||
private int offset = 0;
|
||||
|
||||
public CarverPalette(MaterialSet replaceable, boolean blacklist) {
|
||||
this.blacklist = blacklist;
|
||||
@@ -26,7 +28,12 @@ public class CarverPalette {
|
||||
}
|
||||
|
||||
public ProbabilityCollection<BlockData> get(int y) {
|
||||
return layers[y];
|
||||
int index = y + offset;
|
||||
return index >= 0
|
||||
? index < layers.length
|
||||
? layers[index]
|
||||
: layers[layers.length - 1]
|
||||
: layers[0];
|
||||
}
|
||||
|
||||
public boolean canReplace(BlockType material) {
|
||||
@@ -37,9 +44,11 @@ public class CarverPalette {
|
||||
* Build the palette to an array.
|
||||
*/
|
||||
public void build() {
|
||||
int size = map.lastKey() + 1;
|
||||
layers = new ProbabilityCollection[size];
|
||||
for(int y = 0; y < size; y++) {
|
||||
int min = FastMath.min(map.keySet().stream().min(Integer::compareTo).orElse(0), 0);
|
||||
int max = FastMath.max(map.keySet().stream().max(Integer::compareTo).orElse(255), 255);
|
||||
|
||||
layers = new ProbabilityCollection[map.lastKey() + 1 - min];
|
||||
for(int y = min; y <= FastMath.max(map.lastKey(), max); y++) {
|
||||
ProbabilityCollection<BlockData> d = null;
|
||||
for(Map.Entry<Integer, ProbabilityCollection<BlockData>> e : map.entrySet()) {
|
||||
if(e.getKey() >= y) {
|
||||
@@ -47,8 +56,9 @@ public class CarverPalette {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(d == null) throw new IllegalArgumentException("Null collection at Y=" + y);
|
||||
layers[y] = d;
|
||||
if(d == null) throw new IllegalArgumentException("No palette for Y=" + y);
|
||||
layers[y - min] = d;
|
||||
}
|
||||
offset = -min;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class UserDefinedCarver extends Carver {
|
||||
Vector3 origin = point.getOrigin();
|
||||
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ) // We only want to carve this chunk.
|
||||
return;
|
||||
point.carve(chunkX, chunkZ, consumer);
|
||||
point.carve(chunkX, chunkZ, consumer, w);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ import com.dfsek.terra.config.loaders.LinkedHashMapLoader;
|
||||
import com.dfsek.terra.config.loaders.MaterialSetLoader;
|
||||
import com.dfsek.terra.config.loaders.ProbabilityCollectionLoader;
|
||||
import com.dfsek.terra.config.loaders.RangeLoader;
|
||||
import com.dfsek.terra.config.loaders.config.FloraLayerLoader;
|
||||
import com.dfsek.terra.config.loaders.config.GridSpawnLoader;
|
||||
import com.dfsek.terra.config.loaders.config.OreConfigLoader;
|
||||
import com.dfsek.terra.config.loaders.config.FloraLayerTemplate;
|
||||
import com.dfsek.terra.config.loaders.config.GridSpawnTemplate;
|
||||
import com.dfsek.terra.config.loaders.config.OreConfigTemplate;
|
||||
import com.dfsek.terra.config.loaders.config.OreHolderLoader;
|
||||
import com.dfsek.terra.config.loaders.config.TreeLayerLoader;
|
||||
import com.dfsek.terra.config.loaders.config.TreeLayerTemplate;
|
||||
import com.dfsek.terra.config.loaders.config.biome.BiomeProviderBuilderLoader;
|
||||
import com.dfsek.terra.config.loaders.config.biome.SourceBuilderLoader;
|
||||
import com.dfsek.terra.config.loaders.config.biome.StageBuilderLoader;
|
||||
@@ -69,13 +69,13 @@ public class GenericLoaders implements LoaderRegistrar {
|
||||
public void register(TypeRegistry registry) {
|
||||
registry.registerLoader(ProbabilityCollection.class, new ProbabilityCollectionLoader())
|
||||
.registerLoader(Range.class, new RangeLoader())
|
||||
.registerLoader(GridSpawn.class, new GridSpawnLoader())
|
||||
.registerLoader(GridSpawn.class, GridSpawnTemplate::new)
|
||||
.registerLoader(PaletteHolder.class, new PaletteHolderLoader())
|
||||
.registerLoader(PaletteLayerHolder.class, new PaletteLayerLoader())
|
||||
.registerLoader(FloraLayer.class, new FloraLayerLoader())
|
||||
.registerLoader(FloraLayer.class, FloraLayerTemplate::new)
|
||||
.registerLoader(Ore.Type.class, (t, o, l) -> Ore.Type.valueOf(o.toString()))
|
||||
.registerLoader(OreConfig.class, new OreConfigLoader())
|
||||
.registerLoader(TreeLayer.class, new TreeLayerLoader())
|
||||
.registerLoader(OreConfig.class, OreConfigTemplate::new)
|
||||
.registerLoader(TreeLayer.class, TreeLayerTemplate::new)
|
||||
.registerLoader(MaterialSet.class, new MaterialSetLoader())
|
||||
.registerLoader(OreHolder.class, new OreHolderLoader())
|
||||
.registerLoader(ImageSamplerTemplate.class, ImageSamplerTemplate::new)
|
||||
|
||||
@@ -13,9 +13,9 @@ public class OreFactory implements ConfigFactory<OreTemplate, Ore> {
|
||||
BlockData m = config.getMaterial();
|
||||
switch(config.getType()) {
|
||||
case SPHERE:
|
||||
return new DeformedSphereOre(m, config.getReplaceable(), config.doPhysics(), config.getDeform(), config.getDeformFrequency(), config.getSize(), main);
|
||||
return new DeformedSphereOre(m, config.getReplaceable(), config.doPhysics(), config.getDeform(), config.getDeformFrequency(), config.getSize(), main, config.getMaterialOverrides());
|
||||
case VANILLA:
|
||||
return new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize(), main);
|
||||
return new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize(), main, config.getMaterialOverrides());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.world.flora.Flora;
|
||||
import com.dfsek.terra.config.loaders.Types;
|
||||
import com.dfsek.terra.world.population.items.flora.FloraLayer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class FloraLayerLoader implements TypeLoader<FloraLayer> {
|
||||
@Override
|
||||
public FloraLayer load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
double density = ((Number) map.get("density")).doubleValue();
|
||||
Range range = configLoader.loadClass(Range.class, map.get("y"));
|
||||
if(range == null) throw new LoadException("Flora range unspecified");
|
||||
ProbabilityCollection<Flora> items = (ProbabilityCollection<Flora>) configLoader.loadType(Types.FLORA_PROBABILITY_COLLECTION_TYPE, map.get("items"));
|
||||
|
||||
NoiseSeeded sampler;
|
||||
if(map.containsKey("distribution")) {
|
||||
try {
|
||||
sampler = configLoader.loadClass(NoiseSeeded.class, map.get("distribution"));
|
||||
} catch(ConfigException e) {
|
||||
throw new LoadException("Unable to load noise", e);
|
||||
}
|
||||
return new FloraLayer(density, range, items, sampler.apply(2403L));
|
||||
}
|
||||
|
||||
return new FloraLayer(density, range, items, new WhiteNoiseSampler(2403));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.world.flora.Flora;
|
||||
import com.dfsek.terra.world.population.items.flora.FloraLayer;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class FloraLayerTemplate implements ObjectTemplate<FloraLayer> {
|
||||
@Value("density")
|
||||
private MetaValue<Double> density;
|
||||
|
||||
@Value("y")
|
||||
private MetaValue<Range> range;
|
||||
|
||||
@Value("items")
|
||||
private ProbabilityCollection<Flora> items;
|
||||
|
||||
@Value("distribution")
|
||||
@Default
|
||||
private MetaValue<NoiseSeeded> sampler = MetaValue.of(new NoiseSeeded() {
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
return new WhiteNoiseSampler(seed.intValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDimensions() {
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public FloraLayer get() {
|
||||
return new FloraLayer(density.get(), range.get(), items, sampler.get().apply(2403L));
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.math.GridSpawn;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class GridSpawnLoader implements TypeLoader<GridSpawn> {
|
||||
@Override
|
||||
public GridSpawn load(Type type, Object o, ConfigLoader configLoader) {
|
||||
Map<String, Integer> map = (Map<String, Integer>) o;
|
||||
return new GridSpawn(map.get("width"), map.get("padding"), map.getOrDefault("salt", 0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.GridSpawn;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class GridSpawnTemplate implements ObjectTemplate<GridSpawn> {
|
||||
@Value("width")
|
||||
private MetaValue<Integer> width;
|
||||
|
||||
@Value("padding")
|
||||
private MetaValue<Integer> padding;
|
||||
|
||||
@Value("salt")
|
||||
@Default
|
||||
private MetaValue<Integer> salt = MetaValue.of(0);
|
||||
|
||||
@Override
|
||||
public GridSpawn get() {
|
||||
return new GridSpawn(width.get(), padding.get(), salt.get());
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.world.population.items.ores.OreConfig;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class OreConfigLoader implements TypeLoader<OreConfig> {
|
||||
@Override
|
||||
public OreConfig load(Type type, Object o, ConfigLoader configLoader) {
|
||||
Map<String, Integer> map = (Map<String, Integer>) o;
|
||||
Range amount = new Range(map.get("min"), map.get("max"));
|
||||
Range height = new Range(map.get("min-height"), map.get("max-height"));
|
||||
return new OreConfig(amount, height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.world.population.items.ores.OreConfig;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class OreConfigTemplate implements ObjectTemplate<OreConfig> {
|
||||
@Value("min")
|
||||
private MetaValue<Integer> min;
|
||||
|
||||
@Value("max")
|
||||
private MetaValue<Integer> max;
|
||||
|
||||
@Value("min-height")
|
||||
private MetaValue<Integer> minHeight;
|
||||
|
||||
@Value("max-height")
|
||||
private MetaValue<Integer> maxHeight;
|
||||
|
||||
@Override
|
||||
public OreConfig get() {
|
||||
return new OreConfig(new Range(min.get(), max.get()), new Range(minHeight.get(), maxHeight.get()));
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler;
|
||||
import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.config.loaders.Types;
|
||||
import com.dfsek.terra.world.population.items.tree.TreeLayer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class TreeLayerLoader implements TypeLoader<TreeLayer> {
|
||||
@Override
|
||||
public TreeLayer load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
double density = ((Number) map.get("density")).doubleValue();
|
||||
Range range = configLoader.loadClass(Range.class, map.get("y"));
|
||||
if(range == null) throw new LoadException("Tree range unspecified");
|
||||
ProbabilityCollection<Tree> items = (ProbabilityCollection<Tree>) configLoader.loadType(Types.TREE_PROBABILITY_COLLECTION_TYPE, map.get("items"));
|
||||
|
||||
if(map.containsKey("distribution")) {
|
||||
NoiseSeeded noise = configLoader.loadClass(NoiseSeeded.class, map.get("distribution"));
|
||||
return new TreeLayer(density, range, items, noise.apply(2403L));
|
||||
}
|
||||
|
||||
return new TreeLayer(density, range, items, new WhiteNoiseSampler(2403));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.dfsek.terra.config.loaders.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler;
|
||||
import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.world.population.items.tree.TreeLayer;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
public class TreeLayerTemplate implements ObjectTemplate<TreeLayer> {
|
||||
@Value("density")
|
||||
private MetaValue<Double> density;
|
||||
|
||||
@Value("y")
|
||||
private MetaValue<Range> range;
|
||||
|
||||
@Value("items")
|
||||
private ProbabilityCollection<Tree> items;
|
||||
|
||||
@Value("distribution")
|
||||
@Default
|
||||
private MetaValue<NoiseSeeded> sampler = MetaValue.of(new NoiseSeeded() {
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
return new WhiteNoiseSampler(seed.intValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDimensions() {
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public TreeLayer get() {
|
||||
return new TreeLayer(density.get(), range.get(), items, sampler.get().apply(2403L));
|
||||
}
|
||||
}
|
||||
+8
-7
@@ -3,6 +3,7 @@ package com.dfsek.terra.config.loaders.config.biome.templates.provider;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.util.seeded.SourceSeeded;
|
||||
import com.dfsek.terra.api.util.seeded.StageSeeded;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.BiomePipeline;
|
||||
@@ -16,13 +17,13 @@ public class BiomePipelineTemplate extends BiomeProviderTemplate {
|
||||
private final TerraPlugin main;
|
||||
@Value("pipeline.initial-size")
|
||||
@Default
|
||||
private int initialSize = 2;
|
||||
private MetaValue<Integer> initialSize = MetaValue.of(2);
|
||||
|
||||
@Value("pipeline.stages")
|
||||
private List<StageSeeded> stages;
|
||||
private List<MetaValue<StageSeeded>> stages;
|
||||
|
||||
@Value("pipeline.source")
|
||||
private SourceSeeded source;
|
||||
private MetaValue<SourceSeeded> source;
|
||||
|
||||
public BiomePipelineTemplate(TerraPlugin main) {
|
||||
this.main = main;
|
||||
@@ -30,9 +31,9 @@ public class BiomePipelineTemplate extends BiomeProviderTemplate {
|
||||
|
||||
@Override
|
||||
public BiomeProvider build(long seed) {
|
||||
BiomePipeline.BiomePipelineBuilder biomePipelineBuilder = new BiomePipeline.BiomePipelineBuilder(initialSize);
|
||||
stages.forEach(biomePipelineBuilder::addStage);
|
||||
BiomePipeline pipeline = biomePipelineBuilder.build(source.apply(seed), seed);
|
||||
return new StandardBiomeProvider(pipeline, main, resolution, blend.apply(seed), blendAmp, (int) seed);
|
||||
BiomePipeline.BiomePipelineBuilder biomePipelineBuilder = new BiomePipeline.BiomePipelineBuilder(initialSize.get());
|
||||
stages.stream().map(MetaValue::get).forEach(biomePipelineBuilder::addStage);
|
||||
BiomePipeline pipeline = biomePipelineBuilder.build(source.get().apply(seed), seed);
|
||||
return new StandardBiomeProvider(pipeline, main, resolution.get(), blend.get().apply(seed), blendAmp.get(), (int) seed);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-5
@@ -3,6 +3,7 @@ package com.dfsek.terra.config.loaders.config.biome.templates.provider;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
@@ -11,10 +12,11 @@ import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
|
||||
public abstract class BiomeProviderTemplate implements ObjectTemplate<BiomeProvider.BiomeProviderBuilder>, BiomeProvider.BiomeProviderBuilder {
|
||||
@Value("resolution")
|
||||
@Default
|
||||
protected int resolution = 1;
|
||||
protected MetaValue<Integer> resolution = MetaValue.of(1);
|
||||
|
||||
@Value("blend.noise")
|
||||
@Default
|
||||
protected NoiseSeeded blend = new NoiseSeeded() {
|
||||
protected MetaValue<NoiseSeeded> blend = MetaValue.of(new NoiseSeeded() {
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
return new ConstantSampler(0);
|
||||
@@ -24,12 +26,14 @@ public abstract class BiomeProviderTemplate implements ObjectTemplate<BiomeProvi
|
||||
public int getDimensions() {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@Value("blend.amplitude")
|
||||
@Default
|
||||
protected double blendAmp = 0d;
|
||||
protected MetaValue<Double> blendAmp = MetaValue.of(0d);
|
||||
|
||||
@Value("type")
|
||||
BiomeProvider.Type type;
|
||||
protected MetaValue<BiomeProvider.Type> type;
|
||||
|
||||
@Override
|
||||
public BiomeProvider.BiomeProviderBuilder get() {
|
||||
|
||||
+5
-3
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.provider;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.biome.provider.ImageBiomeProvider;
|
||||
@@ -9,13 +10,14 @@ import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ImageProviderTemplate extends BiomeProviderTemplate {
|
||||
private final Registry<BiomeBuilder> biomes;
|
||||
@Value("image.name")
|
||||
private BufferedImage image;
|
||||
private MetaValue<BufferedImage> image;
|
||||
|
||||
@Value("image.align")
|
||||
private ImageBiomeProvider.Align align;
|
||||
private MetaValue<ImageBiomeProvider.Align> align;
|
||||
|
||||
public ImageProviderTemplate(Registry<BiomeBuilder> set) {
|
||||
this.biomes = set;
|
||||
@@ -23,6 +25,6 @@ public class ImageProviderTemplate extends BiomeProviderTemplate {
|
||||
|
||||
@Override
|
||||
public BiomeProvider build(long seed) {
|
||||
return new ImageBiomeProvider(biomes.entries().stream().map(biomeBuilder -> biomeBuilder.apply(seed)).collect(Collectors.toSet()), image, resolution, align);
|
||||
return new ImageBiomeProvider(biomes.entries().stream().map(biomeBuilder -> biomeBuilder.apply(seed)).collect(Collectors.toSet()), image.get(), resolution.get(), align.get());
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -1,19 +1,21 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.provider;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.biome.provider.SingleBiomeProvider;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class SingleBiomeProviderTemplate extends BiomeProviderTemplate {
|
||||
@Value("biome")
|
||||
private BiomeBuilder biome;
|
||||
private MetaValue<BiomeBuilder> biome;
|
||||
|
||||
public SingleBiomeProviderTemplate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeProvider build(long seed) {
|
||||
return new SingleBiomeProvider(biome.apply(seed));
|
||||
return new SingleBiomeProvider(biome.get().apply(seed));
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -1,21 +1,23 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.source;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.source.RandomSource;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class NoiseSourceTemplate extends SourceTemplate {
|
||||
@Value("noise")
|
||||
private NoiseSeeded noise;
|
||||
private MetaValue<NoiseSeeded> noise;
|
||||
|
||||
@Value("biomes")
|
||||
private ProbabilityCollection<BiomeBuilder> biomes;
|
||||
private ProbabilityCollection<MetaValue<BiomeBuilder>> biomes;
|
||||
|
||||
@Override
|
||||
public BiomeSource apply(Long seed) {
|
||||
return new RandomSource(biomes.map((biome) -> biome.apply(seed), false), noise.apply(seed));
|
||||
return new RandomSource(biomes.map((biome) -> biome.get().apply(seed), false), noise.get().apply(seed));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.util.seeded.SeededBuilder;
|
||||
import com.dfsek.terra.api.util.seeded.StageSeeded;
|
||||
@@ -9,7 +10,7 @@ import com.dfsek.terra.api.world.biome.pipeline.stages.Stage;
|
||||
|
||||
public abstract class StageTemplate implements ObjectTemplate<SeededBuilder<Stage>>, StageSeeded {
|
||||
@Value("noise")
|
||||
protected NoiseSeeded noise;
|
||||
protected MetaValue<NoiseSeeded> noise;
|
||||
|
||||
@Override
|
||||
public StageSeeded get() {
|
||||
|
||||
+1
-1
@@ -8,6 +8,6 @@ import com.dfsek.terra.config.loaders.config.biome.templates.stage.StageTemplate
|
||||
public class ExpanderStageTemplate extends StageTemplate {
|
||||
@Override
|
||||
public Stage apply(Long seed) {
|
||||
return new ExpanderStage(new FractalExpander(noise.apply(seed)));
|
||||
return new ExpanderStage(new FractalExpander(noise.get().apply(seed)));
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator;
|
||||
@@ -13,24 +14,24 @@ import java.util.Map;
|
||||
@SuppressWarnings("unused")
|
||||
public class BorderListMutatorTemplate extends MutatorStageTemplate {
|
||||
@Value("from")
|
||||
private String from;
|
||||
private MetaValue<String> from;
|
||||
|
||||
@Value("default-replace")
|
||||
private String defaultReplace;
|
||||
private MetaValue<String> defaultReplace;
|
||||
|
||||
@Value("default-to")
|
||||
private ProbabilityCollection<BiomeBuilder> defaultTo;
|
||||
private ProbabilityCollection<MetaValue<BiomeBuilder>> defaultTo;
|
||||
|
||||
@Value("replace")
|
||||
private Map<BiomeBuilder, ProbabilityCollection<BiomeBuilder>> replace;
|
||||
private Map<BiomeBuilder, ProbabilityCollection<MetaValue<BiomeBuilder>>> replace;
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeMutator build(long seed) {
|
||||
Map<TerraBiome, ProbabilityCollection<TerraBiome>> replaceMap = new HashMap<>();
|
||||
|
||||
replace.forEach((keyBuilder, replacements) -> replaceMap.put(keyBuilder.apply(seed), replacements.map(replacement -> replacement.apply(seed), true)));
|
||||
replace.forEach((keyBuilder, replacements) -> replaceMap.put(keyBuilder.apply(seed), replacements.map(MetaValue::get).map(replacement -> replacement.apply(seed))));
|
||||
|
||||
return new BorderListMutator(replaceMap, from, defaultReplace, noise.apply(seed), defaultTo.map(biomeBuilder -> biomeBuilder.apply(seed), true));
|
||||
return new BorderListMutator(replaceMap, from.get(), defaultReplace.get(), noise.get().apply(seed), defaultTo.map(MetaValue::get).map(biomeBuilder -> biomeBuilder.apply(seed)));
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.mutator.BorderMutator;
|
||||
@@ -9,16 +10,16 @@ import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
@SuppressWarnings("unused")
|
||||
public class BorderMutatorTemplate extends MutatorStageTemplate {
|
||||
@Value("from")
|
||||
private String from;
|
||||
private MetaValue<String> from;
|
||||
|
||||
@Value("replace")
|
||||
private String replace;
|
||||
private MetaValue<String> replace;
|
||||
|
||||
@Value("to")
|
||||
private ProbabilityCollection<BiomeBuilder> to;
|
||||
private ProbabilityCollection<MetaValue<BiomeBuilder>> to;
|
||||
|
||||
@Override
|
||||
public BiomeMutator build(long seed) {
|
||||
return new BorderMutator(from, replace, noise.apply(seed), to.map(biomeBuilder -> biomeBuilder.apply(seed), true));
|
||||
return new BorderMutator(from.get(), replace.get(), noise.get().apply(seed), to.map(MetaValue::get).map(biomeBuilder -> biomeBuilder.apply(seed)));
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator;
|
||||
@@ -13,20 +14,20 @@ import java.util.Map;
|
||||
@SuppressWarnings("unused")
|
||||
public class ReplaceListMutatorTemplate extends MutatorStageTemplate {
|
||||
@Value("default-from")
|
||||
private String defaultFrom;
|
||||
private MetaValue<String> defaultFrom;
|
||||
|
||||
@Value("default-to")
|
||||
private ProbabilityCollection<BiomeBuilder> defaultTo;
|
||||
private ProbabilityCollection<MetaValue<BiomeBuilder>> defaultTo;
|
||||
|
||||
@Value("to")
|
||||
private Map<BiomeBuilder, ProbabilityCollection<BiomeBuilder>> replace;
|
||||
private Map<BiomeBuilder, ProbabilityCollection<MetaValue<BiomeBuilder>>> replace;
|
||||
|
||||
@Override
|
||||
public BiomeMutator build(long seed) {
|
||||
Map<TerraBiome, ProbabilityCollection<TerraBiome>> replaceMap = new HashMap<>();
|
||||
|
||||
replace.forEach((biomeBuilder, biomeBuilders) -> replaceMap.put(biomeBuilder.apply(seed), biomeBuilders.map(builder -> builder.apply(seed), true)));
|
||||
replace.forEach((biomeBuilder, biomeBuilders) -> replaceMap.put(biomeBuilder.apply(seed), biomeBuilders.map(MetaValue::get).map(builder -> builder.apply(seed))));
|
||||
|
||||
return new ReplaceListMutator(replaceMap, defaultFrom, defaultTo.map(biomeBuilder -> biomeBuilder.apply(seed), true), noise.apply(seed));
|
||||
return new ReplaceListMutator(replaceMap, defaultFrom.get(), defaultTo.map(MetaValue::get).map(biomeBuilder -> biomeBuilder.apply(seed)), noise.get().apply(seed));
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.mutator.ReplaceMutator;
|
||||
@@ -9,13 +10,13 @@ import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
@SuppressWarnings("unused")
|
||||
public class ReplaceMutatorTemplate extends MutatorStageTemplate {
|
||||
@Value("from")
|
||||
private String from;
|
||||
private MetaValue<String> from;
|
||||
|
||||
@Value("to")
|
||||
private ProbabilityCollection<BiomeBuilder> to;
|
||||
private ProbabilityCollection<MetaValue<BiomeBuilder>> to;
|
||||
|
||||
@Override
|
||||
public BiomeMutator build(long seed) {
|
||||
return new ReplaceMutator(from, to.map(biomeBuilder -> biomeBuilder.apply(seed), true), noise.apply(seed));
|
||||
return new ReplaceMutator(from.get(), to.map(MetaValue::get).map(biomeBuilder -> biomeBuilder.apply(seed)), noise.get().apply(seed));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,6 +6,6 @@ import com.dfsek.terra.api.world.biome.pipeline.mutator.SmoothMutator;
|
||||
public class SmoothMutatorTemplate extends MutatorStageTemplate {
|
||||
@Override
|
||||
public BiomeMutator build(long seed) {
|
||||
return new SmoothMutator(noise.apply(seed));
|
||||
return new SmoothMutator(noise.get().apply(seed));
|
||||
}
|
||||
}
|
||||
|
||||
+20
-2
@@ -1,17 +1,20 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.registry.config.NoiseRegistry;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class NoiseSamplerBuilderLoader implements TypeLoader<NoiseSeeded> {
|
||||
@@ -25,11 +28,26 @@ public class NoiseSamplerBuilderLoader implements TypeLoader<NoiseSeeded> {
|
||||
public NoiseSeeded load(Type t, Object c, ConfigLoader loader) throws LoadException {
|
||||
Map<String, Object> map = (Map<String, Object>) c;
|
||||
try {
|
||||
ObjectTemplate<NoiseSeeded> normalizerTemplate = noiseRegistry.get(((String) map.get("type")).toUpperCase(Locale.ROOT)).get();
|
||||
loader.load(normalizerTemplate, new Configuration(map));
|
||||
Template typeTemplate = new Template();
|
||||
Configuration configuration = new Configuration(map);
|
||||
loader.load(typeTemplate, configuration);
|
||||
ObjectTemplate<NoiseSeeded> normalizerTemplate = typeTemplate.get().get();
|
||||
loader.load(normalizerTemplate, configuration);
|
||||
return normalizerTemplate.get();
|
||||
} catch(ConfigException e) {
|
||||
throw new LoadException("Unable to load noise function: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private class Template implements ObjectTemplate<Supplier<ObjectTemplate<NoiseSeeded>>> {
|
||||
@Value("type")
|
||||
private MetaValue<String> type;
|
||||
|
||||
|
||||
@Override
|
||||
public Supplier<ObjectTemplate<NoiseSeeded>> get() {
|
||||
return noiseRegistry.get(type.get().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -2,6 +2,7 @@ package com.dfsek.terra.config.loaders.config.sampler.templates;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.DomainWarpedSampler;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
@@ -9,21 +10,21 @@ import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class DomainWarpTemplate extends SamplerTemplate<DomainWarpedSampler> {
|
||||
@Value("warp")
|
||||
private NoiseSeeded warp;
|
||||
private MetaValue<NoiseSeeded> warp;
|
||||
|
||||
@Value("function")
|
||||
private NoiseSeeded function;
|
||||
private MetaValue<NoiseSeeded> function;
|
||||
|
||||
@Value("salt")
|
||||
@Default
|
||||
private int salt = 0;
|
||||
private MetaValue<Integer> salt = MetaValue.of(0);
|
||||
|
||||
@Value("amplitude")
|
||||
@Default
|
||||
private double amplitude = 1;
|
||||
private MetaValue<Double> amplitude = MetaValue.of(1d);
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
return new DomainWarpedSampler(function.apply(seed), warp.apply(seed), (int) (seed + salt), amplitude);
|
||||
return new DomainWarpedSampler(function.get().apply(seed), warp.get().apply(seed), (int) (seed + salt.get()), amplitude.get());
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler.templates;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.ImageSampler;
|
||||
|
||||
@@ -10,16 +11,16 @@ import java.awt.image.BufferedImage;
|
||||
public class ImageSamplerTemplate extends SamplerTemplate<ImageSampler> {
|
||||
|
||||
@Value("image")
|
||||
private BufferedImage image;
|
||||
private MetaValue<BufferedImage> image;
|
||||
|
||||
@Value("frequency")
|
||||
private double frequency;
|
||||
private MetaValue<Double> frequency;
|
||||
|
||||
@Value("channel")
|
||||
private ImageSampler.Channel channel;
|
||||
private MetaValue<ImageSampler.Channel> channel;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
return new ImageSampler(image, channel, frequency);
|
||||
return new ImageSampler(image.get(), channel.get(), frequency.get());
|
||||
}
|
||||
}
|
||||
|
||||
+8
-7
@@ -4,6 +4,7 @@ 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.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.KernelSampler;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
@@ -14,18 +15,18 @@ import java.util.List;
|
||||
public class KernelTemplate extends SamplerTemplate<KernelSampler> implements ValidatedConfigTemplate {
|
||||
|
||||
@Value("kernel")
|
||||
private List<List<Double>> kernel;
|
||||
private List<List<MetaValue<Double>>> kernel;
|
||||
|
||||
@Value("factor")
|
||||
@Default
|
||||
private double factor = 1;
|
||||
private MetaValue<Double> factor = MetaValue.of(1d);
|
||||
|
||||
@Value("function")
|
||||
private NoiseSeeded function;
|
||||
private MetaValue<NoiseSeeded> function;
|
||||
|
||||
@Value("frequency")
|
||||
@Default
|
||||
private double frequency = 1;
|
||||
private MetaValue<Double> frequency = MetaValue.of(1d);
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
@@ -33,12 +34,12 @@ public class KernelTemplate extends SamplerTemplate<KernelSampler> implements Va
|
||||
|
||||
for(int x = 0; x < kernel.size(); x++) {
|
||||
for(int y = 0; y < kernel.get(x).size(); y++) {
|
||||
k[x][y] = kernel.get(x).get(y) * factor;
|
||||
k[x][y] = kernel.get(x).get(y).get() * factor.get();
|
||||
}
|
||||
}
|
||||
|
||||
KernelSampler sampler = new KernelSampler(k, function.apply(seed));
|
||||
sampler.setFrequency(frequency);
|
||||
KernelSampler sampler = new KernelSampler(k, function.get().apply(seed));
|
||||
sampler.setFrequency(frequency.get());
|
||||
return sampler;
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -5,6 +5,7 @@ import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
|
||||
@@ -12,15 +13,15 @@ import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
public abstract class SamplerTemplate<T extends NoiseSampler> implements ValidatedConfigTemplate, ObjectTemplate<NoiseSeeded>, NoiseSeeded {
|
||||
@Value("dimensions")
|
||||
@Default
|
||||
private int dimensions = 2;
|
||||
private MetaValue<Integer> dimensions = MetaValue.of(2);
|
||||
|
||||
public int getDimensions() {
|
||||
return dimensions;
|
||||
return dimensions.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
if(dimensions != 2 && dimensions != 3) throw new ValidationException("Illegal amount of dimensions: " + dimensions);
|
||||
if(dimensions.get() != 2 && dimensions.get() != 3) throw new ValidationException("Illegal amount of dimensions: " + dimensions);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+12
-11
@@ -2,6 +2,7 @@ package com.dfsek.terra.config.loaders.config.sampler.templates.noise;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.CellularSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.simplex.OpenSimplex2Sampler;
|
||||
@@ -11,20 +12,20 @@ import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
public class CellularNoiseTemplate extends NoiseTemplate<CellularSampler> {
|
||||
@Value("distance")
|
||||
@Default
|
||||
private CellularSampler.DistanceFunction cellularDistanceFunction = CellularSampler.DistanceFunction.EuclideanSq;
|
||||
private MetaValue<CellularSampler.DistanceFunction> cellularDistanceFunction = MetaValue.of(CellularSampler.DistanceFunction.EuclideanSq);
|
||||
|
||||
@Value("return")
|
||||
@Default
|
||||
private CellularSampler.ReturnType cellularReturnType = CellularSampler.ReturnType.Distance;
|
||||
private MetaValue<CellularSampler.ReturnType> cellularReturnType = MetaValue.of(CellularSampler.ReturnType.Distance);
|
||||
|
||||
@Value("jitter")
|
||||
@Default
|
||||
private double cellularJitter = 1.0D;
|
||||
private MetaValue<Double> cellularJitter = MetaValue.of(1.0D);
|
||||
|
||||
|
||||
@Value("lookup")
|
||||
@Default
|
||||
private NoiseSeeded lookup = new NoiseSeeded() {
|
||||
private MetaValue<NoiseSeeded> lookup = MetaValue.of(new NoiseSeeded() {
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
|
||||
@@ -35,16 +36,16 @@ public class CellularNoiseTemplate extends NoiseTemplate<CellularSampler> {
|
||||
public int getDimensions() {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
CellularSampler sampler = new CellularSampler((int) (long) seed + salt);
|
||||
sampler.setNoiseLookup(lookup.apply(seed));
|
||||
sampler.setFrequency(frequency);
|
||||
sampler.setJitterModifier(cellularJitter);
|
||||
sampler.setReturnType(cellularReturnType);
|
||||
sampler.setDistanceFunction(cellularDistanceFunction);
|
||||
CellularSampler sampler = new CellularSampler((int) (long) seed + salt.get());
|
||||
sampler.setNoiseLookup(lookup.get().apply(seed));
|
||||
sampler.setFrequency(frequency.get());
|
||||
sampler.setJitterModifier(cellularJitter.get());
|
||||
sampler.setReturnType(cellularReturnType.get());
|
||||
sampler.setDistanceFunction(cellularDistanceFunction.get());
|
||||
return sampler;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -2,6 +2,7 @@ package com.dfsek.terra.config.loaders.config.sampler.templates.noise;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
||||
@@ -10,10 +11,10 @@ import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
||||
public class ConstantNoiseTemplate extends SamplerTemplate<ConstantSampler> {
|
||||
@Value("value")
|
||||
@Default
|
||||
private double value = 0d;
|
||||
private MetaValue<Double> value = MetaValue.of(0d);
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
return new ConstantSampler(value);
|
||||
return new ConstantSampler(value.get());
|
||||
}
|
||||
}
|
||||
|
||||
+12
-11
@@ -8,12 +8,13 @@ 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.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.ExpressionFunction;
|
||||
import com.dfsek.terra.api.math.paralithic.BlankFunction;
|
||||
import com.dfsek.terra.api.math.paralithic.defined.UserDefinedFunction;
|
||||
import com.dfsek.terra.api.math.paralithic.noise.NoiseFunction2;
|
||||
import com.dfsek.terra.api.math.paralithic.noise.NoiseFunction3;
|
||||
import com.dfsek.terra.api.util.MapUtil;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
||||
@@ -27,24 +28,24 @@ import java.util.Map;
|
||||
public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFunction> implements ValidatedConfigTemplate {
|
||||
@Value("variables")
|
||||
@Default
|
||||
private Map<String, Double> vars = new HashMap<>();
|
||||
private Map<String, MetaValue<Double>> vars = new HashMap<>();
|
||||
|
||||
@Value("equation")
|
||||
private String equation;
|
||||
private MetaValue<String> equation;
|
||||
|
||||
@Value("functions")
|
||||
@Default
|
||||
private LinkedHashMap<String, NoiseSeeded> functions = new LinkedHashMap<>();
|
||||
private LinkedHashMap<String, MetaValue<NoiseSeeded>> functions = new LinkedHashMap<>();
|
||||
|
||||
@Value("expressions")
|
||||
@Default
|
||||
private LinkedHashMap<String, FunctionTemplate> expressions = new LinkedHashMap<>();
|
||||
private LinkedHashMap<String, MetaValue<FunctionTemplate>> expressions = new LinkedHashMap<>();
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
try {
|
||||
Map<String, Function> noiseFunctionMap = generateFunctions(seed);
|
||||
return new ExpressionFunction(noiseFunctionMap, equation, vars);
|
||||
return new ExpressionFunction(noiseFunctionMap, equation.get(), MapUtil.remapValues(MetaValue::get, vars));
|
||||
} catch(ParseException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
@@ -54,7 +55,7 @@ public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFuncti
|
||||
public boolean validate() throws ValidationException {
|
||||
try {
|
||||
Map<String, Function> noiseFunctionMap = generateFunctions(0L);
|
||||
new ExpressionFunction(noiseFunctionMap, equation, vars);
|
||||
new ExpressionFunction(noiseFunctionMap, equation.get(), MapUtil.remapValues(MetaValue::get, vars));
|
||||
} catch(ParseException e) {
|
||||
throw new ValidationException("Errors occurred while parsing noise equation: ", e);
|
||||
}
|
||||
@@ -64,14 +65,14 @@ public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFuncti
|
||||
private Map<String, Function> generateFunctions(Long seed) throws ParseException {
|
||||
Map<String, Function> noiseFunctionMap = new HashMap<>();
|
||||
|
||||
for(Map.Entry<String, FunctionTemplate> entry : expressions.entrySet()) {
|
||||
for(Map.Entry<String, FunctionTemplate> entry : MapUtil.remapValues(MetaValue::get, expressions).entrySet()) {
|
||||
noiseFunctionMap.put(entry.getKey(), UserDefinedFunction.newInstance(entry.getValue(), new Parser(), new Scope()));
|
||||
}
|
||||
|
||||
functions.forEach((id, function) -> {
|
||||
if(function.getDimensions() == 2) {
|
||||
noiseFunctionMap.put(id, new NoiseFunction2(function.apply(seed)));
|
||||
} else noiseFunctionMap.put(id, new NoiseFunction3(function.apply(seed)));
|
||||
if(function.get().getDimensions() == 2) {
|
||||
noiseFunctionMap.put(id, new NoiseFunction2(function.get().apply(seed)));
|
||||
} else noiseFunctionMap.put(id, new NoiseFunction3(function.get().apply(seed)));
|
||||
});
|
||||
|
||||
return noiseFunctionMap;
|
||||
|
||||
+14
-12
@@ -2,39 +2,41 @@ package com.dfsek.terra.config.loaders.config.sampler.templates.noise;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.GaborNoiseSampler;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class GaborNoiseTemplate extends NoiseTemplate<GaborNoiseSampler> {
|
||||
@Value("rotation")
|
||||
@Default
|
||||
private double rotation = 0.25;
|
||||
private MetaValue<Double> rotation = MetaValue.of(0.25);
|
||||
|
||||
@Value("isotropic")
|
||||
@Default
|
||||
private boolean isotropic = true;
|
||||
private MetaValue<Boolean> isotropic = MetaValue.of(true);
|
||||
|
||||
@Value("deviation")
|
||||
@Default
|
||||
private double deviation = 1.0;
|
||||
private MetaValue<Double> deviation = MetaValue.of(1.0);
|
||||
|
||||
@Value("impulses")
|
||||
@Default
|
||||
private double impulses = 64d;
|
||||
private MetaValue<Double> impulses = MetaValue.of(64d);
|
||||
|
||||
@Value("frequency_0")
|
||||
@Default
|
||||
private double f0 = 0.625;
|
||||
private MetaValue<Double> f0 = MetaValue.of(0.625);
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
GaborNoiseSampler gaborNoiseSampler = new GaborNoiseSampler((int) (long) seed + salt);
|
||||
gaborNoiseSampler.setFrequency(frequency);
|
||||
gaborNoiseSampler.setRotation(rotation);
|
||||
gaborNoiseSampler.setIsotropic(isotropic);
|
||||
gaborNoiseSampler.setDeviation(deviation);
|
||||
gaborNoiseSampler.setImpulsesPerKernel(impulses);
|
||||
gaborNoiseSampler.setFrequency0(f0);
|
||||
GaborNoiseSampler gaborNoiseSampler = new GaborNoiseSampler((int) (long) seed + salt.get());
|
||||
gaborNoiseSampler.setFrequency(frequency.get());
|
||||
gaborNoiseSampler.setRotation(rotation.get());
|
||||
gaborNoiseSampler.setIsotropic(isotropic.get());
|
||||
gaborNoiseSampler.setDeviation(deviation.get());
|
||||
gaborNoiseSampler.setImpulsesPerKernel(impulses.get());
|
||||
gaborNoiseSampler.setFrequency0(f0.get());
|
||||
return gaborNoiseSampler;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -2,6 +2,7 @@ package com.dfsek.terra.config.loaders.config.sampler.templates.noise;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.NoiseFunction;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
||||
|
||||
@@ -9,9 +10,9 @@ import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
||||
public abstract class NoiseTemplate<T extends NoiseFunction> extends SamplerTemplate<T> {
|
||||
@Value("frequency")
|
||||
@Default
|
||||
protected double frequency = 0.02d;
|
||||
protected MetaValue<Double> frequency = MetaValue.of(0.02d);
|
||||
|
||||
@Value("salt")
|
||||
@Default
|
||||
protected int salt = 0;
|
||||
protected MetaValue<Integer> salt = MetaValue.of(0);
|
||||
}
|
||||
|
||||
+2
-2
@@ -14,8 +14,8 @@ public class SimpleNoiseTemplate extends NoiseTemplate<NoiseFunction> {
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
NoiseFunction sampler = samplerSupplier.apply((int) (long) seed + salt);
|
||||
sampler.setFrequency(frequency);
|
||||
NoiseFunction sampler = samplerSupplier.apply((int) (long) seed + salt.get());
|
||||
sampler.setFrequency(frequency.get());
|
||||
return sampler;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -6,11 +6,11 @@ import com.dfsek.terra.api.math.noise.samplers.noise.fractal.BrownianMotionSampl
|
||||
public class BrownianMotionTemplate extends FractalTemplate<BrownianMotionSampler> {
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
BrownianMotionSampler sampler = new BrownianMotionSampler((int) (long) seed, function.apply(seed));
|
||||
sampler.setGain(fractalGain);
|
||||
sampler.setLacunarity(fractalLacunarity);
|
||||
sampler.setOctaves(octaves);
|
||||
sampler.setWeightedStrength(weightedStrength);
|
||||
BrownianMotionSampler sampler = new BrownianMotionSampler((int) (long) seed, function.get().apply(seed));
|
||||
sampler.setGain(fractalGain.get());
|
||||
sampler.setLacunarity(fractalLacunarity.get());
|
||||
sampler.setOctaves(octaves.get());
|
||||
sampler.setWeightedStrength(weightedStrength.get());
|
||||
return sampler;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -2,6 +2,7 @@ package com.dfsek.terra.config.loaders.config.sampler.templates.noise.fractal;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.fractal.FractalNoiseFunction;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
||||
@@ -9,20 +10,20 @@ import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
||||
public abstract class FractalTemplate<T extends FractalNoiseFunction> extends SamplerTemplate<T> {
|
||||
@Value("octaves")
|
||||
@Default
|
||||
protected int octaves = 3;
|
||||
protected MetaValue<Integer> octaves = MetaValue.of(3);
|
||||
|
||||
@Value("gain")
|
||||
@Default
|
||||
protected double fractalGain = 0.5D;
|
||||
protected MetaValue<Double> fractalGain = MetaValue.of(0.5D);
|
||||
|
||||
@Value("lacunarity")
|
||||
@Default
|
||||
protected double fractalLacunarity = 2.0D;
|
||||
protected MetaValue<Double> fractalLacunarity = MetaValue.of(2.0D);
|
||||
|
||||
@Value("weighted-strength")
|
||||
@Default
|
||||
protected double weightedStrength = 0.0D;
|
||||
protected MetaValue<Double> weightedStrength = MetaValue.of(0.0D);
|
||||
|
||||
@Value("function")
|
||||
protected NoiseSeeded function;
|
||||
protected MetaValue<NoiseSeeded> function;
|
||||
}
|
||||
|
||||
+5
-5
@@ -12,11 +12,11 @@ public class PingPongTemplate extends FractalTemplate<PingPongSampler> {
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
PingPongSampler sampler = new PingPongSampler((int) (long) seed, function.apply(seed));
|
||||
sampler.setGain(fractalGain);
|
||||
sampler.setLacunarity(fractalLacunarity);
|
||||
sampler.setOctaves(octaves);
|
||||
sampler.setWeightedStrength(weightedStrength);
|
||||
PingPongSampler sampler = new PingPongSampler((int) (long) seed, function.get().apply(seed));
|
||||
sampler.setGain(fractalGain.get());
|
||||
sampler.setLacunarity(fractalLacunarity.get());
|
||||
sampler.setOctaves(octaves.get());
|
||||
sampler.setWeightedStrength(weightedStrength.get());
|
||||
sampler.setPingPongStrength(pingPong);
|
||||
return sampler;
|
||||
}
|
||||
|
||||
+5
-5
@@ -6,11 +6,11 @@ import com.dfsek.terra.api.math.noise.samplers.noise.fractal.RidgedFractalSample
|
||||
public class RidgedFractalTemplate extends FractalTemplate<RidgedFractalSampler> {
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
RidgedFractalSampler sampler = new RidgedFractalSampler((int) (long) seed, function.apply(seed));
|
||||
sampler.setGain(fractalGain);
|
||||
sampler.setLacunarity(fractalLacunarity);
|
||||
sampler.setOctaves(octaves);
|
||||
sampler.setWeightedStrength(weightedStrength);
|
||||
RidgedFractalSampler sampler = new RidgedFractalSampler((int) (long) seed, function.get().apply(seed));
|
||||
sampler.setGain(fractalGain.get());
|
||||
sampler.setLacunarity(fractalLacunarity.get());
|
||||
sampler.setOctaves(octaves.get());
|
||||
sampler.setWeightedStrength(weightedStrength.get());
|
||||
return sampler;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler.templates.normalizer;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.normalizer.ClampNormalizer;
|
||||
import com.dfsek.terra.api.math.noise.normalizer.LinearNormalizer;
|
||||
@@ -8,13 +9,13 @@ import com.dfsek.terra.api.math.noise.normalizer.LinearNormalizer;
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class ClampNormalizerTemplate extends NormalizerTemplate<LinearNormalizer> {
|
||||
@Value("max")
|
||||
private double max;
|
||||
private MetaValue<Double> max;
|
||||
|
||||
@Value("min")
|
||||
private double min;
|
||||
private MetaValue<Double> min;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
return new ClampNormalizer(function.apply(seed), min, max);
|
||||
return new ClampNormalizer(function.get().apply(seed), min.get(), max.get());
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,19 +1,20 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler.templates.normalizer;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.normalizer.LinearNormalizer;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class LinearNormalizerTemplate extends NormalizerTemplate<LinearNormalizer> {
|
||||
@Value("max")
|
||||
private double max;
|
||||
private MetaValue<Double> max;
|
||||
|
||||
@Value("min")
|
||||
private double min;
|
||||
private MetaValue<Double> min;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
return new LinearNormalizer(function.apply(seed), min, max);
|
||||
return new LinearNormalizer(function.get().apply(seed), min.get(), max.get());
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -2,23 +2,24 @@ package com.dfsek.terra.config.loaders.config.sampler.templates.normalizer;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.normalizer.NormalNormalizer;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class NormalNormalizerTemplate extends NormalizerTemplate<NormalNormalizer> {
|
||||
@Value("mean")
|
||||
private double mean;
|
||||
private MetaValue<Double> mean;
|
||||
|
||||
@Value("standard-deviation")
|
||||
private double stdDev;
|
||||
private MetaValue<Double> stdDev;
|
||||
|
||||
@Value("groups")
|
||||
@Default
|
||||
private int groups = 16384;
|
||||
private MetaValue<Integer> groups = MetaValue.of(16384);
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
return new NormalNormalizer(function.apply(seed), groups, mean, stdDev);
|
||||
return new NormalNormalizer(function.get().apply(seed), groups.get(), mean.get(), stdDev.get());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,11 +1,12 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler.templates.normalizer;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.math.noise.normalizer.Normalizer;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
||||
|
||||
public abstract class NormalizerTemplate<T extends Normalizer> extends SamplerTemplate<T> {
|
||||
@Value("function")
|
||||
protected NoiseSeeded function;
|
||||
protected MetaValue<NoiseSeeded> function;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.dfsek.terra.config.loaders.meta;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.terra.api.config.meta.MetaContext;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class GenericMetaValueLoader extends MetaValueLoader<MetaValue<Object>, Object> {
|
||||
public GenericMetaValueLoader(MetaContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaValue<Object> load(Type type, Object c, ConfigLoader loader) throws LoadException {
|
||||
if(type instanceof ParameterizedType) {
|
||||
ParameterizedType pType = (ParameterizedType) type;
|
||||
Type generic = pType.getActualTypeArguments()[0];
|
||||
if(c instanceof String) {
|
||||
String possibleMeta = (String) c;
|
||||
if(possibleMeta.startsWith("$")) {
|
||||
String meta = possibleMeta.substring(1);
|
||||
return MetaValue.of(context.load(meta, generic));
|
||||
}
|
||||
}
|
||||
|
||||
return MetaValue.of(loader.loadType(generic, c));
|
||||
} else throw new LoadException("Unable to load config! Could not retrieve parameterized type: " + type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.dfsek.terra.config.loaders.meta;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.terra.api.config.meta.MetaContext;
|
||||
import com.dfsek.terra.api.config.meta.type.MetaList;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
public class MetaListLoader extends MetaValueLoader<MetaList<Object>, List<Object>> {
|
||||
protected MetaListLoader(MetaContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaList<Object> load(Type t, Object c, ConfigLoader loader) throws LoadException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> get() {
|
||||
return new GlueList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.dfsek.terra.config.loaders.meta;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.terra.api.config.meta.MetaContext;
|
||||
import com.dfsek.terra.api.config.meta.type.MetaMap;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MetaMapLoader extends MetaValueLoader<MetaMap<Object, Object>, Map<Object, Object>> {
|
||||
public MetaMapLoader(MetaContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaMap<Object, Object> load(Type t, Object c, ConfigLoader loader) throws LoadException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, Object> get() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.dfsek.terra.config.loaders.meta;
|
||||
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.config.meta.MetaContext;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class MetaValueLoader<M extends MetaValue<T>, T> implements TypeLoader<M>, Supplier<T> {
|
||||
protected final MetaContext context;
|
||||
|
||||
protected MetaValueLoader(MetaContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.LoaderRegistrar;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
@@ -42,6 +43,8 @@ import com.dfsek.terra.config.loaders.config.biome.templates.provider.ImageProvi
|
||||
import com.dfsek.terra.config.loaders.config.biome.templates.provider.SingleBiomeProviderTemplate;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.NoiseSamplerBuilderLoader;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.ImageSamplerTemplate;
|
||||
import com.dfsek.terra.config.loaders.meta.GenericMetaValueLoader;
|
||||
import com.dfsek.terra.config.pack.meta.PackMetaContext;
|
||||
import com.dfsek.terra.config.templates.AbstractableTemplate;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.config.templates.CarverTemplate;
|
||||
@@ -115,6 +118,8 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
private final BiomeProvider.BiomeProviderBuilder biomeProviderBuilder;
|
||||
|
||||
private final PackMetaContext context;
|
||||
|
||||
|
||||
public ConfigPack(File folder, TerraPlugin main) throws ConfigException {
|
||||
try {
|
||||
@@ -124,6 +129,9 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
floraRegistry = new FloraRegistry(main);
|
||||
paletteRegistry = new PaletteRegistry(main);
|
||||
treeRegistry = new TreeRegistry();
|
||||
|
||||
context = new PackMetaContext(loader, selfLoader);
|
||||
|
||||
register(abstractConfigLoader);
|
||||
register(selfLoader);
|
||||
|
||||
@@ -165,6 +173,9 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
floraRegistry = new FloraRegistry(main);
|
||||
paletteRegistry = new PaletteRegistry(main);
|
||||
treeRegistry = new TreeRegistry();
|
||||
|
||||
context = new PackMetaContext(loader, selfLoader);
|
||||
|
||||
register(abstractConfigLoader);
|
||||
register(selfLoader);
|
||||
|
||||
@@ -295,7 +306,8 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
.registerLoader(SingleBiomeProviderTemplate.class, SingleBiomeProviderTemplate::new)
|
||||
.registerLoader(BiomePipelineTemplate.class, () -> new BiomePipelineTemplate(main))
|
||||
.registerLoader(ImageProviderTemplate.class, () -> new ImageProviderTemplate(biomeRegistry))
|
||||
.registerLoader(ImageSamplerTemplate.class, () -> new ImageProviderTemplate(biomeRegistry));
|
||||
.registerLoader(ImageSamplerTemplate.class, () -> new ImageProviderTemplate(biomeRegistry))
|
||||
.registerLoader(MetaValue.class, new GenericMetaValueLoader(context));
|
||||
}
|
||||
|
||||
public Set<UserDefinedCarver> getCarvers() {
|
||||
|
||||
@@ -2,13 +2,14 @@ package com.dfsek.terra.config.pack;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
|
||||
|
||||
public class ConfigPackPostTemplate implements ConfigTemplate {
|
||||
@Value("biomes")
|
||||
private BiomeProvider.BiomeProviderBuilder providerBuilder;
|
||||
private MetaValue<BiomeProvider.BiomeProviderBuilder> providerBuilder;
|
||||
|
||||
public BiomeProvider.BiomeProviderBuilder getProviderBuilder() {
|
||||
return providerBuilder;
|
||||
return providerBuilder.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.api.addons.TerraAddon;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.util.MapUtil;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
||||
|
||||
@@ -12,14 +15,24 @@ import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class ConfigPackTemplate implements ConfigTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("version")
|
||||
@Default
|
||||
private String version = "0.1.0";
|
||||
|
||||
@Value("author")
|
||||
@Default
|
||||
private String author = "Anon Y. Mous";
|
||||
|
||||
@Value("noise")
|
||||
private Map<String, NoiseSeeded> noiseBuilderMap;
|
||||
private Map<String, MetaValue<NoiseSeeded>> noiseBuilderMap;
|
||||
private final Lazy<Map<String, NoiseSeeded>> lazyNoiseBuilderMap = new Lazy<>(() -> MapUtil.remapValues(MetaValue::get, noiseBuilderMap));
|
||||
|
||||
@Value("addons")
|
||||
@Default
|
||||
@@ -27,94 +40,89 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
|
||||
@Value("variables")
|
||||
@Default
|
||||
private Map<String, Double> variables = new HashMap<>();
|
||||
private Map<String, MetaValue<Double>> variables = new HashMap<>();
|
||||
private final Lazy<Map<String, Double>> lazyVariables = new Lazy<>(() -> MapUtil.remapValues(MetaValue::get, variables));
|
||||
|
||||
@Value("beta.carving")
|
||||
@Default
|
||||
private boolean betaCarvers = false;
|
||||
private MetaValue<Boolean> betaCarvers = MetaValue.of(false);
|
||||
|
||||
@Value("functions")
|
||||
@Default
|
||||
private LinkedHashMap<String, FunctionTemplate> functions = new LinkedHashMap<>();
|
||||
private LinkedHashMap<String, MetaValue<FunctionTemplate>> functions = new LinkedHashMap<>();
|
||||
private final Lazy<LinkedHashMap<String, FunctionTemplate>> lazyFunctions = new Lazy<>(() -> MapUtil.remap(Function.identity(), MetaValue::get, functions, LinkedHashMap::new));
|
||||
|
||||
@Value("structures.locatable")
|
||||
@Default
|
||||
private Map<String, String> locatable = new HashMap<>();
|
||||
private Map<String, MetaValue<String>> locatable = new HashMap<>();
|
||||
private final Lazy<Map<String, String>> lazyLocatable = new Lazy<>(() -> MapUtil.remapValues(MetaValue::get, locatable));
|
||||
|
||||
@Value("blend.terrain.elevation")
|
||||
@Default
|
||||
private int elevationBlend = 4;
|
||||
private MetaValue<Integer> elevationBlend = MetaValue.of(4);
|
||||
|
||||
@Value("vanilla.mobs")
|
||||
@Default
|
||||
private boolean vanillaMobs = true;
|
||||
private MetaValue<Boolean> vanillaMobs = MetaValue.of(true);
|
||||
|
||||
@Value("vanilla.caves")
|
||||
@Default
|
||||
private boolean vanillaCaves = false;
|
||||
private MetaValue<Boolean> vanillaCaves = MetaValue.of(false);
|
||||
|
||||
@Value("vanilla.decorations")
|
||||
@Default
|
||||
private boolean vanillaDecorations = false;
|
||||
private MetaValue<Boolean> vanillaDecorations = MetaValue.of(false);
|
||||
|
||||
@Value("vanilla.structures")
|
||||
@Default
|
||||
private boolean vanillaStructures = false;
|
||||
|
||||
@Value("author")
|
||||
@Default
|
||||
private String author = "Anon Y. Mous";
|
||||
private MetaValue<Boolean> vanillaStructures = MetaValue.of(false);
|
||||
|
||||
@Value("disable.sapling")
|
||||
@Default
|
||||
private boolean disableSaplings = false;
|
||||
|
||||
@Value("version")
|
||||
@Default
|
||||
private String version = "0.1.0";
|
||||
private MetaValue<Boolean> disableSaplings = MetaValue.of(false);
|
||||
|
||||
@Value("disable.carvers")
|
||||
@Default
|
||||
private boolean disableCarvers = false;
|
||||
private MetaValue<Boolean> disableCarvers = MetaValue.of(false);
|
||||
|
||||
@Value("disable.structures")
|
||||
@Default
|
||||
private boolean disableStructures = false;
|
||||
private MetaValue<Boolean> disableStructures = MetaValue.of(false);
|
||||
|
||||
@Value("disable.ores")
|
||||
@Default
|
||||
private boolean disableOres = false;
|
||||
private MetaValue<Boolean> disableOres = MetaValue.of(false);
|
||||
|
||||
@Value("disable.trees")
|
||||
@Default
|
||||
private boolean disableTrees = false;
|
||||
private MetaValue<Boolean> disableTrees = MetaValue.of(false);
|
||||
|
||||
@Value("disable.flora")
|
||||
@Default
|
||||
private boolean disableFlora = false;
|
||||
private MetaValue<Boolean> disableFlora = MetaValue.of(false);
|
||||
|
||||
public boolean disableCarvers() {
|
||||
return disableCarvers;
|
||||
return disableCarvers.get();
|
||||
}
|
||||
|
||||
public boolean disableFlora() {
|
||||
return disableFlora;
|
||||
return disableFlora.get();
|
||||
}
|
||||
|
||||
public boolean disableOres() {
|
||||
return disableOres;
|
||||
return disableOres.get();
|
||||
}
|
||||
|
||||
public boolean disableStructures() {
|
||||
return disableStructures;
|
||||
return disableStructures.get();
|
||||
}
|
||||
|
||||
public boolean disableTrees() {
|
||||
return disableTrees;
|
||||
return disableTrees.get();
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, FunctionTemplate> getFunctions() {
|
||||
return functions;
|
||||
return lazyFunctions.get();
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
@@ -122,7 +130,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
}
|
||||
|
||||
public boolean isDisableSaplings() {
|
||||
return disableSaplings;
|
||||
return disableSaplings.get();
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
@@ -134,39 +142,39 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
}
|
||||
|
||||
public boolean vanillaMobs() {
|
||||
return vanillaMobs;
|
||||
return vanillaMobs.get();
|
||||
}
|
||||
|
||||
public boolean vanillaCaves() {
|
||||
return vanillaCaves;
|
||||
return vanillaCaves.get();
|
||||
}
|
||||
|
||||
public boolean vanillaDecorations() {
|
||||
return vanillaDecorations;
|
||||
return vanillaDecorations.get();
|
||||
}
|
||||
|
||||
public boolean vanillaStructures() {
|
||||
return vanillaStructures;
|
||||
return vanillaStructures.get();
|
||||
}
|
||||
|
||||
public Map<String, NoiseSeeded> getNoiseBuilderMap() {
|
||||
return noiseBuilderMap;
|
||||
return lazyNoiseBuilderMap.get();
|
||||
}
|
||||
|
||||
public Map<String, Double> getVariables() {
|
||||
return variables;
|
||||
return lazyVariables.get();
|
||||
}
|
||||
|
||||
public int getElevationBlend() {
|
||||
return elevationBlend;
|
||||
return elevationBlend.get();
|
||||
}
|
||||
|
||||
public Map<String, String> getLocatable() {
|
||||
return locatable;
|
||||
return lazyLocatable.get();
|
||||
}
|
||||
|
||||
public boolean doBetaCarvers() {
|
||||
return betaCarvers;
|
||||
return betaCarvers.get();
|
||||
}
|
||||
|
||||
public Set<TerraAddon> getAddons() {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.dfsek.terra.config.pack.meta;
|
||||
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.terra.api.config.meta.MetaContext;
|
||||
import com.dfsek.terra.config.fileloaders.Loader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PackMetaContext implements MetaContext {
|
||||
private final Map<String, Configuration> configs = new HashMap<>(); // Lazy init configs
|
||||
private final Loader fileAccess;
|
||||
private final ConfigLoader loader;
|
||||
|
||||
public PackMetaContext(Loader fileAccess, ConfigLoader loader) {
|
||||
this.fileAccess = fileAccess;
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T load(String meta, Type clazz) throws LoadException {
|
||||
if(meta.indexOf(":") != meta.lastIndexOf(":")) { // We just need to know if there are >1.
|
||||
throw new LoadException("Malformed metavalue string: " + meta);
|
||||
}
|
||||
|
||||
String file = "/pack.yml";
|
||||
String key;
|
||||
if(meta.contains(":")) {
|
||||
file = meta.substring(0, meta.indexOf(":"));
|
||||
key = meta.substring(meta.indexOf(":") + 1);
|
||||
} else {
|
||||
key = meta;
|
||||
}
|
||||
Configuration configuration;
|
||||
try {
|
||||
configuration = new Configuration(fileAccess.get(file), file);
|
||||
} catch(IOException e) {
|
||||
throw new LoadException("Failed to load config file \"" + file + "\":", e);
|
||||
}
|
||||
|
||||
return (T) loader.loadType(clazz, configuration.get(key));
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,13 @@ import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.world.population.items.ores.Ore;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class OreTemplate extends AbstractableTemplate {
|
||||
@Value("id")
|
||||
@@ -17,6 +21,11 @@ public class OreTemplate extends AbstractableTemplate {
|
||||
@Abstractable
|
||||
private BlockData material;
|
||||
|
||||
@Value("material-overrides")
|
||||
@Default
|
||||
@Abstractable
|
||||
private Map<BlockType, BlockData> materials = new HashMap<>();
|
||||
|
||||
@Value("type")
|
||||
@Abstractable
|
||||
@Default
|
||||
@@ -76,4 +85,8 @@ public class OreTemplate extends AbstractableTemplate {
|
||||
public Ore.Type getType() {
|
||||
return oreType;
|
||||
}
|
||||
|
||||
public Map<BlockType, BlockData> getMaterialOverrides() {
|
||||
return materials;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -59,7 +59,7 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
|
||||
}
|
||||
|
||||
for(int y = 0; y < size + 1; y++) {
|
||||
noiseStorage[x][z][y] = computeNoise(genMap, (x << 2) + xOrigin, y << 2, (z << 2) + zOrigin);
|
||||
noiseStorage[x][z][y] = computeNoise(genMap, (x << 2) + xOrigin, (y << 2) + min, (z << 2) + zOrigin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,10 +98,10 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
|
||||
*/
|
||||
@Override
|
||||
public double getNoise(double x, double y, double z) {
|
||||
return interpGrid[reRange(((int) x) / 4, 3)][FastMath.max(FastMath.min(((int) y), max), min) / 4][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
|
||||
return interpGrid[reRange(((int) x) / 4, 3)][(FastMath.max(FastMath.min(((int) y), max), min) - min) / 4][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
|
||||
}
|
||||
|
||||
public double getNoise(int x, int y, int z) {
|
||||
return interpGrid[x / 4][y / 4][z / 4].trilerp((double) (x % 4) / 4, (double) (y % 4) / 4, (double) (z % 4) / 4);
|
||||
return interpGrid[x / 4][(y - min) / 4][z / 4].trilerp((double) (x % 4) / 4, (double) (y % 4) / 4, (double) (z % 4) / 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class CavePopulator implements TerraBlockPopulator, Chunkified {
|
||||
Location mut = l.clone();
|
||||
BlockData orig = l.getBlock().getBlockData();
|
||||
do mut.subtract(0, 1, 0);
|
||||
while(mut.getY() > 0 && mut.getBlock().getBlockData().matches(orig));
|
||||
while(mut.getY() > world.getMinHeight() && mut.getBlock().getBlockData().matches(orig));
|
||||
try {
|
||||
if(template.getShift().get(entry.getValue().getBlockType()).contains(mut.getBlock().getBlockData().getBlockType())) {
|
||||
mut.getBlock().setBlockData(shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false);
|
||||
|
||||
+8
-7
@@ -6,10 +6,11 @@ import com.dfsek.terra.api.math.noise.samplers.noise.simplex.OpenSimplex2Sampler
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class DeformedSphereOre extends Ore {
|
||||
@@ -17,8 +18,8 @@ public class DeformedSphereOre extends Ore {
|
||||
private final double deformFrequency;
|
||||
private final Range size;
|
||||
|
||||
public DeformedSphereOre(BlockData material, MaterialSet replaceable, boolean applyGravity, double deform, double deformFrequency, Range size, TerraPlugin main) {
|
||||
super(material, replaceable, applyGravity, main);
|
||||
public DeformedSphereOre(BlockData material, MaterialSet replaceable, boolean applyGravity, double deform, double deformFrequency, Range size, TerraPlugin main, Map<BlockType, BlockData> materials) {
|
||||
super(material, replaceable, applyGravity, main, materials);
|
||||
this.deform = deform;
|
||||
this.deformFrequency = deformFrequency;
|
||||
this.size = size;
|
||||
@@ -27,7 +28,6 @@ public class DeformedSphereOre extends Ore {
|
||||
|
||||
@Override
|
||||
public void generate(Vector3 origin, Chunk c, Random r) {
|
||||
WorldHandle handle = main.getWorldHandle();
|
||||
OpenSimplex2Sampler ore = new OpenSimplex2Sampler(r.nextInt());
|
||||
ore.setFrequency(deformFrequency);
|
||||
int rad = size.get(r);
|
||||
@@ -35,12 +35,13 @@ public class DeformedSphereOre extends Ore {
|
||||
for(int y = -rad; y <= rad; y++) {
|
||||
for(int z = -rad; z <= rad; z++) {
|
||||
Vector3 oreLoc = origin.clone().add(new Vector3(x, y, z));
|
||||
if(oreLoc.getBlockX() > 15 || oreLoc.getBlockZ() > 15 || oreLoc.getBlockY() > 255 || oreLoc.getBlockX() < 0 || oreLoc.getBlockZ() < 0 || oreLoc.getBlockY() < 0)
|
||||
if(oreLoc.getBlockX() > 15 || oreLoc.getBlockZ() > 15 || oreLoc.getBlockY() > c.getWorld().getMaxHeight() || oreLoc.getBlockX() < 0 || oreLoc.getBlockZ() < 0 || oreLoc.getBlockY() < c.getWorld().getMinHeight())
|
||||
continue;
|
||||
if(oreLoc.distance(origin) < (rad + 0.5) * ((ore.getNoise(x, y, z) + 1) * deform)) {
|
||||
Block b = c.getBlock(oreLoc.getBlockX(), oreLoc.getBlockY(), oreLoc.getBlockZ());
|
||||
if(getReplaceable().contains(b.getType()) && b.getLocation().getY() >= 0)
|
||||
b.setBlockData(getMaterial(), isApplyGravity());
|
||||
BlockType type = b.getType();
|
||||
if(getReplaceable().contains(type) && b.getLocation().getY() >= c.getWorld().getMinHeight())
|
||||
b.setBlockData(getMaterial(type), isApplyGravity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.dfsek.terra.world.population.items.ores;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class Ore {
|
||||
@@ -14,18 +16,20 @@ public abstract class Ore {
|
||||
private final MaterialSet replaceable;
|
||||
private final boolean applyGravity;
|
||||
protected TerraPlugin main;
|
||||
private final Map<BlockType, BlockData> materials;
|
||||
|
||||
public Ore(BlockData material, MaterialSet replaceable, boolean applyGravity, TerraPlugin main) {
|
||||
public Ore(BlockData material, MaterialSet replaceable, boolean applyGravity, TerraPlugin main, Map<BlockType, BlockData> materials) {
|
||||
this.material = material;
|
||||
this.replaceable = replaceable;
|
||||
this.applyGravity = applyGravity;
|
||||
this.main = main;
|
||||
this.materials = materials;
|
||||
}
|
||||
|
||||
public abstract void generate(Vector3 origin, Chunk c, Random r);
|
||||
|
||||
public BlockData getMaterial() {
|
||||
return material;
|
||||
public BlockData getMaterial(BlockType replace) {
|
||||
return materials.getOrDefault(replace, material);
|
||||
}
|
||||
|
||||
public MaterialSet getReplaceable() {
|
||||
|
||||
@@ -5,18 +5,20 @@ import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class VanillaOre extends Ore {
|
||||
private final Range sizeRange;
|
||||
|
||||
public VanillaOre(BlockData material, MaterialSet replaceable, boolean applyGravity, Range size, TerraPlugin main) {
|
||||
super(material, replaceable, applyGravity, main);
|
||||
public VanillaOre(BlockData material, MaterialSet replaceable, boolean applyGravity, Range size, TerraPlugin main, Map<BlockType, BlockData> materials) {
|
||||
super(material, replaceable, applyGravity, main, materials);
|
||||
this.sizeRange = size;
|
||||
}
|
||||
|
||||
@@ -67,8 +69,9 @@ public class VanillaOre extends Ore {
|
||||
double d15 = (z + 0.5D - (d3 + (d4 - d3) * iFactor)) / (d11 / 2.0D);
|
||||
if(x > 15 || z > 15 || y > 255 || x < 0 || z < 0 || y < 0) continue;
|
||||
Block block = chunk.getBlock(x, y, z);
|
||||
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(block.getType())) {
|
||||
block.setBlockData(getMaterial(), isApplyGravity());
|
||||
BlockType type = block.getType();
|
||||
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(type)) {
|
||||
block.setBlockData(getMaterial(type), isApplyGravity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
org.gradle.jvmargs=-Xmx4096m
|
||||
@@ -7,7 +7,7 @@ import net.fabricmc.loom.task.RemapJarTask
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
id("fabric-loom").version("0.6-SNAPSHOT")
|
||||
id("fabric-loom").version("0.8-SNAPSHOT")
|
||||
id("com.modrinth.minotaur").version("1.1.0")
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ group = "com.dfsek.terra.fabric"
|
||||
dependencies {
|
||||
"shadedApi"(project(":common"))
|
||||
|
||||
"minecraft"("com.mojang:minecraft:1.16.5")
|
||||
"mappings"("net.fabricmc:yarn:1.16.5+build.5:v2")
|
||||
"modImplementation"("net.fabricmc:fabric-loader:0.11.2")
|
||||
"minecraft"("com.mojang:minecraft:1.17")
|
||||
"mappings"("net.fabricmc:yarn:1.17+build.1:v2")
|
||||
"modImplementation"("net.fabricmc:fabric-loader:0.11.3")
|
||||
|
||||
"modCompileOnly"("com.sk89q.worldedit:worldedit-fabric-mc1.16:7.2.0-SNAPSHOT") {
|
||||
exclude(group = "com.google.guava", module = "guava")
|
||||
@@ -36,6 +36,11 @@ dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
relocate("org.json", "com.dfsek.terra.lib.json")
|
||||
relocate("org.yaml", "com.dfsek.terra.lib.yaml")
|
||||
}
|
||||
|
||||
|
||||
configure<LoomGradleExtension> {
|
||||
accessWidener("src/main/resources/terra.accesswidener")
|
||||
|
||||
@@ -264,7 +264,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
|
||||
Registry.register(Registry.FEATURE, new Identifier("terra", "populator"), POPULATOR_FEATURE);
|
||||
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("terra", "populator"));
|
||||
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_KEY, new Identifier("terra", "populator"));
|
||||
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, floraKey.getValue(), POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);
|
||||
@@ -319,7 +319,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
injectTree(treeRegistry, "LARGE_OAK", ConfiguredFeatures.FANCY_OAK);
|
||||
injectTree(treeRegistry, "LARGE_SPRUCE", ConfiguredFeatures.PINE);
|
||||
injectTree(treeRegistry, "SMALL_JUNGLE", ConfiguredFeatures.JUNGLE_TREE);
|
||||
injectTree(treeRegistry, "SWAMP_OAK", ConfiguredFeatures.SWAMP_TREE);
|
||||
injectTree(treeRegistry, "SWAMP_OAK", ConfiguredFeatures.SWAMP_OAK);
|
||||
injectTree(treeRegistry, "TALL_BIRCH", ConfiguredFeatures.BIRCH_TALL);
|
||||
injectTree(treeRegistry, "ACACIA", ConfiguredFeatures.ACACIA);
|
||||
injectTree(treeRegistry, "BIRCH", ConfiguredFeatures.BIRCH);
|
||||
|
||||
+31
-15
@@ -5,10 +5,12 @@ import com.dfsek.terra.api.platform.world.generator.ChunkData;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.generation.Chunkified;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.mixin.StructureAccessorAccessor;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
|
||||
@@ -25,11 +27,10 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.HeightLimitView;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.SpawnHelper;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeAccess;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
@@ -46,6 +47,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class FabricChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper {
|
||||
private final long seed;
|
||||
@@ -120,11 +122,6 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
return super.locateStructure(world, feature, center, radius, skipExistingChunks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateNoise(WorldAccess world, StructureAccessor accessor, Chunk chunk) {
|
||||
delegate.generateChunkData((World) world, new FastRandom(), chunk.getPos().x, chunk.getPos().z, (ChunkData) chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {
|
||||
if(pack.getTemplate().vanillaCaves()) super.carve(seed, access, chunk, carver);
|
||||
@@ -136,6 +133,20 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
super.setStructureStarts(dynamicRegistryManager, structureAccessor, chunk, structureManager, worldSeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Chunk> populateNoise(Executor executor, StructureAccessor accessor, Chunk chunk) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
World world = (World) ((StructureAccessorAccessor) accessor).getWorld();
|
||||
delegate.generateChunkData(world, new FastRandom(), chunk.getPos().x, chunk.getPos().z, (ChunkData) chunk);
|
||||
delegate.getPopulators().forEach(populator -> {
|
||||
if(populator instanceof Chunkified) {
|
||||
populator.populate(world, (com.dfsek.terra.api.platform.world.Chunk) world);
|
||||
}
|
||||
});
|
||||
return chunk;
|
||||
}, executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
|
||||
if(pack.getTemplate().vanillaStructures()) return super.isStrongholdStartingChunk(chunkPos);
|
||||
@@ -143,7 +154,12 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight(int x, int z, Heightmap.Type heightmapType) {
|
||||
public int getHeightOnGround(int x, int z, Heightmap.Type heightmap, HeightLimitView world) {
|
||||
return super.getHeightOnGround(x, z, heightmap, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView heightmapType) {
|
||||
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
|
||||
Sampler sampler = world.getConfig().getSamplerCache().getChunk(FastMath.floorDiv(x, 16), FastMath.floorDiv(z, 16));
|
||||
int cx = FastMath.floorMod(x, 16);
|
||||
@@ -157,11 +173,11 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockView getColumnSample(int x, int z) {
|
||||
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView view) {
|
||||
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
|
||||
int height = getHeight(x, z, Heightmap.Type.WORLD_SURFACE);
|
||||
int height = getHeight(x, z, Heightmap.Type.WORLD_SURFACE, view);
|
||||
BlockState[] array = new BlockState[256];
|
||||
for(int y = 255; y >= 0; y--) {
|
||||
for(int y = view.getBottomY()+view.getHeight(); y >= view.getBottomY(); y--) {
|
||||
if(y > height) {
|
||||
if(y > ((UserDefinedBiome) world.getBiomeProvider().getBiome(x, z)).getConfig().getSeaLevel()) {
|
||||
array[y] = Blocks.AIR.getDefaultState();
|
||||
@@ -173,18 +189,18 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
}
|
||||
}
|
||||
|
||||
return new VerticalBlockSample(array);
|
||||
return new VerticalBlockSample(view.getBottomY(), array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateEntities(ChunkRegion region) {
|
||||
if(pack.getTemplate().vanillaMobs()) {
|
||||
int cx = region.getCenterChunkX();
|
||||
int cy = region.getCenterChunkZ();
|
||||
int cx = region.getCenterPos().x;
|
||||
int cy = region.getCenterPos().z;
|
||||
Biome biome = region.getBiome((new ChunkPos(cx, cy)).getStartPos());
|
||||
ChunkRandom chunkRandom = new ChunkRandom();
|
||||
chunkRandom.setPopulationSeed(region.getSeed(), cx << 4, cy << 4);
|
||||
SpawnHelper.populateEntities(region, biome, cx, cy, chunkRandom);
|
||||
SpawnHelper.populateEntities(region, biome, region.getCenterPos(), chunkRandom);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-5
@@ -2,14 +2,13 @@ package com.dfsek.terra.fabric.generation;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.world.generation.Chunkified;
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
|
||||
import java.util.Random;
|
||||
import net.minecraft.world.gen.feature.util.FeatureContext;
|
||||
|
||||
/**
|
||||
* Feature wrapper for Terra populator
|
||||
@@ -20,10 +19,16 @@ public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
|
||||
public boolean generate(FeatureContext<DefaultFeatureConfig> context) {
|
||||
ChunkGenerator chunkGenerator = context.getGenerator();
|
||||
if(!(chunkGenerator instanceof FabricChunkGeneratorWrapper)) return true;
|
||||
StructureWorldAccess world = context.getWorld();
|
||||
FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator;
|
||||
gen.getHandle().getPopulators().forEach(populator -> populator.populate((World) world, (Chunk) world));
|
||||
gen.getHandle().getPopulators().forEach(populator -> {
|
||||
if(!(populator instanceof Chunkified)) {
|
||||
populator.populate((World) world, (Chunk) world);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,8 +8,8 @@ import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.dynamic.RegistryLookupCodec;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryLookupCodec;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
|
||||
|
||||
+2
-2
@@ -48,7 +48,7 @@ public abstract class GeneratorOptionsMixin {
|
||||
boolean generateStructures = generate_structures == null || Boolean.parseBoolean(generate_structures);
|
||||
Registry<DimensionType> dimensionTypes = dynamicRegistryManager.get(Registry.DIMENSION_TYPE_KEY);
|
||||
Registry<Biome> biomes = dynamicRegistryManager.get(Registry.BIOME_KEY);
|
||||
Registry<ChunkGeneratorSettings> chunkGeneratorSettings = dynamicRegistryManager.get(Registry.NOISE_SETTINGS_WORLDGEN);
|
||||
Registry<ChunkGeneratorSettings> chunkGeneratorSettings = dynamicRegistryManager.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
|
||||
SimpleRegistry<DimensionOptions> dimensionOptions = DimensionType.createDefaultDimensionOptions(dimensionTypes, biomes, chunkGeneratorSettings, l);
|
||||
|
||||
prop = prop.substring(prop.indexOf(":") + 1);
|
||||
@@ -57,7 +57,7 @@ public abstract class GeneratorOptionsMixin {
|
||||
|
||||
if(pack == null) throw new IllegalArgumentException("No such pack " + prop);
|
||||
|
||||
cir.setReturnValue(new GeneratorOptions(l, generateStructures, false, GeneratorOptions.method_28608(dimensionTypes, dimensionOptions, new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomes, l, pack), l, pack))));
|
||||
cir.setReturnValue(new GeneratorOptions(l, generateStructures, false, GeneratorOptions.getRegistryWithReplacedOverworldGenerator(dimensionTypes, dimensionOptions, new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomes, l, pack), l, pack))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.dfsek.terra.fabric.mixin;
|
||||
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(StructureAccessor.class)
|
||||
public interface StructureAccessorAccessor {
|
||||
@Accessor
|
||||
WorldAccess getWorld();
|
||||
}
|
||||
+3
-1
@@ -1,12 +1,14 @@
|
||||
package com.dfsek.terra.fabric.mixin.access;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.MobSpawnerLogic;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(MobSpawnerLogic.class)
|
||||
public interface MobSpawnerLogicAccessor {
|
||||
@Invoker("getEntityId")
|
||||
Identifier callGetEntityId();
|
||||
Identifier callGetEntityId(World world, BlockPos blockPos);
|
||||
}
|
||||
|
||||
+3
-1
@@ -9,6 +9,7 @@ import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
@@ -18,6 +19,7 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
@Mixin(BlockEntity.class)
|
||||
@Implements(@Interface(iface = BlockState.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class BlockEntityMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
protected BlockPos pos;
|
||||
@Shadow
|
||||
@@ -56,7 +58,7 @@ public abstract class BlockEntityMixin {
|
||||
}
|
||||
|
||||
public boolean terra$update(boolean applyPhysics) {
|
||||
if(hasWorld()) world.getChunk(pos).setBlockEntity(pos, (BlockEntity) (Object) this);
|
||||
if(hasWorld()) world.getChunk(pos).setBlockEntity((BlockEntity) (Object) this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-2
@@ -5,9 +5,14 @@ import com.dfsek.terra.api.platform.block.state.SerialState;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.mixin.access.MobSpawnerLogicAccessor;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.MobSpawnerLogic;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
@@ -16,12 +21,16 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(MobSpawnerBlockEntity.class)
|
||||
@Implements(@Interface(iface = MobSpawner.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class MobSpawnerBlockEntityMixin {
|
||||
public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
private MobSpawnerBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
@Shadow
|
||||
public abstract MobSpawnerLogic getLogic();
|
||||
|
||||
public EntityType terra$getSpawnedType() {
|
||||
return (EntityType) Registry.ENTITY_TYPE.get(((MobSpawnerLogicAccessor) getLogic()).callGetEntityId());
|
||||
return (EntityType) Registry.ENTITY_TYPE.get(((MobSpawnerLogicAccessor) getLogic()).callGetEntityId(world, pos));
|
||||
}
|
||||
|
||||
public void terra$setSpawnedType(@NotNull EntityType creatureType) {
|
||||
|
||||
+5
-5
@@ -20,18 +20,18 @@ public abstract class SignBlockEntityMixin {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Text[] text;
|
||||
private Text[] texts;
|
||||
|
||||
public @NotNull String[] terra$getLines() {
|
||||
String[] lines = new String[text.length];
|
||||
for(int i = 0; i < text.length; i++) {
|
||||
lines[i] = text[i].asString();
|
||||
String[] lines = new String[texts.length];
|
||||
for(int i = 0; i < texts.length; i++) {
|
||||
lines[i] = texts[i].asString();
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public @NotNull String terra$getLine(int index) throws IndexOutOfBoundsException {
|
||||
return text[index].asString();
|
||||
return texts[index].asString();
|
||||
}
|
||||
|
||||
public void terra$setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
|
||||
|
||||
+6
-9
@@ -7,6 +7,7 @@ import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
@@ -20,18 +21,14 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
public abstract class ChunkRegionMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private int centerChunkX;
|
||||
|
||||
@Final
|
||||
@Shadow
|
||||
private int centerChunkZ;
|
||||
private ChunkPos centerPos;
|
||||
|
||||
public int terra$getX() {
|
||||
return centerChunkX;
|
||||
return centerPos.x;
|
||||
}
|
||||
|
||||
public int terra$getZ() {
|
||||
return centerChunkZ;
|
||||
return centerPos.z;
|
||||
}
|
||||
|
||||
public World terra$getWorld() {
|
||||
@@ -39,7 +36,7 @@ public abstract class ChunkRegionMixin {
|
||||
}
|
||||
|
||||
public Block terra$getBlock(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x + (centerChunkX << 4), y, z + (centerChunkZ << 4));
|
||||
BlockPos pos = new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4));
|
||||
return new FabricBlock(pos, (ChunkRegion) (Object) this);
|
||||
}
|
||||
|
||||
@@ -48,7 +45,7 @@ public abstract class ChunkRegionMixin {
|
||||
}
|
||||
|
||||
public void terra$setBlock(int x, int y, int z, @NotNull BlockData blockData) {
|
||||
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerChunkX << 4), y, z + (centerChunkZ << 4)), ((FabricBlockData) blockData).getHandle(), 0);
|
||||
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4)), ((FabricBlockData) blockData).getHandle(), 0);
|
||||
}
|
||||
|
||||
// getHandle already added in world/ChunkRegionMixin.
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ package com.dfsek.terra.fabric.mixin.implementations.inventory.item;
|
||||
import com.dfsek.terra.api.platform.inventory.Item;
|
||||
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
@@ -27,7 +27,7 @@ public abstract class ItemStackMixin {
|
||||
public abstract boolean isDamageable();
|
||||
|
||||
@Shadow
|
||||
public abstract void setTag(@Nullable CompoundTag tag);
|
||||
public abstract void setTag(@Nullable NbtCompound tag);
|
||||
|
||||
public int terra$getAmount() {
|
||||
return getCount();
|
||||
|
||||
+4
-4
@@ -3,8 +3,8 @@ package com.dfsek.terra.fabric.mixin.implementations.inventory.meta;
|
||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
@@ -23,7 +23,7 @@ public abstract class ItemStackMetaMixin {
|
||||
public abstract boolean hasEnchantments();
|
||||
|
||||
@Shadow
|
||||
public abstract ListTag getEnchantments();
|
||||
public abstract NbtList getEnchantments();
|
||||
|
||||
@Shadow
|
||||
public abstract void addEnchantment(net.minecraft.enchantment.Enchantment enchantment, int level);
|
||||
@@ -39,7 +39,7 @@ public abstract class ItemStackMetaMixin {
|
||||
Map<Enchantment, Integer> map = new HashMap<>();
|
||||
|
||||
getEnchantments().forEach(enchantment -> {
|
||||
CompoundTag eTag = (CompoundTag) enchantment;
|
||||
NbtCompound eTag = (NbtCompound) enchantment;
|
||||
map.put((Enchantment) Registry.ENCHANTMENT.get(eTag.getInt("id")), eTag.getInt("lvl"));
|
||||
});
|
||||
return map;
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ public abstract class ChunkRegionMixin {
|
||||
private long seed;
|
||||
|
||||
public int terra$getMaxHeight() {
|
||||
return ((ChunkRegion) (Object) this).getDimensionHeight();
|
||||
return (((ChunkRegion) (Object) this).getBottomY()) + ((ChunkRegion) (Object) this).getHeight();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -64,7 +64,7 @@ public abstract class ChunkRegionMixin {
|
||||
}
|
||||
|
||||
public int terra$getMinHeight() {
|
||||
return 0;
|
||||
return ((ChunkRegion) (Object) this).getBottomY();
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@ import com.dfsek.terra.fabric.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
@@ -27,7 +28,7 @@ public abstract class ServerWorldMixin {
|
||||
public abstract long getSeed();
|
||||
|
||||
public int terra$getMaxHeight() {
|
||||
return ((ServerWorld) (Object) this).getDimensionHeight();
|
||||
return (((ServerWorld) (Object) this).getBottomY()) + ((ServerWorld) (Object) this).getHeight();
|
||||
}
|
||||
|
||||
public ChunkGenerator terra$getGenerator() {
|
||||
@@ -55,7 +56,7 @@ public abstract class ServerWorldMixin {
|
||||
}
|
||||
|
||||
public int terra$getMinHeight() {
|
||||
return 0;
|
||||
return ((ServerWorld) (Object) this).getBottomY();
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"minecraft": "1.16.x"
|
||||
"minecraft": "1.17.x"
|
||||
},
|
||||
"accessWidener": "terra.accesswidener"
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
accessWidener v1 named
|
||||
|
||||
extendable method net/minecraft/client/world/GeneratorType <init> (Ljava/lang/String;)V
|
||||
extendable method net/minecraft/client/world/GeneratorType <init> (Ljava/lang/String;)V
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.dfsek.terra.fabric.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"compatibilityLevel": "JAVA_16",
|
||||
"mixins": [
|
||||
"StructureAccessorAccessor",
|
||||
"CommandManagerMixin",
|
||||
"GeneratorOptionsMixin",
|
||||
"ServerWorldMixin",
|
||||
|
||||
@@ -3,7 +3,6 @@ import com.dfsek.terra.configureCommon
|
||||
plugins {
|
||||
java
|
||||
id("org.spongepowered.plugin").version("0.9.0")
|
||||
id("org.spongepowered.gradle.vanilla").version("0.2")
|
||||
}
|
||||
|
||||
configureCommon()
|
||||
@@ -16,11 +15,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
"compileOnly"("org.spongepowered:spongeapi:8.0.0-SNAPSHOT")
|
||||
|
||||
"annotationProcessor"("org.spongepowered:mixin:0.8.2:processor")
|
||||
|
||||
"compileOnly"("org.spongepowered:mixin:0.8.2")
|
||||
"compileOnly"("org.spongepowered:spongeapi:7.2.0")
|
||||
"shadedApi"(project(":common"))
|
||||
"shadedImplementation"("org.yaml:snakeyaml:1.27")
|
||||
"shadedImplementation"("com.googlecode.json-simple:json-simple:1.1.1")
|
||||
@@ -30,20 +25,4 @@ sponge {
|
||||
plugin {
|
||||
id = "terra"
|
||||
}
|
||||
}
|
||||
|
||||
minecraft {
|
||||
version("1.16.5")
|
||||
runs {
|
||||
server()
|
||||
client()
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<Jar>("jar") {
|
||||
manifest {
|
||||
attributes(
|
||||
mapOf("MixinConfigs" to "terra.mixins.json")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.dfsek.terra.sponge;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.sponge.world.block.data.SpongeBlockData;
|
||||
import org.spongepowered.api.block.BlockState;
|
||||
|
||||
public final class SpongeAdapter {
|
||||
public static BlockData adapt(BlockState state) {
|
||||
return new SpongeBlockData(state);
|
||||
}
|
||||
|
||||
public static BlockState adapt(BlockData data) {
|
||||
return ((SpongeBlockData) data).getHandle();
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,9 @@ package com.dfsek.terra.sponge;
|
||||
import com.dfsek.terra.api.util.logging.Logger;
|
||||
|
||||
public class SpongeLogger implements Logger {
|
||||
private final org.apache.logging.log4j.Logger logger;
|
||||
private final org.slf4j.Logger logger;
|
||||
|
||||
public SpongeLogger(org.apache.logging.log4j.Logger logger) {
|
||||
public SpongeLogger(org.slf4j.Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,124 +3,77 @@ package com.dfsek.terra.sponge;
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addons.TerraAddon;
|
||||
import com.dfsek.terra.api.addons.annotations.Addon;
|
||||
import com.dfsek.terra.api.addons.annotations.Author;
|
||||
import com.dfsek.terra.api.addons.annotations.Version;
|
||||
import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.TerraEventManager;
|
||||
import com.dfsek.terra.api.event.annotations.Global;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.world.Biome;
|
||||
import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.config.GenericLoaders;
|
||||
import com.dfsek.terra.config.PluginConfig;
|
||||
import com.dfsek.terra.config.lang.Language;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.profiler.Profiler;
|
||||
import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
import com.dfsek.terra.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.sponge.handle.SpongeItemHandle;
|
||||
import com.dfsek.terra.sponge.handle.SpongeWorldHandle;
|
||||
import com.dfsek.terra.sponge.intern.util.SpongeUtil;
|
||||
import com.dfsek.terra.sponge.world.SpongeTree;
|
||||
import com.dfsek.terra.sponge.world.SpongeWorldHandle;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.google.inject.Inject;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import org.spongepowered.api.Server;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.api.config.ConfigDir;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.lifecycle.StartedEngineEvent;
|
||||
import org.spongepowered.api.event.lifecycle.StartingEngineEvent;
|
||||
import org.spongepowered.api.registry.Registry;
|
||||
import org.spongepowered.api.world.biome.Biomes;
|
||||
import org.spongepowered.api.world.server.ServerWorld;
|
||||
import org.spongepowered.plugin.PluginContainer;
|
||||
import org.spongepowered.plugin.jvm.Plugin;
|
||||
|
||||
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@Plugin("terra")
|
||||
@Plugin(id = "terra", name = "Terra-Sponge", version = "", description = "Terra")
|
||||
public class TerraSpongePlugin implements TerraPlugin {
|
||||
private final ConfigRegistry configRegistry = new ConfigRegistry();
|
||||
private final CheckedRegistry<ConfigPack> packCheckedRegistry = new CheckedRegistry<>(configRegistry);
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(this);
|
||||
private final LockedRegistry<TerraAddon> addonLockedRegistry = new LockedRegistry<>(addonRegistry);
|
||||
|
||||
private final SpongeWorldHandle spongeWorldHandle = new SpongeWorldHandle();
|
||||
|
||||
private final EventManager eventManager = new TerraEventManager(this);
|
||||
private final AddonRegistry addonRegistry;
|
||||
private final LockedRegistry<TerraAddon> addonLockedRegistry;
|
||||
|
||||
private static TerraSpongePlugin INSTANCE;
|
||||
|
||||
private final Map<DimensionType, Pair<ServerWorld, TerraWorld>> worldMap = new HashMap<>();
|
||||
|
||||
private final PluginContainer plugin;
|
||||
|
||||
private final GenericLoaders loaders = new GenericLoaders(this);
|
||||
|
||||
private final WorldHandle worldHandle = new SpongeWorldHandle();
|
||||
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
|
||||
@Inject
|
||||
public TerraSpongePlugin(PluginContainer plugin) {
|
||||
this.plugin = plugin;
|
||||
this.addonRegistry = new AddonRegistry(new SpongeAddon(this), this);
|
||||
this.addonLockedRegistry = new LockedRegistry<>(addonRegistry);
|
||||
INSTANCE = this;
|
||||
}
|
||||
@ConfigDir(sharedRoot = false)
|
||||
private Path privateConfigDir;
|
||||
|
||||
@Inject
|
||||
private Logger logger;
|
||||
|
||||
public static TerraSpongePlugin getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void initialize(StartingEngineEvent<Server> event) {
|
||||
plugin.logger().info("Loading Terra...");
|
||||
public void initialize(GameStartedServerEvent event) {
|
||||
addonRegistry.loadAll();
|
||||
configRegistry.loadAll(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
loaders.register(registry);
|
||||
registry.registerLoader(BlockData.class, (t, o, l) -> worldHandle.createBlockData((String) o))
|
||||
.registerLoader(Biome.class, (t, o, l) -> SpongeUtil.BIOME_FIXER.translate((String) o));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldHandle getWorldHandle() {
|
||||
return worldHandle;
|
||||
return spongeWorldHandle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraWorld getWorld(World world) {
|
||||
return getWorld(((LevelReader) world).dimensionType());
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(DimensionType type) {
|
||||
TerraWorld world = worldMap.get(type).getRight();
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with dimension type " + type);
|
||||
return world;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.dfsek.terra.api.util.logging.Logger logger() {
|
||||
return new SpongeLogger(plugin.logger());
|
||||
return new SpongeLogger(logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,7 +83,7 @@ public class TerraSpongePlugin implements TerraPlugin {
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return Sponge.configManager().pluginConfig(plugin).directory().toFile();
|
||||
return privateConfigDir.toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,7 +117,7 @@ public class TerraSpongePlugin implements TerraPlugin {
|
||||
|
||||
@Override
|
||||
public ItemHandle getItemHandle() {
|
||||
return new SpongeItemHandle();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,7 +132,7 @@ public class TerraSpongePlugin implements TerraPlugin {
|
||||
|
||||
@Override
|
||||
public DebugLogger getDebugLogger() {
|
||||
return new DebugLogger(logger());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,59 +142,6 @@ public class TerraSpongePlugin implements TerraPlugin {
|
||||
|
||||
@Override
|
||||
public Profiler getProfiler() {
|
||||
return profiler;
|
||||
}
|
||||
|
||||
public Map<DimensionType,Pair<ServerWorld, TerraWorld>> getWorldMap() {
|
||||
return worldMap;
|
||||
}
|
||||
|
||||
@Addon("Terra-Sponge")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
private static final class SpongeAddon extends TerraAddon implements EventListener {
|
||||
private final TerraPlugin main;
|
||||
|
||||
private SpongeAddon(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager().registerListener(this, this);
|
||||
}
|
||||
|
||||
@Global
|
||||
public void onPackLoad(ConfigPackPreLoadEvent event) {
|
||||
CheckedRegistry<Tree> treeRegistry = event.getPack().getTreeRegistry();
|
||||
|
||||
injectTree(treeRegistry, "BROWN_MUSHROOM", new SpongeTree());
|
||||
injectTree(treeRegistry, "RED_MUSHROOM", new SpongeTree());
|
||||
injectTree(treeRegistry, "JUNGLE", new SpongeTree());
|
||||
injectTree(treeRegistry, "JUNGLE_COCOA", new SpongeTree());
|
||||
injectTree(treeRegistry, "LARGE_OAK", new SpongeTree());
|
||||
injectTree(treeRegistry, "LARGE_SPRUCE", new SpongeTree());
|
||||
injectTree(treeRegistry, "SMALL_JUNGLE", new SpongeTree());
|
||||
injectTree(treeRegistry, "SWAMP_OAK", new SpongeTree());
|
||||
injectTree(treeRegistry, "TALL_BIRCH", new SpongeTree());
|
||||
injectTree(treeRegistry, "ACACIA", new SpongeTree());
|
||||
injectTree(treeRegistry, "BIRCH", new SpongeTree());
|
||||
injectTree(treeRegistry, "DARK_OAK", new SpongeTree());
|
||||
injectTree(treeRegistry, "OAK", new SpongeTree());
|
||||
injectTree(treeRegistry, "CHORUS_PLANT", new SpongeTree());
|
||||
injectTree(treeRegistry, "SPRUCE", new SpongeTree());
|
||||
injectTree(treeRegistry, "JUNGLE_BUSH", new SpongeTree());
|
||||
injectTree(treeRegistry, "MEGA_SPRUCE", new SpongeTree());
|
||||
injectTree(treeRegistry, "CRIMSON_FUNGUS", new SpongeTree());
|
||||
injectTree(treeRegistry, "WARPED_FUNGUS", new SpongeTree());
|
||||
}
|
||||
|
||||
private void injectTree(CheckedRegistry<Tree> registry, String id, Tree tree) {
|
||||
try {
|
||||
registry.add(id, tree);
|
||||
} catch(DuplicateEntryException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.dfsek.terra.sponge.handle;
|
||||
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.inventory.Item;
|
||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class SpongeItemHandle implements ItemHandle {
|
||||
@Override
|
||||
public Item createItem(String data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enchantment getEnchantment(String id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Enchantment> getEnchantments() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user