mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 23:01:03 +00:00
move modules to better directory structure
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import com.dfsek.terra.configureCompilation
|
||||
import com.dfsek.terra.configureDependencies
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
idea
|
||||
}
|
||||
|
||||
configureCompilation()
|
||||
configureDependencies()
|
||||
|
||||
group = "com.dfsek.terra.common"
|
||||
|
||||
dependencies {
|
||||
"shadedApi"(project(":common:api"))
|
||||
|
||||
"shadedApi"("org.apache.commons:commons-rng-core:1.3")
|
||||
"shadedApi"("commons-io:commons-io:2.4")
|
||||
|
||||
"shadedApi"("com.dfsek:Paralithic:0.3.2")
|
||||
"shadedApi"("com.dfsek:Tectonic:1.4.0")
|
||||
"shadedApi"("net.jafama:jafama:2.3.2")
|
||||
"shadedApi"("org.yaml:snakeyaml:1.27")
|
||||
"shadedApi"("org.ow2.asm:asm:9.0")
|
||||
"shadedApi"("commons-io:commons-io:2.6")
|
||||
|
||||
"shadedApi"("com.googlecode.json-simple:json-simple:1.1.1")
|
||||
"shadedApi"("org.yaml:snakeyaml:1.27")
|
||||
|
||||
"compileOnly"("com.google.guava:guava:30.0-jre")
|
||||
|
||||
"testImplementation"("com.google.guava:guava:30.0-jre")
|
||||
}
|
||||
|
||||
tasks.named<Jar>("jar") {
|
||||
archiveBaseName.set("Terra-biome")
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
artifact(tasks["sourcesJar"])
|
||||
artifact(tasks["jar"])
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
val mavenUrl = "https://repo.codemc.io/repository/maven-releases/"
|
||||
val mavenSnapshotUrl = "https://repo.codemc.io/repository/maven-snapshots/"
|
||||
|
||||
maven(mavenUrl) {
|
||||
val mavenUsername: String? by project
|
||||
val mavenPassword: String? by project
|
||||
if (mavenUsername != null && mavenPassword != null) {
|
||||
credentials {
|
||||
username = mavenUsername
|
||||
password = mavenPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
import com.dfsek.terra.addons.biome.holder.PaletteHolder;
|
||||
import com.dfsek.terra.addons.biome.holder.PaletteHolderLoader;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
import com.dfsek.terra.api.addon.annotations.Author;
|
||||
import com.dfsek.terra.api.addon.annotations.Version;
|
||||
import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
|
||||
@Addon("core-biome-config")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class BiomeConfigAddon extends TerraAddon implements EventListener {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager().registerListener(this, this);
|
||||
main.applyLoader(PaletteHolder.class, new PaletteHolderLoader());
|
||||
}
|
||||
|
||||
public void onPackLoad(ConfigPackPreLoadEvent event) {
|
||||
event.getPack().registerConfigType(new BiomeConfigType(event.getPack()), "BIOME", 5);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.seeded.BiomeBuilder;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BiomeConfigType implements ConfigType<BiomeTemplate, BiomeBuilder> {
|
||||
private final ConfigPack pack;
|
||||
private final BiomeFactory factory;
|
||||
|
||||
public BiomeConfigType(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
this.factory = new BiomeFactory(pack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new BiomeTemplate(pack, main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<BiomeTemplate, BiomeBuilder> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BiomeBuilder> getTypeClass() {
|
||||
return BiomeBuilder.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<OpenRegistry<BiomeBuilder>> registrySupplier() {
|
||||
return () -> pack.getRegistryFactory().create(registry -> (TypeLoader<BiomeBuilder>) (t, c, loader) -> {
|
||||
if(c.equals("SELF")) return null;
|
||||
BiomeBuilder obj = registry.get((String) c);
|
||||
if(obj == null)
|
||||
throw new LoadException("No such " + t.getTypeName() + " matching \"" + c + "\" was found in this registry.");
|
||||
return obj;
|
||||
});
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.util.seeded.BiomeBuilder;
|
||||
|
||||
public class BiomeFactory implements ConfigFactory<BiomeTemplate, BiomeBuilder> {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public BiomeFactory(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeBuilder build(BiomeTemplate template, TerraPlugin main) {
|
||||
return new UserDefinedBiomeBuilder(template, pack);
|
||||
}
|
||||
}
|
||||
+314
@@ -0,0 +1,314 @@
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Parser;
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
import com.dfsek.terra.addons.biome.holder.PaletteHolder;
|
||||
import com.dfsek.terra.addons.biome.slant.SlantHolder;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.structure.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
public class BiomeTemplate implements AbstractableTemplate, ValidatedConfigTemplate {
|
||||
private final ConfigPack pack;
|
||||
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("extends")
|
||||
@Default
|
||||
private List<String> extended = Collections.emptyList();
|
||||
|
||||
@Value("variables")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<String, Double> variables = new HashMap<>();
|
||||
|
||||
@Value("beta.carving.equation")
|
||||
@Abstractable
|
||||
@Default
|
||||
private NoiseSeeded carvingEquation = NoiseSeeded.zero(3);
|
||||
|
||||
@Value("palette")
|
||||
@Abstractable
|
||||
private PaletteHolder palette;
|
||||
|
||||
@Value("slant")
|
||||
@Abstractable
|
||||
@Default
|
||||
private SlantHolder slant = null;
|
||||
|
||||
@Value("vanilla")
|
||||
@Abstractable
|
||||
private ProbabilityCollection<Biome> vanilla;
|
||||
|
||||
@Value("biome-noise")
|
||||
@Default
|
||||
@Abstractable
|
||||
private NoiseSeeded biomeNoise = NoiseSeeded.zero(2);
|
||||
|
||||
@Value("blend.distance")
|
||||
@Abstractable
|
||||
@Default
|
||||
private int blendDistance = 3;
|
||||
|
||||
@Value("blend.weight")
|
||||
@Abstractable
|
||||
@Default
|
||||
private double blendWeight = 1;
|
||||
|
||||
@Value("blend.step")
|
||||
@Abstractable
|
||||
@Default
|
||||
private int blendStep = 4;
|
||||
|
||||
@Value("structures")
|
||||
@Abstractable
|
||||
@Default
|
||||
private List<ConfiguredStructure> structures = new ArrayList<>();
|
||||
|
||||
@Value("noise")
|
||||
@Abstractable
|
||||
private NoiseSeeded noiseEquation;
|
||||
|
||||
/*@Value("ores")
|
||||
@Abstractable
|
||||
@Default
|
||||
private OreHolder oreHolder = new OreHolder();*/
|
||||
|
||||
@Value("ocean.level")
|
||||
@Abstractable
|
||||
@Default
|
||||
private int seaLevel = 62;
|
||||
|
||||
@Value("ocean.palette")
|
||||
@Abstractable
|
||||
private Palette oceanPalette;
|
||||
|
||||
@Value("elevation.equation")
|
||||
@Default
|
||||
@Abstractable
|
||||
private NoiseSeeded elevationEquation = NoiseSeeded.zero(2);
|
||||
|
||||
@Value("elevation.weight")
|
||||
@Default
|
||||
@Abstractable
|
||||
private double elevationWeight = 1;
|
||||
|
||||
/*@Value("flora")
|
||||
@Abstractable
|
||||
@Default
|
||||
private List<FloraLayer> flora = new ArrayList<>();
|
||||
|
||||
@Value("trees")
|
||||
@Abstractable
|
||||
@Default
|
||||
private List<TreeLayer> trees = new ArrayList<>();*/
|
||||
|
||||
@Value("slabs.enable")
|
||||
@Abstractable
|
||||
@Default
|
||||
private boolean doSlabs = false;
|
||||
|
||||
@Value("slabs.threshold")
|
||||
@Abstractable
|
||||
@Default
|
||||
private double slabThreshold = 0.0075D;
|
||||
|
||||
@Value("slabs.palettes")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<BlockType, Palette> slabPalettes;
|
||||
|
||||
@Value("slabs.stair-palettes")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<BlockType, Palette> stairPalettes;
|
||||
|
||||
@Value("interpolate-elevation")
|
||||
@Abstractable
|
||||
@Default
|
||||
private boolean interpolateElevation = true;
|
||||
|
||||
@Value("color")
|
||||
@Default
|
||||
private int color = 0;
|
||||
|
||||
@Value("tags")
|
||||
@Default
|
||||
@Abstractable
|
||||
private Set<String> tags = new HashSet<>();
|
||||
|
||||
/*@Value("carving")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<UserDefinedCarver, Integer> carvers = new HashMap<>();*/
|
||||
|
||||
@Value("colors")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<String, Integer> colors = new HashMap<>(); // Plain ol' map, so platforms can decide what to do with colors (if anything).
|
||||
|
||||
public List<String> getExtended() {
|
||||
return extended;
|
||||
}
|
||||
|
||||
public Set<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getColors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
public double getBlendWeight() {
|
||||
return blendWeight;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public int getBlendDistance() {
|
||||
return blendDistance;
|
||||
}
|
||||
|
||||
public boolean interpolateElevation() {
|
||||
return interpolateElevation;
|
||||
}
|
||||
|
||||
public SlantHolder getSlant() {
|
||||
return slant;
|
||||
}
|
||||
|
||||
public double getSlabThreshold() {
|
||||
return slabThreshold;
|
||||
}
|
||||
|
||||
public boolean doSlabs() {
|
||||
return doSlabs;
|
||||
}
|
||||
|
||||
public BiomeTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
public Map<BlockType, Palette> getSlabPalettes() {
|
||||
return slabPalettes;
|
||||
}
|
||||
|
||||
public Map<BlockType, Palette> getStairPalettes() {
|
||||
return stairPalettes;
|
||||
}
|
||||
|
||||
public NoiseSeeded getBiomeNoise() {
|
||||
return biomeNoise;
|
||||
}
|
||||
|
||||
public NoiseSeeded getElevationEquation() {
|
||||
return elevationEquation;
|
||||
}
|
||||
|
||||
public NoiseSeeded getCarvingEquation() {
|
||||
return carvingEquation;
|
||||
}
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public int getSeaLevel() {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
public Palette getOceanPalette() {
|
||||
return oceanPalette;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public PaletteHolder getPalette() {
|
||||
return palette;
|
||||
}
|
||||
|
||||
public ProbabilityCollection<Biome> getVanilla() {
|
||||
return vanilla;
|
||||
}
|
||||
|
||||
public List<ConfiguredStructure> getStructures() {
|
||||
return structures;
|
||||
}
|
||||
|
||||
public NoiseSeeded getNoiseEquation() {
|
||||
return noiseEquation;
|
||||
}
|
||||
|
||||
public double getElevationWeight() {
|
||||
return elevationWeight;
|
||||
}
|
||||
|
||||
public int getBlendStep() {
|
||||
return blendStep;
|
||||
}
|
||||
|
||||
public Map<String, Double> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
color |= 0xff000000; // Alpha adjustment
|
||||
Parser tester = new Parser();
|
||||
Scope testScope = new Scope();
|
||||
|
||||
variables.forEach(testScope::create);
|
||||
|
||||
testScope.addInvocationVariable("x");
|
||||
testScope.addInvocationVariable("y");
|
||||
testScope.addInvocationVariable("z");
|
||||
|
||||
|
||||
//pack.getTemplate().getNoiseBuilderMap().forEach((id, builder) -> tester.registerFunction(id, new BlankFunction(builder.getDimensions()))); // Register dummy functions
|
||||
|
||||
try {
|
||||
noiseEquation.apply(0L);
|
||||
} catch(Exception e) {
|
||||
throw new ValidationException("Invalid noise sampler: ", e);
|
||||
}
|
||||
|
||||
try {
|
||||
carvingEquation.apply(0L);
|
||||
} catch(Exception e) {
|
||||
throw new ValidationException("Invalid carving sampler: ", e);
|
||||
}
|
||||
|
||||
try {
|
||||
elevationEquation.apply(0L);
|
||||
} catch(Exception e) {
|
||||
throw new ValidationException("Invalid elevation sampler: ", e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
|
||||
import com.dfsek.paralithic.functions.dynamic.DynamicFunction;
|
||||
|
||||
public class BlankFunction implements DynamicFunction {
|
||||
private final int args;
|
||||
|
||||
public BlankFunction(int args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArgNumber() {
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double eval(double... d) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStateless() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
import com.dfsek.terra.addons.biome.holder.PaletteHolder;
|
||||
import com.dfsek.terra.api.world.biome.PaletteSettings;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
public class PaletteSettingsImpl implements PaletteSettings {
|
||||
private final PaletteHolder palette;
|
||||
|
||||
public PaletteSettingsImpl(PaletteHolder palette) {
|
||||
this.palette = palette;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette getPalette(int y) {
|
||||
return palette.getPalette(y);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.Generator;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Class representing a config-defined biome
|
||||
*/
|
||||
public class UserDefinedBiome implements TerraBiome {
|
||||
private final WorldGenerator gen;
|
||||
private final ProbabilityCollection<Biome> vanilla;
|
||||
private final String id;
|
||||
private final BiomeTemplate config;
|
||||
private final int color;
|
||||
private final Set<String> tags;
|
||||
|
||||
|
||||
public UserDefinedBiome(ProbabilityCollection<Biome> vanilla, WorldGenerator gen, BiomeTemplate config) {
|
||||
this.vanilla = vanilla;
|
||||
this.gen = gen;
|
||||
this.id = config.getID();
|
||||
this.config = config;
|
||||
this.color = config.getColor();
|
||||
this.tags = config.getTags();
|
||||
tags.add("BIOME:" + id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Vanilla biomes to represent the custom biome.
|
||||
*
|
||||
* @return Collection of biomes to represent the custom biome.
|
||||
*/
|
||||
@Override
|
||||
public ProbabilityCollection<Biome> getVanillaBiomes() {
|
||||
return vanilla;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public BiomeTemplate getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generator getGenerator(World w) {
|
||||
return gen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{BIOME:" + getID() + "}";
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.seeded.BiomeBuilder;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class UserDefinedBiomeBuilder implements BiomeBuilder {
|
||||
private final BiomeTemplate template;
|
||||
private final ConfigPack pack;
|
||||
|
||||
private final Map<Long, UserDefinedBiome> biomeMap = new ConcurrentHashMap<>();
|
||||
|
||||
public UserDefinedBiomeBuilder(BiomeTemplate template, ConfigPack pack) {
|
||||
this.template = template;
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDefinedBiome apply(Long seed) {
|
||||
synchronized(biomeMap) {
|
||||
return biomeMap.computeIfAbsent(seed,
|
||||
s -> {
|
||||
WorldGenerator generator = new WorldGenerator(template.getPalette(), template.getSlant(), template.getNoiseEquation().apply(seed), template.getElevationEquation().apply(seed), template.getCarvingEquation().apply(seed), template.getBiomeNoise().apply(seed), template.getElevationWeight(),
|
||||
template.getBlendDistance(), template.getBlendStep(), template.getBlendWeight());
|
||||
return new UserDefinedBiome(template.getVanilla(), generator, template);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProbabilityCollection<Biome> getVanillaBiomes() {
|
||||
return template.getVanilla();
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
import com.dfsek.terra.addons.biome.holder.PaletteHolder;
|
||||
import com.dfsek.terra.addons.biome.slant.SlantHolder;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.world.biome.Generator;
|
||||
import com.dfsek.terra.api.world.biome.PaletteSettings;
|
||||
|
||||
public class WorldGenerator implements Generator {
|
||||
private final PaletteSettings paletteSettings;
|
||||
private final SlantHolder slantPalettes;
|
||||
|
||||
private final NoiseSampler noise;
|
||||
private final NoiseSampler elevation;
|
||||
private final NoiseSampler carving;
|
||||
|
||||
private final NoiseSampler biomeNoise;
|
||||
private final double elevationWeight;
|
||||
private final int blendDistance;
|
||||
private final int blendStep;
|
||||
private final double blendWeight;
|
||||
|
||||
public WorldGenerator(PaletteHolder palettes, SlantHolder slantPalettes, NoiseSampler noise, NoiseSampler elevation, NoiseSampler carving, NoiseSampler biomeNoise, double elevationWeight, int blendDistance, int blendStep, double blendWeight) {
|
||||
this.paletteSettings = new PaletteSettingsImpl(palettes);
|
||||
this.slantPalettes = slantPalettes;
|
||||
this.noise = noise;
|
||||
this.elevation = elevation;
|
||||
this.carving = carving;
|
||||
|
||||
this.biomeNoise = biomeNoise;
|
||||
this.elevationWeight = elevationWeight;
|
||||
this.blendDistance = blendDistance;
|
||||
this.blendStep = blendStep;
|
||||
this.blendWeight = blendWeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseSampler getBaseSampler() {
|
||||
return noise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseSampler getElevationSampler() {
|
||||
return elevation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseSampler getCarver() {
|
||||
return carving;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlendDistance() {
|
||||
return blendDistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getWeight() {
|
||||
return blendWeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaletteSettings getPaletteSettings() {
|
||||
return paletteSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseSampler getBiomeNoise() {
|
||||
return biomeNoise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getElevationWeight() {
|
||||
return elevationWeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlendStep() {
|
||||
return blendStep;
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.dfsek.terra.addons.biome.command.biome;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Runnable that locates a biome asynchronously
|
||||
*/
|
||||
public class AsyncBiomeFinder extends AsyncFeatureFinder<TerraBiome> {
|
||||
|
||||
public AsyncBiomeFinder(BiomeProvider provider, TerraBiome target, @NotNull Vector3 origin, World world, int startRadius, int maxRadius, Consumer<Vector3> callback, TerraPlugin main) {
|
||||
super(provider, target, origin, world, startRadius, maxRadius, callback, main);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get biome at location
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return TerraBiome at coordinates
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(int x, int z, TerraBiome target) {
|
||||
int res = main.getTerraConfig().getBiomeSearchResolution();
|
||||
return getProvider().getBiome(x * res, z * res).equals(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 finalizeVector(Vector3 orig) {
|
||||
return orig.multiply(main.getTerraConfig().getBiomeSearchResolution());
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package com.dfsek.terra.addons.biome.command.biome;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class AsyncFeatureFinder<T> implements Runnable {
|
||||
protected final BiomeProvider provider;
|
||||
protected final T target;
|
||||
protected final int startRadius;
|
||||
protected final int maxRadius;
|
||||
protected final int centerX;
|
||||
protected final int centerZ;
|
||||
protected final World world;
|
||||
private final Consumer<Vector3> callback;
|
||||
protected int searchSize = 1;
|
||||
protected final TerraPlugin main;
|
||||
|
||||
public AsyncFeatureFinder(BiomeProvider provider, T target, @NotNull Vector3 origin, World world, int startRadius, int maxRadius, Consumer<Vector3> callback, TerraPlugin main) {
|
||||
this.provider = provider;
|
||||
this.target = target;
|
||||
this.main = main;
|
||||
this.startRadius = startRadius;
|
||||
this.maxRadius = maxRadius;
|
||||
this.centerX = origin.getBlockX();
|
||||
this.centerZ = origin.getBlockZ();
|
||||
this.world = world;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int x = centerX;
|
||||
int z = centerZ;
|
||||
|
||||
x /= searchSize;
|
||||
z /= searchSize;
|
||||
|
||||
int run = 1;
|
||||
boolean toggle = true;
|
||||
boolean found = false;
|
||||
|
||||
main:
|
||||
for(int i = startRadius; i < maxRadius; i++) {
|
||||
for(int j = 0; j < run; j++) {
|
||||
if(isValid(x, z, target)) {
|
||||
found = true;
|
||||
break main;
|
||||
}
|
||||
if(toggle) x += 1;
|
||||
else x -= 1;
|
||||
}
|
||||
for(int j = 0; j < run; j++) {
|
||||
if(isValid(x, z, target)) {
|
||||
found = true;
|
||||
break main;
|
||||
}
|
||||
if(toggle) z += 1;
|
||||
else z -= 1;
|
||||
}
|
||||
run++;
|
||||
toggle = !toggle;
|
||||
}
|
||||
Vector3 finalSpawn = found ? finalizeVector(new Vector3(x, 0, z)) : null;
|
||||
callback.accept(finalSpawn);
|
||||
}
|
||||
|
||||
|
||||
public abstract Vector3 finalizeVector(Vector3 orig);
|
||||
|
||||
public abstract boolean isValid(int x, int z, T target);
|
||||
|
||||
public T getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public BiomeProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public int getSearchSize() {
|
||||
return searchSize;
|
||||
}
|
||||
|
||||
public void setSearchSize(int searchSize) {
|
||||
this.searchSize = searchSize;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.dfsek.terra.addons.biome.command.biome;
|
||||
|
||||
import com.dfsek.terra.addons.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.command.annotation.Subcommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.PlayerCommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.WorldCommand;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
@Command(
|
||||
subcommands = {
|
||||
@Subcommand(
|
||||
value = "info",
|
||||
aliases = {"i"},
|
||||
clazz = BiomeInfoCommand.class
|
||||
),
|
||||
@Subcommand(
|
||||
value = "locate",
|
||||
aliases = {"l"},
|
||||
clazz = BiomeLocateCommand.class
|
||||
)
|
||||
},
|
||||
usage = "/terra biome"
|
||||
)
|
||||
@WorldCommand
|
||||
@PlayerCommand
|
||||
public class BiomeCommand implements CommandTemplate {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
BiomeProvider provider = main.getWorld(player.world()).getBiomeProvider();
|
||||
UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome(player.position());
|
||||
sender.sendMessage("You are standing in " + biome.getID());
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.dfsek.terra.addons.biome.command.biome;
|
||||
|
||||
import com.dfsek.terra.addons.biome.BiomeTemplate;
|
||||
import com.dfsek.terra.addons.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.addons.biome.command.biome.arg.BiomeArgumentParser;
|
||||
import com.dfsek.terra.addons.biome.command.biome.tab.BiomeTabCompleter;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Argument;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.structure.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Command(
|
||||
arguments = {
|
||||
@Argument(
|
||||
value = "biome",
|
||||
tabCompleter = BiomeTabCompleter.class,
|
||||
argumentParser = BiomeArgumentParser.class
|
||||
)
|
||||
}
|
||||
)
|
||||
public class BiomeInfoCommand implements CommandTemplate {
|
||||
@ArgumentTarget("biome")
|
||||
private TerraBiome biome;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
sender.sendMessage("Biome info for \"" + biome.getID() + "\".");
|
||||
sender.sendMessage("Vanilla biome: " + biome.getVanillaBiomes());
|
||||
|
||||
if(biome instanceof UserDefinedBiome) {
|
||||
BiomeTemplate bio = ((UserDefinedBiome) biome).getConfig();
|
||||
|
||||
if(bio.getExtended().size() == 0) {
|
||||
sender.sendMessage("No Parent Biomes");
|
||||
} else {
|
||||
sender.sendMessage("------Parent Biomes-----");
|
||||
bio.getExtended().forEach(id -> sender.sendMessage(" - " + id));
|
||||
}
|
||||
|
||||
List<ConfiguredStructure> structureConfigs = bio.getStructures();
|
||||
|
||||
if(structureConfigs.size() == 0) {
|
||||
sender.sendMessage("No Structures");
|
||||
} else {
|
||||
sender.sendMessage("-------Structures-------");
|
||||
for(ConfiguredStructure c : structureConfigs) {
|
||||
sender.sendMessage(" - " + c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.dfsek.terra.addons.biome.command.biome;
|
||||
|
||||
import com.dfsek.terra.addons.biome.command.biome.arg.BiomeArgumentParser;
|
||||
import com.dfsek.terra.addons.biome.command.biome.tab.BiomeTabCompleter;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Argument;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.command.annotation.Switch;
|
||||
import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget;
|
||||
import com.dfsek.terra.api.command.annotation.inject.SwitchTarget;
|
||||
import com.dfsek.terra.api.command.annotation.type.PlayerCommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.WorldCommand;
|
||||
import com.dfsek.terra.api.command.arg.IntegerArgumentParser;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@PlayerCommand
|
||||
@WorldCommand
|
||||
@Command(
|
||||
arguments = {
|
||||
@Argument(
|
||||
value = "biome",
|
||||
tabCompleter = BiomeTabCompleter.class,
|
||||
argumentParser = BiomeArgumentParser.class
|
||||
),
|
||||
@Argument(
|
||||
value = "radius",
|
||||
required = false,
|
||||
defaultValue = "1000",
|
||||
argumentParser = IntegerArgumentParser.class
|
||||
)
|
||||
},
|
||||
switches = {
|
||||
@Switch(
|
||||
value = "teleport",
|
||||
aliases = {"t", "tp"}
|
||||
)
|
||||
}
|
||||
)
|
||||
public class BiomeLocateCommand implements CommandTemplate {
|
||||
|
||||
@ArgumentTarget("radius")
|
||||
private Integer radius;
|
||||
|
||||
@ArgumentTarget("biome")
|
||||
private TerraBiome biome;
|
||||
|
||||
@SwitchTarget("teleport")
|
||||
private boolean teleport;
|
||||
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
new Thread(new AsyncBiomeFinder(main.getWorld(player.world()).getBiomeProvider(), biome, player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), player.world(), 0, radius, location -> {
|
||||
if(location != null) {
|
||||
sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", biome.getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position())));
|
||||
if(teleport) {
|
||||
main.runPossiblyUnsafeTask(() -> player.position(new Vector3(location.getX(), player.position().getY(), location.getZ())));
|
||||
}
|
||||
} else sender.sendMessage("Unable to locate biome \"" + biome.getID() + "\"");
|
||||
}, main), "Biome Location Thread").start();
|
||||
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.dfsek.terra.addons.biome.command.biome.arg;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.command.arg.ArgumentParser;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
public class BiomeArgumentParser implements ArgumentParser<TerraBiome> {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public TerraBiome parse(CommandSender sender, String arg) {
|
||||
Player player = (Player) sender;
|
||||
return main.getWorld(player.world()).getConfig().getRegistry(TerraBiome.class).get(arg);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.dfsek.terra.addons.biome.command.biome.tab;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.command.tab.TabCompleter;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BiomeTabCompleter implements TabCompleter {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public List<String> complete(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
return main.getWorld(player.world()).getConfig().getRegistry(TerraBiome.class).entries().stream().map(TerraBiome::getID).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.dfsek.terra.addons.biome.holder;
|
||||
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
public class PaletteHolder {
|
||||
private final Palette[] palettes;
|
||||
private final int offset;
|
||||
|
||||
protected PaletteHolder(Palette[] palettes, int offset) {
|
||||
this.palettes = palettes;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public Palette getPalette(int y) {
|
||||
int index = y + offset;
|
||||
return index >= 0
|
||||
? index < palettes.length
|
||||
? palettes[index]
|
||||
: palettes[palettes.length - 1]
|
||||
: palettes[0];
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.dfsek.terra.addons.biome.holder;
|
||||
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class PaletteHolderBuilder {
|
||||
private final TreeMap<Integer, Palette> paletteMap = new TreeMap<>();
|
||||
|
||||
public PaletteHolderBuilder add(int y, Palette palette) {
|
||||
paletteMap.put(y, palette);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PaletteHolder build() {
|
||||
|
||||
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[] palettes = new Palette[paletteMap.lastKey() + 1 - min];
|
||||
for(int y = min; y <= FastMath.max(paletteMap.lastKey(), max); y++) {
|
||||
Palette d = null;
|
||||
for(Map.Entry<Integer, Palette> e : paletteMap.entrySet()) {
|
||||
if(e.getKey() >= y) {
|
||||
d = e.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(d == null) throw new IllegalArgumentException("No palette for Y=" + y);
|
||||
palettes[y - min] = d;
|
||||
}
|
||||
return new PaletteHolder(palettes, -min);
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.addons.biome.holder;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PaletteHolderLoader implements TypeLoader<PaletteHolder> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public PaletteHolder load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
List<Map<String, Integer>> palette = (List<Map<String, Integer>>) o;
|
||||
PaletteHolderBuilder builder = new PaletteHolderBuilder();
|
||||
for(Map<String, Integer> layer : palette) {
|
||||
for(Map.Entry<String, Integer> entry : layer.entrySet()) {
|
||||
builder.add(entry.getValue(), (Palette) configLoader.loadType(Palette.class, entry.getKey()));
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.dfsek.terra.addons.biome.slant;
|
||||
|
||||
import com.dfsek.terra.addons.biome.holder.PaletteHolder;
|
||||
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class SlantHolder {
|
||||
private final TreeMap<Double, PaletteHolder> layers;
|
||||
private final double minSlope;
|
||||
|
||||
public SlantHolder(TreeMap<Double, PaletteHolder> layers, double minSlope) {
|
||||
this.layers = layers;
|
||||
this.minSlope = minSlope;
|
||||
}
|
||||
|
||||
public PaletteHolder getPalette(double slope) {
|
||||
return layers.floorEntry(slope).getValue();
|
||||
}
|
||||
|
||||
public double getMinSlope() {
|
||||
return minSlope;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user