mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-05-20 00:30:20 +00:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| be3e50411e | |||
| c87d0446d3 | |||
| e08a105d27 | |||
| 03cecfb0fd | |||
| 502b84722e | |||
| 1abaace21b | |||
| 951270c147 | |||
| 29cc8e9ffb | |||
| c5bd7e7646 | |||
| 4cdcdc0fee | |||
| 9d4c4e35e7 | |||
| 3876cbc88e | |||
| 800b8bc3a7 | |||
| 73ca08cb3d | |||
| 664995e6eb | |||
| 130d9648ee | |||
| 869d95f5c8 | |||
| f396e0e5eb | |||
| 942a8c9c8b | |||
| 414dcdae3e | |||
| 1195a6676f | |||
| 5501f53056 | |||
| 41d6e1c648 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
import com.dfsek.terra.getGitHash
|
||||
|
||||
val versionObj = Version("6", "0", "0", true)
|
||||
val versionObj = Version("5", "1", "3", true)
|
||||
|
||||
allprojects {
|
||||
version = versionObj
|
||||
|
||||
+213
-1
@@ -1,10 +1,25 @@
|
||||
import com.dfsek.terra.configureCommon
|
||||
import com.github.javaparser.StaticJavaParser
|
||||
import com.github.javaparser.ast.CompilationUnit
|
||||
import com.github.javaparser.ast.body.FieldDeclaration
|
||||
import com.github.javaparser.ast.expr.StringLiteralExpr
|
||||
import com.github.javaparser.ast.type.PrimitiveType
|
||||
import com.github.javaparser.ast.type.PrimitiveType.Primitive
|
||||
import com.github.javaparser.ast.type.Type
|
||||
import com.github.javaparser.ast.Node
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath("com.github.javaparser:javaparser-symbol-solver-core:3.20.2")
|
||||
}
|
||||
}
|
||||
|
||||
configureCommon()
|
||||
|
||||
group = "com.dfsek.terra.common"
|
||||
@@ -14,7 +29,7 @@ dependencies {
|
||||
"shadedApi"("commons-io:commons-io:2.4")
|
||||
|
||||
"shadedApi"("com.dfsek:Paralithic:0.3.2")
|
||||
"shadedApi"("com.dfsek:Tectonic:1.3.1")
|
||||
"shadedApi"("com.dfsek:Tectonic:1.2.3")
|
||||
"shadedApi"("net.jafama:jafama:2.3.2")
|
||||
"shadedApi"("org.yaml:snakeyaml:1.27")
|
||||
"shadedApi"("org.ow2.asm:asm:9.0")
|
||||
@@ -51,4 +66,201 @@ publishing {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
create("tectonic") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
tasks.create<SourceTask>("tectonicDocs") {
|
||||
group = "terra"
|
||||
println("Scanning sources...")
|
||||
|
||||
|
||||
val docs = HashMap<String, String>()
|
||||
|
||||
val refactor = HashMap<String, String>()
|
||||
|
||||
val sources = HashMap<String, CompilationUnit>()
|
||||
|
||||
sourceSets.main.get().java.forEach {
|
||||
sources[it.name.substring(0, it.name.length - 5)] = StaticJavaParser.parse(it)
|
||||
}
|
||||
|
||||
sources.forEach { (name, unit) ->
|
||||
unit.getClassByName(name).ifPresent { declaration ->
|
||||
if (declaration.isAnnotationPresent("AutoDocAlias")) {
|
||||
refactor[name] = (declaration.getAnnotationByName("AutoDocAlias").get().childNodes[1] as StringLiteralExpr).asString()
|
||||
println("Refactoring $name to ${refactor[name]}.")
|
||||
} else if (declaration.isAnnotationPresent("AutoDocShadow")) {
|
||||
refactor[name] = (declaration.getAnnotationByName("AutoDocShadow").get().childNodes[1] as StringLiteralExpr).asString()
|
||||
println("Shadowing $name to ${refactor[name]}.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val children = HashMap<String, MutableList<ClassOrInterfaceDeclaration>>()
|
||||
sources.forEach { (name, unit) ->
|
||||
unit.getClassByName(name).ifPresent { declaration ->
|
||||
if(!declaration.isAnnotationPresent("AutoDocShadow")) {
|
||||
declaration.extendedTypes.forEach { classOrInterfaceType ->
|
||||
val inherit = classOrInterfaceType.name.asString()
|
||||
if (!children.containsKey(inherit)) children[inherit] = ArrayList()
|
||||
children[inherit]!!.add(declaration)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val linksAll = HashMap<String, Set<String>>()
|
||||
|
||||
sources.forEach { (name, unit) ->
|
||||
val doc = StringBuilder()
|
||||
doc.append("# ${generify(name, refactor)}\n")
|
||||
|
||||
var applicable = false
|
||||
|
||||
val links = HashSet<String>()
|
||||
|
||||
unit.getClassByName(name).ifPresent { declaration ->
|
||||
applicable = scanForParent(sources, declaration, "ConfigTemplate", "ValidatedConfigTemplate", "ObjectTemplate")
|
||||
|
||||
declaration.javadoc.ifPresent {
|
||||
doc.append("${sanitizeJavadoc(it.toText())} \n")
|
||||
}
|
||||
declaration.extendedTypes.forEach {
|
||||
if (!it.name.asString().equals("AbstractableTemplate")) {
|
||||
doc.append("Inherits from ${parseTypeLink(it, refactor, links, false)} \n \n")
|
||||
}
|
||||
}
|
||||
if (children.containsKey(name)) {
|
||||
doc.append("Children:\n")
|
||||
children[name]!!.forEach {
|
||||
doc.append("* ${parseTypeLink(it.name, refactor, links)}\n")
|
||||
}
|
||||
doc.append(" \n\n")
|
||||
}
|
||||
doc.append("\n")
|
||||
}
|
||||
|
||||
|
||||
unit.findAll(FieldDeclaration::class.java).filter { it.isAnnotationPresent("Value") }.forEach { fieldDeclaration ->
|
||||
doc.append("## ${(fieldDeclaration.getAnnotationByName("Value").get().childNodes[1] as StringLiteralExpr).asString()}\n")
|
||||
|
||||
if (fieldDeclaration.isAnnotationPresent("Default")) {
|
||||
doc.append("* Default value: ${fieldDeclaration.variables[0]} \n")
|
||||
}
|
||||
val type = fieldDeclaration.commonType
|
||||
doc.append("* Type: ${parseTypeLink(type, refactor, links)} \n")
|
||||
doc.append("\n")
|
||||
|
||||
fieldDeclaration.javadoc.ifPresent {
|
||||
doc.append(sanitizeJavadoc(it.toText()))
|
||||
}
|
||||
doc.append("\n\n")
|
||||
applicable = true
|
||||
}
|
||||
val s = doc.toString()
|
||||
if (s.isNotEmpty() && applicable) {
|
||||
docs[generify(name, refactor)] = s
|
||||
linksAll[name] = links
|
||||
}
|
||||
}
|
||||
println("Done. Generated ${docs.size} files")
|
||||
|
||||
val docsDir = File(buildDir, "tectonic")
|
||||
docsDir.mkdirs()
|
||||
val files = HashSet<String>()
|
||||
|
||||
docs.forEach {
|
||||
val save = File(docsDir, "${it.key}.md")
|
||||
files.add(it.key)
|
||||
if (save.exists()) save.delete()
|
||||
save.createNewFile()
|
||||
save.writeText(it.value)
|
||||
}
|
||||
|
||||
sourceSets["tectonic"].resources.forEach {
|
||||
files.add(it.name.substringBefore('.'))
|
||||
it.copyTo(File(docsDir, it.name), true)
|
||||
}
|
||||
|
||||
linksAll.forEach { (file, links) ->
|
||||
links.forEach {
|
||||
if(!files.contains(it)) println("WARNING: Dead link to \"$it\" in file \"$file\"")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun scanForParent(map: HashMap<String, CompilationUnit>, current: ClassOrInterfaceDeclaration, vararg parent: String): Boolean {
|
||||
for (type in current.implementedTypes) {
|
||||
if(parent.contains(type.childNodes[0].toString())) return true
|
||||
}
|
||||
for(type in current.extendedTypes) {
|
||||
val name = type.childNodes[0].toString()
|
||||
if(map.containsKey(name)) {
|
||||
val op = map[name]!!.getClassByName(name)
|
||||
if(op.isPresent && scanForParent(map, op.get(), *parent)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun parseTypeLink(type: Node, refactor: Map<String, String>, links: MutableSet<String>, generic: Boolean = true): String {
|
||||
val st = parseType(type, refactor)
|
||||
|
||||
if (type is Type && type.childNodes.size > 1 && generic) {
|
||||
val outer = generify(type.childNodes[0].toString(), refactor)
|
||||
|
||||
val builder = StringBuilder()
|
||||
builder.append("[$outer](./$outer)\\<")
|
||||
links.add(outer)
|
||||
|
||||
for (i in 1 until type.childNodes.size) {
|
||||
builder.append(parseTypeLink(type.childNodes[i], refactor, links, generic))
|
||||
if (i != type.childNodes.size - 1) builder.append(", ")
|
||||
}
|
||||
|
||||
builder.append("\\>")
|
||||
|
||||
return builder.toString()
|
||||
}
|
||||
links.add(st)
|
||||
return "[$st](./$st)"
|
||||
}
|
||||
|
||||
fun parseType(type: Node, refactor: Map<String, String>): String {
|
||||
if (type is PrimitiveType) {
|
||||
return when (type.type) {
|
||||
Primitive.BOOLEAN -> "Boolean"
|
||||
Primitive.BYTE -> "Byte"
|
||||
Primitive.DOUBLE -> "Double"
|
||||
Primitive.INT -> "Integer"
|
||||
Primitive.CHAR -> "Char"
|
||||
Primitive.FLOAT -> "Float"
|
||||
Primitive.SHORT -> "Short"
|
||||
Primitive.LONG -> "Long"
|
||||
else -> type.asString()
|
||||
}
|
||||
}
|
||||
if(type is Type && type.childNodes.size > 1) return generify(type.childNodes[0].toString(), refactor)
|
||||
return generify(type.toString(), refactor)
|
||||
}
|
||||
|
||||
fun generify(type: String, refactor: Map<String, String>): String {
|
||||
return when (type) {
|
||||
"HashMap", "LinkedHashMap" -> "Map"
|
||||
"ArrayList", "LinkedList", "GlueList" -> "List"
|
||||
"HashSet" -> "Set"
|
||||
else -> refactor.getOrDefault(type, type)
|
||||
}
|
||||
}
|
||||
|
||||
fun sanitizeJavadoc(doc: String): String {
|
||||
return doc
|
||||
.replace("<p>", "")
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import com.dfsek.terra.api.util.logging.Logger;
|
||||
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.world.TerraWorld;
|
||||
|
||||
import java.io.File;
|
||||
@@ -65,6 +64,4 @@ public interface TerraPlugin extends LoaderRegistrar {
|
||||
default void runPossiblyUnsafeTask(Runnable task) {
|
||||
task.run();
|
||||
}
|
||||
|
||||
Profiler getProfiler();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.dfsek.terra.api.docs;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* For use in Terra AutoDoc, to specify
|
||||
* that references to the annotated class
|
||||
* should be refactored in the documentation.
|
||||
*/
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface AutoDocAlias {
|
||||
String value();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.dfsek.terra.api.docs;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* For use in Terra AutoDoc, to specify
|
||||
* that references to the annotated class
|
||||
* should be shadowed to the target class.
|
||||
*/
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface AutoDocShadow {
|
||||
String value();
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import com.dfsek.terra.registry.OpenRegistry;
|
||||
import com.dfsek.terra.registry.exception.DuplicateEntryException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
@@ -69,7 +68,7 @@ public class CheckedRegistry<T> implements Registry<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<T> entries() {
|
||||
public Set<T> entries() {
|
||||
return registry.entries();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
@@ -42,7 +41,7 @@ public class LockedRegistry<T> implements Registry<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<T> entries() {
|
||||
public Set<T> entries() {
|
||||
return registry.entries();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.dfsek.terra.api.registry;
|
||||
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
@@ -43,7 +42,7 @@ public interface Registry<T> extends TypeLoader<T> {
|
||||
*
|
||||
* @return Set containing all entries.
|
||||
*/
|
||||
Collection<T> entries();
|
||||
Set<T> entries();
|
||||
|
||||
/**
|
||||
* Get all the keys in this registry.
|
||||
|
||||
@@ -3,13 +3,10 @@ package com.dfsek.terra.api.structures.script;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structures.loot.LootTable;
|
||||
import com.dfsek.terra.api.structures.parser.Parser;
|
||||
import com.dfsek.terra.api.structures.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.api.structures.parser.lang.Block;
|
||||
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.api.structures.script.builders.BinaryNumberFunctionBuilder;
|
||||
import com.dfsek.terra.api.structures.script.builders.BiomeFunctionBuilder;
|
||||
import com.dfsek.terra.api.structures.script.builders.BlockFunctionBuilder;
|
||||
@@ -32,7 +29,9 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.DirectBuffer;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer;
|
||||
import com.dfsek.terra.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.registry.config.FunctionRegistry;
|
||||
import com.dfsek.terra.registry.config.LootRegistry;
|
||||
import com.dfsek.terra.registry.config.ScriptRegistry;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import net.jafama.FastMath;
|
||||
@@ -40,7 +39,6 @@ import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@@ -51,10 +49,10 @@ public class StructureScript {
|
||||
private final TerraPlugin main;
|
||||
private String tempID;
|
||||
|
||||
public StructureScript(InputStream inputStream, TerraPlugin main, Registry<StructureScript> registry, Registry<LootTable> lootRegistry, Registry<FunctionBuilder<?>> functionRegistry) throws ParseException {
|
||||
public StructureScript(InputStream inputStream, TerraPlugin main, ScriptRegistry registry, LootRegistry lootRegistry, FunctionRegistry functionRegistry) throws ParseException {
|
||||
Parser parser;
|
||||
try {
|
||||
parser = new Parser(IOUtils.toString(inputStream, Charset.defaultCharset()));
|
||||
parser = new Parser(IOUtils.toString(inputStream));
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -106,31 +104,22 @@ public class StructureScript {
|
||||
* @param rotation Rotation of structure
|
||||
* @return Whether generation was successful
|
||||
*/
|
||||
@SuppressWarnings("try")
|
||||
public boolean execute(Location location, Random random, Rotation rotation) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("terrascript:" + id)) {
|
||||
StructureBuffer buffer = new StructureBuffer(location);
|
||||
boolean level = applyBlock(new TerraImplementationArguments(buffer, rotation, random, 0));
|
||||
buffer.paste();
|
||||
return level;
|
||||
}
|
||||
StructureBuffer buffer = new StructureBuffer(location);
|
||||
boolean level = applyBlock(new TerraImplementationArguments(buffer, rotation, random, 0));
|
||||
buffer.paste();
|
||||
return level;
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
public boolean execute(Location location, Chunk chunk, Random random, Rotation rotation) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_chunk:" + id)) {
|
||||
StructureBuffer buffer = computeBuffer(location, random, rotation);
|
||||
buffer.paste(chunk);
|
||||
return buffer.succeeded();
|
||||
}
|
||||
StructureBuffer buffer = computeBuffer(location, random, rotation);
|
||||
buffer.paste(chunk);
|
||||
return buffer.succeeded();
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
public boolean test(Location location, Random random, Rotation rotation) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_test:" + id)) {
|
||||
StructureBuffer buffer = computeBuffer(location, random, rotation);
|
||||
return buffer.succeeded();
|
||||
}
|
||||
StructureBuffer buffer = computeBuffer(location, random, rotation);
|
||||
return buffer.succeeded();
|
||||
}
|
||||
|
||||
private StructureBuffer computeBuffer(Location location, Random random, Rotation rotation) {
|
||||
@@ -145,19 +134,13 @@ public class StructureScript {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
public boolean executeInBuffer(Buffer buffer, Random random, Rotation rotation, int recursions) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_recursive:" + id)) {
|
||||
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, recursions));
|
||||
}
|
||||
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, recursions));
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
public boolean executeDirect(Location location, Random random, Rotation rotation) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_direct:" + id)) {
|
||||
DirectBuffer buffer = new DirectBuffer(location);
|
||||
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, 0));
|
||||
}
|
||||
DirectBuffer buffer = new DirectBuffer(location);
|
||||
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, 0));
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
||||
+3
-4
@@ -1,22 +1,21 @@
|
||||
package com.dfsek.terra.api.structures.script.builders;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structures.loot.LootTable;
|
||||
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.api.structures.script.StructureScript;
|
||||
import com.dfsek.terra.api.structures.script.functions.LootFunction;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import com.dfsek.terra.registry.config.LootRegistry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LootFunctionBuilder implements FunctionBuilder<LootFunction> {
|
||||
private final TerraPlugin main;
|
||||
private final Registry<LootTable> registry;
|
||||
private final LootRegistry registry;
|
||||
private final StructureScript script;
|
||||
|
||||
public LootFunctionBuilder(TerraPlugin main, Registry<LootTable> registry, StructureScript script) {
|
||||
public LootFunctionBuilder(TerraPlugin main, LootRegistry registry, StructureScript script) {
|
||||
this.main = main;
|
||||
this.registry = registry;
|
||||
this.script = script;
|
||||
|
||||
+3
-4
@@ -1,22 +1,21 @@
|
||||
package com.dfsek.terra.api.structures.script.builders;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structures.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.api.structures.script.StructureScript;
|
||||
import com.dfsek.terra.api.structures.script.functions.StructureFunction;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import com.dfsek.terra.registry.config.ScriptRegistry;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class StructureFunctionBuilder implements FunctionBuilder<StructureFunction> {
|
||||
private final Registry<StructureScript> registry;
|
||||
private final ScriptRegistry registry;
|
||||
private final TerraPlugin main;
|
||||
|
||||
public StructureFunctionBuilder(Registry<StructureScript> registry, TerraPlugin main) {
|
||||
public StructureFunctionBuilder(ScriptRegistry registry, TerraPlugin main) {
|
||||
this.registry = registry;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
+3
-3
@@ -3,7 +3,6 @@ package com.dfsek.terra.api.structures.script.functions;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structures.loot.LootTable;
|
||||
import com.dfsek.terra.api.structures.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||
@@ -14,19 +13,20 @@ import com.dfsek.terra.api.structures.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.api.structures.structure.RotationUtil;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedLootApplication;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import com.dfsek.terra.registry.config.LootRegistry;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class LootFunction implements Function<Void> {
|
||||
private final Registry<LootTable> registry;
|
||||
private final LootRegistry registry;
|
||||
private final Returnable<String> data;
|
||||
private final Returnable<Number> x, y, z;
|
||||
private final Position position;
|
||||
private final TerraPlugin main;
|
||||
private final StructureScript script;
|
||||
|
||||
public LootFunction(Registry<LootTable> registry, Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, TerraPlugin main, Position position, StructureScript script) {
|
||||
public LootFunction(LootRegistry registry, Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, TerraPlugin main, Position position, StructureScript script) {
|
||||
this.registry = registry;
|
||||
this.position = position;
|
||||
this.data = data;
|
||||
|
||||
+3
-3
@@ -3,7 +3,6 @@ package com.dfsek.terra.api.structures.script.functions;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structures.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||
import com.dfsek.terra.api.structures.parser.lang.functions.Function;
|
||||
@@ -14,20 +13,21 @@ import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.structures.structure.RotationUtil;
|
||||
import com.dfsek.terra.api.structures.structure.buffer.IntermediateBuffer;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import com.dfsek.terra.registry.config.ScriptRegistry;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class StructureFunction implements Function<Boolean> {
|
||||
private final Registry<StructureScript> registry;
|
||||
private final ScriptRegistry registry;
|
||||
private final Returnable<String> id;
|
||||
private final Returnable<Number> x, y, z;
|
||||
private final Position position;
|
||||
private final TerraPlugin main;
|
||||
private final List<Returnable<String>> rotations;
|
||||
|
||||
public StructureFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> id, List<Returnable<String>> rotations, Registry<StructureScript> registry, Position position, TerraPlugin main) {
|
||||
public StructureFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> id, List<Returnable<String>> rotations, ScriptRegistry registry, Position position, TerraPlugin main) {
|
||||
this.registry = registry;
|
||||
this.id = id;
|
||||
this.position = position;
|
||||
|
||||
@@ -15,7 +15,6 @@ public class Tokenizer {
|
||||
private final Lookahead reader;
|
||||
private final Stack<Token> brackets = new Stack<>();
|
||||
private Token current;
|
||||
private Token last;
|
||||
|
||||
public Tokenizer(String data) throws ParseException {
|
||||
reader = new Lookahead(new StringReader(data + '\0'));
|
||||
@@ -29,7 +28,7 @@ public class Tokenizer {
|
||||
* @throws ParseException If token does not exist
|
||||
*/
|
||||
public Token get() throws ParseException {
|
||||
if(!hasNext()) throw new ParseException("Unexpected end of input", last.getPosition());
|
||||
if(!hasNext()) throw new ParseException("Unexpected end of input", current.getPosition());
|
||||
return current;
|
||||
}
|
||||
|
||||
@@ -40,7 +39,7 @@ public class Tokenizer {
|
||||
* @throws ParseException If token does not exist
|
||||
*/
|
||||
public Token consume() throws ParseException {
|
||||
if(!hasNext()) throw new ParseException("Unexpected end of input", last.getPosition());
|
||||
if(!hasNext()) throw new ParseException("Unexpected end of input", current.getPosition());
|
||||
Token temp = current;
|
||||
current = fetchCheck();
|
||||
return temp;
|
||||
@@ -58,9 +57,8 @@ public class Tokenizer {
|
||||
private Token fetchCheck() throws ParseException {
|
||||
Token fetch = fetch();
|
||||
if(fetch != null) {
|
||||
last = fetch;
|
||||
if(fetch.getType() == Token.Type.BLOCK_BEGIN) brackets.push(fetch); // Opening bracket
|
||||
else if(fetch.getType() == Token.Type.BLOCK_END) {
|
||||
if(fetch.getType().equals(Token.Type.BLOCK_BEGIN)) brackets.push(fetch); // Opening bracket
|
||||
else if(fetch.getType().equals(Token.Type.BLOCK_END)) {
|
||||
if(!brackets.isEmpty()) brackets.pop();
|
||||
else throw new ParseException("Dangling opening brace", new Position(0, 0));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ public class Transformer<F, T> {
|
||||
private final LinkedHashMap<Transform<F, T>, List<Validator<T>>> transforms = new LinkedHashMap<>();
|
||||
|
||||
@SafeVarargs
|
||||
@SuppressWarnings("varargs")
|
||||
public final Builder<F, T> addTransform(Transform<F, T> transform, Validator<T>... validators) {
|
||||
transforms.put(transform, Arrays.asList(validators));
|
||||
return this;
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.dfsek.terra.api.util.generic.pair;
|
||||
|
||||
public final class ImmutablePair<L, R> {
|
||||
public class ImmutablePair<L, R> {
|
||||
private final L left;
|
||||
private final R right;
|
||||
|
||||
private static final ImmutablePair<?, ?> NULL = new ImmutablePair<>(null, null);
|
||||
|
||||
private ImmutablePair(L left, R right) {
|
||||
public ImmutablePair(L left, R right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
@@ -23,12 +21,7 @@ public final class ImmutablePair<L, R> {
|
||||
return left;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <L1, R1> ImmutablePair<L1, R1> ofNull() {
|
||||
return (ImmutablePair<L1, R1>) NULL;
|
||||
}
|
||||
|
||||
public Pair<L, R> mutable() {
|
||||
return Pair.of(left, right);
|
||||
return new Pair<>(left, right);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ public class Pair<L, R> {
|
||||
private L left;
|
||||
private R right;
|
||||
|
||||
private Pair(L left, R right) {
|
||||
public Pair(L left, R right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
@@ -30,6 +30,6 @@ public class Pair<L, R> {
|
||||
}
|
||||
|
||||
public ImmutablePair<L, R> immutable() {
|
||||
return ImmutablePair.of(left, right);
|
||||
return new ImmutablePair<>(left, right);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.dfsek.terra.api.util.seeded;
|
||||
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface NoiseProvider extends Supplier<ObjectTemplate<NoiseSeeded>> {
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.dfsek.terra.api.util.world;
|
||||
|
||||
import com.dfsek.terra.api.math.MathUtil;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
import com.dfsek.terra.api.world.palette.holder.PaletteHolder;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.world.generation.math.samplers.Sampler;
|
||||
|
||||
public final class PaletteUtil {
|
||||
public static Palette getPalette(int x, int y, int z, BiomeTemplate c, Sampler sampler) {
|
||||
public static Palette<BlockData> getPalette(int x, int y, int z, BiomeTemplate c, Sampler sampler) {
|
||||
PaletteHolder slant = c.getSlantPalette();
|
||||
if(slant != null && MathUtil.derivative(sampler, x, y, z) > c.getSlantThreshold()) {
|
||||
return slant.getPalette(y);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.dfsek.terra.api.world.biome;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
import com.dfsek.terra.world.generation.math.samplers.terrain.TerrainSampler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Generator {
|
||||
/**
|
||||
@@ -37,13 +35,11 @@ public interface Generator {
|
||||
*
|
||||
* @return BlocPalette - The biome's palette.
|
||||
*/
|
||||
Palette getPalette(int y);
|
||||
Palette<BlockData> getPalette(int y);
|
||||
|
||||
NoiseSampler getBiomeNoise();
|
||||
|
||||
double getElevationWeight();
|
||||
|
||||
int getBlendStep();
|
||||
|
||||
List<TerrainSampler> getTerrainSamplers();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.dfsek.terra.api.world.palette;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NoisePalette extends Palette {
|
||||
public class NoisePalette<E> extends Palette<E> {
|
||||
private final NoiseSampler sampler;
|
||||
private final boolean is2D;
|
||||
|
||||
@@ -15,11 +14,11 @@ public class NoisePalette extends Palette {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData get(int layer, double x, double y, double z) {
|
||||
PaletteLayer paletteLayer;
|
||||
public E get(int layer, double x, double y, double z) {
|
||||
PaletteLayer<E> paletteLayer;
|
||||
if(layer > this.getSize()) paletteLayer = this.getLayers().get(this.getLayers().size() - 1);
|
||||
else {
|
||||
List<PaletteLayer> pl = getLayers();
|
||||
List<PaletteLayer<E>> pl = getLayers();
|
||||
if(layer >= pl.size()) paletteLayer = pl.get(pl.size() - 1);
|
||||
else paletteLayer = pl.get(layer);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.api.world.palette;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
|
||||
@@ -12,8 +11,8 @@ import java.util.Random;
|
||||
* A class representation of a "slice" of the world.
|
||||
* Used to get a section of blocks, based on the depth at which they are found.
|
||||
*/
|
||||
public abstract class Palette {
|
||||
private final List<PaletteLayer> pallet = new GlueList<>();
|
||||
public abstract class Palette<E> {
|
||||
private final List<PaletteLayer<E>> pallet = new GlueList<>();
|
||||
|
||||
/**
|
||||
* Constructs a blank palette.
|
||||
@@ -22,16 +21,16 @@ public abstract class Palette {
|
||||
|
||||
}
|
||||
|
||||
public com.dfsek.terra.api.world.palette.Palette add(BlockData m, int layers, NoiseSampler sampler) {
|
||||
public com.dfsek.terra.api.world.palette.Palette<E> add(E m, int layers, NoiseSampler sampler) {
|
||||
for(int i = 0; i < layers; i++) {
|
||||
pallet.add(new PaletteLayer(m, sampler));
|
||||
pallet.add(new PaletteLayer<>(m, sampler));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public com.dfsek.terra.api.world.palette.Palette add(ProbabilityCollection<BlockData> m, int layers, NoiseSampler sampler) {
|
||||
public com.dfsek.terra.api.world.palette.Palette<E> add(ProbabilityCollection<E> m, int layers, NoiseSampler sampler) {
|
||||
for(int i = 0; i < layers; i++) {
|
||||
pallet.add(new PaletteLayer(m, sampler));
|
||||
pallet.add(new PaletteLayer<>(m, sampler));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -42,25 +41,25 @@ public abstract class Palette {
|
||||
* @param layer - The layer at which to fetch the material.
|
||||
* @return BlockData - The material fetched.
|
||||
*/
|
||||
public abstract BlockData get(int layer, double x, double y, double z);
|
||||
public abstract E get(int layer, double x, double y, double z);
|
||||
|
||||
|
||||
public int getSize() {
|
||||
return pallet.size();
|
||||
}
|
||||
|
||||
public List<PaletteLayer> getLayers() {
|
||||
public List<PaletteLayer<E>> getLayers() {
|
||||
return pallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class representation of a layer of a BlockPalette.
|
||||
*/
|
||||
public static class PaletteLayer {
|
||||
public static class PaletteLayer<E> {
|
||||
private final boolean col; // Is layer using a collection?
|
||||
private ProbabilityCollection<BlockData> collection;
|
||||
private ProbabilityCollection<E> collection;
|
||||
private final NoiseSampler sampler;
|
||||
private BlockData m;
|
||||
private E m;
|
||||
|
||||
/**
|
||||
* Constructs a PaletteLayerHolder with a ProbabilityCollection of materials and a number of layers.
|
||||
@@ -68,7 +67,7 @@ public abstract class Palette {
|
||||
* @param type The collection of materials to choose from.
|
||||
* @param sampler Noise sampler to use
|
||||
*/
|
||||
public PaletteLayer(ProbabilityCollection<BlockData> type, NoiseSampler sampler) {
|
||||
public PaletteLayer(ProbabilityCollection<E> type, NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
this.col = true;
|
||||
this.collection = type;
|
||||
@@ -80,7 +79,7 @@ public abstract class Palette {
|
||||
* @param type The material to use.
|
||||
* @param sampler Noise sampler to use
|
||||
*/
|
||||
public PaletteLayer(BlockData type, NoiseSampler sampler) {
|
||||
public PaletteLayer(E type, NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
this.col = false;
|
||||
this.m = type;
|
||||
@@ -95,18 +94,18 @@ public abstract class Palette {
|
||||
*
|
||||
* @return Material - the material..
|
||||
*/
|
||||
public BlockData get(Random random) {
|
||||
public E get(Random random) {
|
||||
if(col) return this.collection.get(random);
|
||||
return m;
|
||||
}
|
||||
|
||||
public BlockData get(NoiseSampler random, double x, double y, double z, boolean is2D) {
|
||||
public E get(NoiseSampler random, double x, double y, double z, boolean is2D) {
|
||||
if(col && is2D) return this.collection.get(random, x, z);
|
||||
else if(col) return this.collection.get(random, x, y, z);
|
||||
return m;
|
||||
}
|
||||
|
||||
public ProbabilityCollection<BlockData> getCollection() {
|
||||
public ProbabilityCollection<E> getCollection() {
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package com.dfsek.terra.api.world.palette;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
public class SinglePalette<E> extends Palette<E> {
|
||||
private final E item;
|
||||
|
||||
public class SinglePalette extends Palette {
|
||||
private final BlockData item;
|
||||
|
||||
public SinglePalette(BlockData item) {
|
||||
public SinglePalette(E item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData get(int layer, double x, double y, double z) {
|
||||
public E get(int layer, double x, double y, double z) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.dfsek.terra.api.world.palette.holder;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
|
||||
public class PaletteHolder {
|
||||
private final Palette[] palettes;
|
||||
private final Palette<BlockData>[] palettes;
|
||||
|
||||
protected PaletteHolder(Palette[] palettes) {
|
||||
protected PaletteHolder(Palette<BlockData>[] palettes) {
|
||||
this.palettes = palettes;
|
||||
}
|
||||
|
||||
public Palette getPalette(int y) {
|
||||
public Palette<BlockData> getPalette(int y) {
|
||||
return palettes[y];
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.api.world.palette.holder;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
@@ -7,19 +8,19 @@ import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class PaletteHolderBuilder {
|
||||
private final TreeMap<Integer, Palette> paletteMap = new TreeMap<>();
|
||||
private final TreeMap<Integer, Palette<BlockData>> paletteMap = new TreeMap<>();
|
||||
|
||||
public PaletteHolderBuilder add(int y, Palette palette) {
|
||||
public PaletteHolderBuilder add(int y, Palette<BlockData> palette) {
|
||||
paletteMap.put(y, palette);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||
public PaletteHolder build() {
|
||||
Palette[] palettes = new Palette[paletteMap.lastKey() + 1];
|
||||
Palette<BlockData>[] palettes = new Palette[paletteMap.lastKey() + 1];
|
||||
for(int y = 0; y <= FastMath.max(paletteMap.lastKey(), 255); y++) {
|
||||
Palette d = null;
|
||||
for(Map.Entry<Integer, Palette> e : paletteMap.entrySet()) {
|
||||
Palette<BlockData> d = null;
|
||||
for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) {
|
||||
if(e.getKey() >= y) {
|
||||
d = e.getValue();
|
||||
break;
|
||||
|
||||
@@ -14,6 +14,6 @@ public class BiomeArgumentParser implements ArgumentParser<TerraBiome> {
|
||||
@Override
|
||||
public TerraBiome parse(CommandSender sender, String arg) {
|
||||
Player player = (Player) sender;
|
||||
return main.getWorld(player.getWorld()).getConfig().getRegistry(TerraBiome.class).get(arg);
|
||||
return main.getWorld(player.getWorld()).getConfig().getBiomeRegistry().get(arg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@ public class BiomeTabCompleter implements TabCompleter {
|
||||
@Override
|
||||
public List<String> complete(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
return main.getWorld(player.getWorld()).getConfig().getRegistry(TerraBiome.class).entries().stream().map(TerraBiome::getID).collect(Collectors.toList());
|
||||
return main.getWorld(player.getWorld()).getConfig().getBiomeRegistry().entries().stream().map(TerraBiome::getID).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,16 @@ 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.type.DebugCommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.PlayerCommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.WorldCommand;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
|
||||
@Command
|
||||
@WorldCommand
|
||||
@PlayerCommand
|
||||
@DebugCommand
|
||||
public class ProfileQueryCommand implements CommandTemplate {
|
||||
@Inject
|
||||
@@ -15,9 +21,8 @@ public class ProfileQueryCommand implements CommandTemplate {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
StringBuilder data = new StringBuilder("Terra Profiler data dump: \n");
|
||||
main.getProfiler().getTimings().forEach((id, timings) -> data.append(id).append(": ").append(timings.toString()).append('\n'));
|
||||
main.logger().info(data.toString());
|
||||
sender.sendMessage("Profiler data dumped to console.");
|
||||
Player player = (Player) sender;
|
||||
TerraWorld world = main.getWorld(player.getWorld());
|
||||
player.sendMessage(world.getProfiler().getResultsFormatted());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,16 @@ 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.type.DebugCommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.PlayerCommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.WorldCommand;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
|
||||
@Command
|
||||
@WorldCommand
|
||||
@PlayerCommand
|
||||
@DebugCommand
|
||||
public class ProfileResetCommand implements CommandTemplate {
|
||||
@Inject
|
||||
@@ -15,7 +21,9 @@ public class ProfileResetCommand implements CommandTemplate {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
main.getProfiler().reset();
|
||||
sender.sendMessage("Profiler reset.");
|
||||
Player player = (Player) sender;
|
||||
TerraWorld world = main.getWorld(player.getWorld());
|
||||
world.getProfiler().reset();
|
||||
player.sendMessage("Profiler reset.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,16 @@ 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.type.DebugCommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.PlayerCommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.WorldCommand;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
|
||||
@Command
|
||||
@WorldCommand
|
||||
@PlayerCommand
|
||||
@DebugCommand
|
||||
public class ProfileStartCommand implements CommandTemplate {
|
||||
@Inject
|
||||
@@ -15,7 +21,9 @@ public class ProfileStartCommand implements CommandTemplate {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
main.getProfiler().start();
|
||||
sender.sendMessage("Profiling enabled.");
|
||||
Player player = (Player) sender;
|
||||
TerraWorld world = main.getWorld(player.getWorld());
|
||||
world.getProfiler().setProfiling(true);
|
||||
player.sendMessage("Profiling enabled.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,16 @@ 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.type.DebugCommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.PlayerCommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.WorldCommand;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
|
||||
@Command
|
||||
@WorldCommand
|
||||
@PlayerCommand
|
||||
@DebugCommand
|
||||
public class ProfileStopCommand implements CommandTemplate {
|
||||
@Inject
|
||||
@@ -15,7 +21,9 @@ public class ProfileStopCommand implements CommandTemplate {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
main.getProfiler().stop();
|
||||
sender.sendMessage("Profiling disabled.");
|
||||
Player player = (Player) sender;
|
||||
TerraWorld world = main.getWorld(player.getWorld());
|
||||
world.getProfiler().setProfiling(false);
|
||||
player.sendMessage("Profiling disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,6 +13,6 @@ public class ScriptArgumentParser implements ArgumentParser<StructureScript> {
|
||||
|
||||
@Override
|
||||
public StructureScript parse(CommandSender sender, String arg) {
|
||||
return main.getWorld(((Player) sender).getWorld()).getConfig().getRegistry(StructureScript.class).get(arg);
|
||||
return main.getWorld(((Player) sender).getWorld()).getConfig().getScriptRegistry().get(arg);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,6 +13,6 @@ public class StructureArgumentParser implements ArgumentParser<TerraStructure> {
|
||||
|
||||
@Override
|
||||
public TerraStructure parse(CommandSender sender, String arg) {
|
||||
return main.getWorld(((Player) sender).getWorld()).getConfig().getRegistry(TerraStructure.class).get(arg);
|
||||
return main.getWorld(((Player) sender).getWorld()).getConfig().getStructureRegistry().get(arg);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,6 +16,6 @@ public class ScriptCompleter implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public List<String> complete(CommandSender sender) {
|
||||
return main.getWorld(((Player) sender).getWorld()).getConfig().getRegistry(StructureScript.class).entries().stream().map(StructureScript::getId).collect(Collectors.toList());
|
||||
return main.getWorld(((Player) sender).getWorld()).getConfig().getScriptRegistry().entries().stream().map(StructureScript::getId).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -5,7 +5,6 @@ import com.dfsek.terra.api.command.tab.TabCompleter;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
import com.dfsek.terra.world.population.items.TerraStructure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -17,6 +16,6 @@ public class StructureCompleter implements TabCompleter {
|
||||
@Override
|
||||
public List<String> complete(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
return new ArrayList<>(main.getWorld(player.getWorld()).getConfig().getRegistry(TerraStructure.class).keys());
|
||||
return new ArrayList<>(main.getWorld(player.getWorld()).getConfig().getStructureRegistry().keys());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.dfsek.terra.config.builder;
|
||||
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.platform.world.Biome;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.seeded.SeededBuilder;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
|
||||
@AutoDocAlias("TerraBiome")
|
||||
public interface BiomeBuilder extends SeededBuilder<TerraBiome> {
|
||||
ProbabilityCollection<Biome> getVanillaBiomes();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.world.flora.Flora;
|
||||
import com.dfsek.terra.api.world.palette.NoisePalette;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
@@ -12,7 +13,7 @@ import com.dfsek.terra.world.population.items.flora.TerraFlora;
|
||||
public class FloraFactory implements ConfigFactory<FloraTemplate, Flora> {
|
||||
@Override
|
||||
public TerraFlora build(FloraTemplate config, TerraPlugin main) {
|
||||
Palette palette = new NoisePalette(new WhiteNoiseSampler(2403), false);
|
||||
Palette<BlockData> palette = new NoisePalette<>(new WhiteNoiseSampler(2403), false);
|
||||
for(PaletteLayerHolder layer : config.getFloraPalette()) {
|
||||
palette.add(layer.getLayer(), layer.getSize(), layer.getSampler());
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.world.palette.NoisePalette;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
import com.dfsek.terra.api.world.palette.holder.PaletteLayerHolder;
|
||||
import com.dfsek.terra.config.templates.PaletteTemplate;
|
||||
|
||||
public class PaletteFactory implements ConfigFactory<PaletteTemplate, Palette> {
|
||||
public class PaletteFactory implements ConfigFactory<PaletteTemplate, Palette<BlockData>> {
|
||||
@Override
|
||||
public Palette build(PaletteTemplate config, TerraPlugin main) {
|
||||
NoisePalette palette = new NoisePalette(config.getNoise().apply(2403L), config.getNoise().getDimensions() == 2);
|
||||
public Palette<BlockData> build(PaletteTemplate config, TerraPlugin main) {
|
||||
NoisePalette<BlockData> palette = new NoisePalette<>(config.getNoise().apply(2403L), config.getNoise().getDimensions() == 2);
|
||||
for(PaletteLayerHolder layer : config.getPalette()) {
|
||||
palette.add(layer.getLayer(), layer.getSize(), layer.getSampler());
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ZIPLoader extends Loader {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(!entry.isDirectory() && entry.getName().startsWith(directory) && entry.getName().endsWith(extension)) {
|
||||
try {
|
||||
String rel = entry.getName().substring(directory.length());
|
||||
String rel = entry.getName().substring(directory.length() + 1);
|
||||
streams.put(rel, file.getInputStream(entry));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.flora.Flora;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
@@ -14,6 +15,7 @@ import java.util.Map;
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class Types {
|
||||
public static final Type BLOCK_DATA_PALETTE_TYPE;
|
||||
public static final Type BLOCK_DATA_PROBABILITY_COLLECTION_TYPE;
|
||||
public static final Type FLORA_PROBABILITY_COLLECTION_TYPE;
|
||||
public static final Type TREE_PROBABILITY_COLLECTION_TYPE;
|
||||
@@ -21,6 +23,7 @@ public final class Types {
|
||||
public static final Type TERRA_BIOME_TERRA_BIOME_PROBABILITY_COLLECTION_MAP;
|
||||
|
||||
static {
|
||||
BLOCK_DATA_PALETTE_TYPE = getType("blockDataPalette");
|
||||
BLOCK_DATA_PROBABILITY_COLLECTION_TYPE = getType("blockDataProbabilityCollection");
|
||||
FLORA_PROBABILITY_COLLECTION_TYPE = getType("floraProbabilityCollection");
|
||||
TREE_PROBABILITY_COLLECTION_TYPE = getType("treeProbabilityCollection");
|
||||
@@ -28,6 +31,7 @@ public final class Types {
|
||||
TERRA_BIOME_TERRA_BIOME_PROBABILITY_COLLECTION_MAP = getType("terraBiomeProbabilityCollectionMap");
|
||||
}
|
||||
|
||||
private Palette<BlockData> blockDataPalette;
|
||||
private ProbabilityCollection<BlockData> blockDataProbabilityCollection;
|
||||
private ProbabilityCollection<Flora> floraProbabilityCollection;
|
||||
private ProbabilityCollection<Tree> treeProbabilityCollection;
|
||||
|
||||
@@ -18,7 +18,7 @@ public class OreHolderLoader implements TypeLoader<OreHolder> {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
|
||||
for(Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
holder.add(configLoader.loadClass(Ore.class, entry.getKey()), configLoader.loadClass(OreConfig.class, entry.getValue()), entry.getKey());
|
||||
holder.add(configLoader.loadClass(Ore.class, entry.getKey()), (OreConfig) configLoader.loadType(OreConfig.class, entry.getValue()));
|
||||
}
|
||||
|
||||
return holder;
|
||||
|
||||
+12
@@ -11,16 +11,28 @@ import com.dfsek.terra.api.world.biome.provider.StandardBiomeProvider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Configures a biome pipeline.
|
||||
*/
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
public class BiomePipelineTemplate extends BiomeProviderTemplate {
|
||||
private final TerraPlugin main;
|
||||
/**
|
||||
* Initial size of biome pipeline chunks.
|
||||
*/
|
||||
@Value("pipeline.initial-size")
|
||||
@Default
|
||||
private int initialSize = 2;
|
||||
|
||||
/**
|
||||
* Mutator stages to be used in this biome pipeline.
|
||||
*/
|
||||
@Value("pipeline.stages")
|
||||
private List<StageSeeded> stages;
|
||||
|
||||
/**
|
||||
* Biome source to initialize the pipeline.
|
||||
*/
|
||||
@Value("pipeline.source")
|
||||
private SourceSeeded source;
|
||||
|
||||
|
||||
+15
-2
@@ -8,10 +8,21 @@ import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
|
||||
|
||||
/**
|
||||
* Configures a biome provider.
|
||||
*/
|
||||
public abstract class BiomeProviderTemplate implements ObjectTemplate<BiomeProvider.BiomeProviderBuilder>, BiomeProvider.BiomeProviderBuilder {
|
||||
/**
|
||||
* Resolution of this provider.
|
||||
* A resolution of 1 means that 1 block = 1 sample.
|
||||
*/
|
||||
@Value("resolution")
|
||||
@Default
|
||||
protected int resolution = 1;
|
||||
|
||||
/**
|
||||
* Noise function to use for blending biomes at edges.
|
||||
*/
|
||||
@Value("blend.noise")
|
||||
@Default
|
||||
protected NoiseSeeded blend = new NoiseSeeded() {
|
||||
@@ -25,11 +36,13 @@ public abstract class BiomeProviderTemplate implements ObjectTemplate<BiomeProvi
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Amplitude of edge blending, in blocks.
|
||||
*/
|
||||
@Value("blend.amplitude")
|
||||
@Default
|
||||
protected double blendAmp = 0d;
|
||||
@Value("type")
|
||||
BiomeProvider.Type type;
|
||||
|
||||
@Override
|
||||
public BiomeProvider.BiomeProviderBuilder get() {
|
||||
|
||||
+10
@@ -9,11 +9,21 @@ import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Configures an image biome provider.
|
||||
*/
|
||||
public class ImageProviderTemplate extends BiomeProviderTemplate {
|
||||
private final Registry<BiomeBuilder> biomes;
|
||||
|
||||
/**
|
||||
* Image to use for biome selection.
|
||||
*/
|
||||
@Value("image.name")
|
||||
private BufferedImage image;
|
||||
|
||||
/**
|
||||
* How the image should be aligned.
|
||||
*/
|
||||
@Value("image.align")
|
||||
private ImageBiomeProvider.Align align;
|
||||
|
||||
|
||||
+6
@@ -5,7 +5,13 @@ 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;
|
||||
|
||||
/**
|
||||
* Configures a single-biome provider.
|
||||
*/
|
||||
public class SingleBiomeProviderTemplate extends BiomeProviderTemplate {
|
||||
/**
|
||||
* The biome.
|
||||
*/
|
||||
@Value("biome")
|
||||
private BiomeBuilder biome;
|
||||
|
||||
|
||||
+11
@@ -1,16 +1,27 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.source;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Configures a noise-based biome source.
|
||||
*/
|
||||
@AutoDocAlias("NoiseSource")
|
||||
public class NoiseSourceTemplate extends SourceTemplate {
|
||||
/**
|
||||
* Noise function to use for selecting biomes.
|
||||
*/
|
||||
@Value("noise")
|
||||
private NoiseSeeded noise;
|
||||
|
||||
/**
|
||||
* ProbabilityCollection of biomes to use.
|
||||
*/
|
||||
@Value("biomes")
|
||||
private ProbabilityCollection<BiomeBuilder> biomes;
|
||||
|
||||
|
||||
+2
@@ -1,9 +1,11 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.source;
|
||||
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.util.seeded.SourceSeeded;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource;
|
||||
|
||||
@AutoDocAlias("SourceSeeded")
|
||||
public abstract class SourceTemplate implements ObjectTemplate<SourceSeeded>, SourceSeeded {
|
||||
@Override
|
||||
public SourceSeeded get() {
|
||||
|
||||
+5
@@ -2,12 +2,17 @@ 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.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.util.seeded.SeededBuilder;
|
||||
import com.dfsek.terra.api.util.seeded.StageSeeded;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.stages.Stage;
|
||||
|
||||
@AutoDocAlias("StageSeeded")
|
||||
public abstract class StageTemplate implements ObjectTemplate<SeededBuilder<Stage>>, StageSeeded {
|
||||
/**
|
||||
* Noise function to use for mutating biomes in this stage.
|
||||
*/
|
||||
@Value("noise")
|
||||
protected NoiseSeeded noise;
|
||||
|
||||
|
||||
+15
@@ -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.docs.AutoDocAlias;
|
||||
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;
|
||||
@@ -11,16 +12,30 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AutoDocAlias("BorderListMutator")
|
||||
public class BorderListMutatorTemplate extends MutatorStageTemplate {
|
||||
/**
|
||||
* Tag of the biome on the external side of the border.
|
||||
*/
|
||||
@Value("from")
|
||||
private String from;
|
||||
|
||||
/**
|
||||
* Tag of biomes to replace when bordering biomes with
|
||||
* tag "from".
|
||||
*/
|
||||
@Value("default-replace")
|
||||
private String defaultReplace;
|
||||
|
||||
/**
|
||||
* Default replacement biomes.
|
||||
*/
|
||||
@Value("default-to")
|
||||
private ProbabilityCollection<BiomeBuilder> defaultTo;
|
||||
|
||||
/**
|
||||
* Map of single biomes to their replacements.
|
||||
*/
|
||||
@Value("replace")
|
||||
private Map<BiomeBuilder, ProbabilityCollection<BiomeBuilder>> replace;
|
||||
|
||||
|
||||
+13
@@ -1,19 +1,32 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
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;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AutoDocAlias("BorderMutator")
|
||||
public class BorderMutatorTemplate extends MutatorStageTemplate {
|
||||
/**
|
||||
* Tag of the biome on the external side of the border.
|
||||
*/
|
||||
@Value("from")
|
||||
private String from;
|
||||
|
||||
/**
|
||||
* Tag of biomes to replace when bordering biomes
|
||||
* with tag "from"
|
||||
*/
|
||||
@Value("replace")
|
||||
private String replace;
|
||||
|
||||
/**
|
||||
* Collection of biomes to place at borders
|
||||
* of "from" and "to"
|
||||
*/
|
||||
@Value("to")
|
||||
private ProbabilityCollection<BiomeBuilder> to;
|
||||
|
||||
|
||||
+2
@@ -1,10 +1,12 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator;
|
||||
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.stages.MutatorStage;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.stages.Stage;
|
||||
import com.dfsek.terra.config.loaders.config.biome.templates.stage.StageTemplate;
|
||||
|
||||
@AutoDocAlias("MutatorStage")
|
||||
public abstract class MutatorStageTemplate extends StageTemplate {
|
||||
public abstract BiomeMutator build(long seed);
|
||||
|
||||
|
||||
+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.docs.AutoDocAlias;
|
||||
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;
|
||||
@@ -11,7 +12,11 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AutoDocAlias("ReplaceListMutator")
|
||||
public class ReplaceListMutatorTemplate extends MutatorStageTemplate {
|
||||
/**
|
||||
* Default tag to replace from
|
||||
*/
|
||||
@Value("default-from")
|
||||
private String defaultFrom;
|
||||
|
||||
|
||||
+8
@@ -1,16 +1,24 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
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;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AutoDocAlias("ReplaceMutator")
|
||||
public class ReplaceMutatorTemplate extends MutatorStageTemplate {
|
||||
/**
|
||||
* Tag of biomes to replace.
|
||||
*/
|
||||
@Value("from")
|
||||
private String from;
|
||||
|
||||
/**
|
||||
* Biomes to replace with.
|
||||
*/
|
||||
@Value("to")
|
||||
private ProbabilityCollection<BiomeBuilder> to;
|
||||
|
||||
|
||||
+2
@@ -1,8 +1,10 @@
|
||||
package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator;
|
||||
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator;
|
||||
import com.dfsek.terra.api.world.biome.pipeline.mutator.SmoothMutator;
|
||||
|
||||
@AutoDocAlias("SmoothMutator")
|
||||
public class SmoothMutatorTemplate extends MutatorStageTemplate {
|
||||
@Override
|
||||
public BiomeMutator build(long seed) {
|
||||
|
||||
+5
-4
@@ -6,19 +6,20 @@ 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.registry.Registry;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseProvider;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
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;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@AutoDocAlias("NoiseSeeded")
|
||||
public class NoiseSamplerBuilderLoader implements TypeLoader<NoiseSeeded> {
|
||||
private final Registry<NoiseProvider> noiseRegistry;
|
||||
private final NoiseRegistry noiseRegistry;
|
||||
|
||||
public NoiseSamplerBuilderLoader(Registry<NoiseProvider> noiseRegistry) {
|
||||
public NoiseSamplerBuilderLoader(NoiseRegistry noiseRegistry) {
|
||||
this.noiseRegistry = noiseRegistry;
|
||||
}
|
||||
|
||||
|
||||
+20
-2
@@ -2,28 +2,46 @@ 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.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.samplers.DomainWarpedSampler;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
|
||||
/**
|
||||
* Defines a domain-warped noise function.
|
||||
*/
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@AutoDocAlias("DomainWarpedSampler")
|
||||
public class DomainWarpTemplate extends SamplerTemplate<DomainWarpedSampler> {
|
||||
/**
|
||||
* Noise function used to warp input function.
|
||||
*/
|
||||
@Value("warp")
|
||||
private NoiseSeeded warp;
|
||||
|
||||
/**
|
||||
* Input function (function to be warped)
|
||||
*/
|
||||
@Value("function")
|
||||
private NoiseSeeded function;
|
||||
|
||||
/**
|
||||
* Salt for both warp function and
|
||||
* input function.
|
||||
*/
|
||||
@Value("salt")
|
||||
@Default
|
||||
private int salt = 0;
|
||||
|
||||
/**
|
||||
* Amplitude of warping. Values provided by
|
||||
* the warp function are multiplied by this constant.
|
||||
*/
|
||||
@Value("amplitude")
|
||||
@Default
|
||||
private double amplitude = 1;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public DomainWarpedSampler apply(Long seed) {
|
||||
return new DomainWarpedSampler(function.apply(seed), warp.apply(seed), (int) (seed + salt), amplitude);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,12 +1,13 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler.templates;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.samplers.ImageSampler;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@AutoDocAlias("ImageSampler")
|
||||
public class ImageSamplerTemplate extends SamplerTemplate<ImageSampler> {
|
||||
|
||||
@Value("image")
|
||||
@@ -19,7 +20,7 @@ public class ImageSamplerTemplate extends SamplerTemplate<ImageSampler> {
|
||||
private ImageSampler.Channel channel;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public ImageSampler apply(Long seed) {
|
||||
return new ImageSampler(image, channel, frequency);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -4,13 +4,14 @@ 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.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.samplers.KernelSampler;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@AutoDocAlias("KernelSampler")
|
||||
public class KernelTemplate extends SamplerTemplate<KernelSampler> implements ValidatedConfigTemplate {
|
||||
|
||||
@Value("kernel")
|
||||
@@ -28,7 +29,7 @@ public class KernelTemplate extends SamplerTemplate<KernelSampler> implements Va
|
||||
private double frequency = 1;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public KernelSampler apply(Long seed) {
|
||||
double[][] k = new double[kernel.size()][kernel.get(0).size()];
|
||||
|
||||
for(int x = 0; x < kernel.size(); x++) {
|
||||
|
||||
+8
@@ -5,11 +5,16 @@ 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.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
@AutoDocAlias("NoiseSeeded")
|
||||
public abstract class SamplerTemplate<T extends NoiseSampler> implements ValidatedConfigTemplate, ObjectTemplate<NoiseSeeded>, NoiseSeeded {
|
||||
/**
|
||||
* Number of dimensions for this sampler.
|
||||
*/
|
||||
@Value("dimensions")
|
||||
@Default
|
||||
private int dimensions = 2;
|
||||
@@ -28,4 +33,7 @@ public abstract class SamplerTemplate<T extends NoiseSampler> implements Validat
|
||||
public NoiseSeeded get() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract T apply(Long seed);
|
||||
}
|
||||
|
||||
+3
-1
@@ -2,12 +2,14 @@ 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.docs.AutoDocAlias;
|
||||
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;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
@AutoDocAlias("CellularSampler")
|
||||
public class CellularNoiseTemplate extends NoiseTemplate<CellularSampler> {
|
||||
@Value("distance")
|
||||
@Default
|
||||
@@ -38,7 +40,7 @@ public class CellularNoiseTemplate extends NoiseTemplate<CellularSampler> {
|
||||
};
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public CellularSampler apply(Long seed) {
|
||||
CellularSampler sampler = new CellularSampler((int) (long) seed + salt);
|
||||
sampler.setNoiseLookup(lookup.apply(seed));
|
||||
sampler.setFrequency(frequency);
|
||||
|
||||
+3
-2
@@ -2,18 +2,19 @@ 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.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
@AutoDocAlias("ConstantSampler")
|
||||
public class ConstantNoiseTemplate extends SamplerTemplate<ConstantSampler> {
|
||||
@Value("value")
|
||||
@Default
|
||||
private double value = 0d;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public ConstantSampler apply(Long seed) {
|
||||
return new ConstantSampler(value);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -8,9 +8,8 @@ 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.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
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;
|
||||
@@ -24,6 +23,7 @@ import java.util.Map;
|
||||
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
@AutoDocAlias("ExpressionFunction")
|
||||
public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFunction> implements ValidatedConfigTemplate {
|
||||
@Value("variables")
|
||||
@Default
|
||||
@@ -41,7 +41,7 @@ public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFuncti
|
||||
private LinkedHashMap<String, FunctionTemplate> expressions = new LinkedHashMap<>();
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public ExpressionFunction apply(Long seed) {
|
||||
try {
|
||||
Map<String, Function> noiseFunctionMap = generateFunctions(seed);
|
||||
return new ExpressionFunction(noiseFunctionMap, equation, vars);
|
||||
|
||||
+15
-2
@@ -2,18 +2,31 @@ 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.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.GaborNoiseSampler;
|
||||
|
||||
/**
|
||||
* Defines a Gabor noise function.
|
||||
*/
|
||||
@AutoDocAlias("GaborNoiseSampler")
|
||||
public class GaborNoiseTemplate extends NoiseTemplate<GaborNoiseSampler> {
|
||||
/**
|
||||
* Rotation to apply to noise. Only has noticeable effects in anisotropic mode.
|
||||
*/
|
||||
@Value("rotation")
|
||||
@Default
|
||||
private double rotation = 0.25;
|
||||
|
||||
/**
|
||||
* Whether to use anisotropic or isotropic algorithm.
|
||||
*/
|
||||
@Value("isotropic")
|
||||
@Default
|
||||
private boolean isotropic = true;
|
||||
|
||||
/**
|
||||
* Standard deviation of result values.
|
||||
*/
|
||||
@Value("deviation")
|
||||
@Default
|
||||
private double deviation = 1.0;
|
||||
@@ -27,7 +40,7 @@ public class GaborNoiseTemplate extends NoiseTemplate<GaborNoiseSampler> {
|
||||
private double f0 = 0.625;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public GaborNoiseSampler apply(Long seed) {
|
||||
GaborNoiseSampler gaborNoiseSampler = new GaborNoiseSampler((int) (long) seed + salt);
|
||||
gaborNoiseSampler.setFrequency(frequency);
|
||||
gaborNoiseSampler.setRotation(rotation);
|
||||
|
||||
+2
@@ -2,10 +2,12 @@ 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.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.NoiseFunction;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@AutoDocAlias("NoiseFunction")
|
||||
public abstract class NoiseTemplate<T extends NoiseFunction> extends SamplerTemplate<T> {
|
||||
@Value("frequency")
|
||||
@Default
|
||||
|
||||
+3
-2
@@ -1,10 +1,11 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler.templates.noise;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocShadow;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.NoiseFunction;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@AutoDocShadow("NoiseFunction")
|
||||
public class SimpleNoiseTemplate extends NoiseTemplate<NoiseFunction> {
|
||||
private final Function<Integer, NoiseFunction> samplerSupplier;
|
||||
|
||||
@@ -13,7 +14,7 @@ public class SimpleNoiseTemplate extends NoiseTemplate<NoiseFunction> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public NoiseFunction apply(Long seed) {
|
||||
NoiseFunction sampler = samplerSupplier.apply((int) (long) seed + salt);
|
||||
sampler.setFrequency(frequency);
|
||||
return sampler;
|
||||
|
||||
+3
-2
@@ -1,11 +1,12 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler.templates.noise.fractal;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.fractal.BrownianMotionSampler;
|
||||
|
||||
@AutoDocAlias("BrownianMotionSampler")
|
||||
public class BrownianMotionTemplate extends FractalTemplate<BrownianMotionSampler> {
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public BrownianMotionSampler apply(Long seed) {
|
||||
BrownianMotionSampler sampler = new BrownianMotionSampler((int) (long) seed, function.apply(seed));
|
||||
sampler.setGain(fractalGain);
|
||||
sampler.setLacunarity(fractalLacunarity);
|
||||
|
||||
+2
@@ -2,10 +2,12 @@ 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.docs.AutoDocAlias;
|
||||
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;
|
||||
|
||||
@AutoDocAlias("FractalNoiseFunction")
|
||||
public abstract class FractalTemplate<T extends FractalNoiseFunction> extends SamplerTemplate<T> {
|
||||
@Value("octaves")
|
||||
@Default
|
||||
|
||||
+3
-2
@@ -2,16 +2,17 @@ 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.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.fractal.PingPongSampler;
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@AutoDocAlias("PingPongSampler")
|
||||
public class PingPongTemplate extends FractalTemplate<PingPongSampler> {
|
||||
@Value("ping-pong")
|
||||
@Default
|
||||
private double pingPong = 2.0D;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public PingPongSampler apply(Long seed) {
|
||||
PingPongSampler sampler = new PingPongSampler((int) (long) seed, function.apply(seed));
|
||||
sampler.setGain(fractalGain);
|
||||
sampler.setLacunarity(fractalLacunarity);
|
||||
|
||||
+3
-2
@@ -1,11 +1,12 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler.templates.noise.fractal;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.fractal.RidgedFractalSampler;
|
||||
|
||||
@AutoDocAlias("RidgedFractalSampler")
|
||||
public class RidgedFractalTemplate extends FractalTemplate<RidgedFractalSampler> {
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public RidgedFractalSampler apply(Long seed) {
|
||||
RidgedFractalSampler sampler = new RidgedFractalSampler((int) (long) seed, function.apply(seed));
|
||||
sampler.setGain(fractalGain);
|
||||
sampler.setLacunarity(fractalLacunarity);
|
||||
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler.templates.normalizer;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.normalizer.ClampNormalizer;
|
||||
import com.dfsek.terra.api.math.noise.normalizer.LinearNormalizer;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class ClampNormalizerTemplate extends NormalizerTemplate<LinearNormalizer> {
|
||||
@AutoDocAlias("ClampNormalizer")
|
||||
public class ClampNormalizerTemplate extends NormalizerTemplate<ClampNormalizer> {
|
||||
@Value("max")
|
||||
private double max;
|
||||
|
||||
@@ -14,7 +14,7 @@ public class ClampNormalizerTemplate extends NormalizerTemplate<LinearNormalizer
|
||||
private double min;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public ClampNormalizer apply(Long seed) {
|
||||
return new ClampNormalizer(function.apply(seed), min, max);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,10 +1,11 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler.templates.normalizer;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.normalizer.LinearNormalizer;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@AutoDocAlias("LinearNormalizer")
|
||||
public class LinearNormalizerTemplate extends NormalizerTemplate<LinearNormalizer> {
|
||||
@Value("max")
|
||||
private double max;
|
||||
@@ -13,7 +14,7 @@ public class LinearNormalizerTemplate extends NormalizerTemplate<LinearNormalize
|
||||
private double min;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public LinearNormalizer apply(Long seed) {
|
||||
return new LinearNormalizer(function.apply(seed), min, max);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -2,10 +2,11 @@ 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.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.normalizer.NormalNormalizer;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@AutoDocAlias("NormalNormalizer")
|
||||
public class NormalNormalizerTemplate extends NormalizerTemplate<NormalNormalizer> {
|
||||
@Value("mean")
|
||||
private double mean;
|
||||
@@ -18,7 +19,7 @@ public class NormalNormalizerTemplate extends NormalizerTemplate<NormalNormalize
|
||||
private int groups = 16384;
|
||||
|
||||
@Override
|
||||
public NoiseSampler apply(Long seed) {
|
||||
public NormalNormalizer apply(Long seed) {
|
||||
return new NormalNormalizer(function.apply(seed), groups, mean, stdDev);
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -1,10 +1,12 @@
|
||||
package com.dfsek.terra.config.loaders.config.sampler.templates.normalizer;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
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;
|
||||
|
||||
@AutoDocAlias("Normalizer")
|
||||
public abstract class NormalizerTemplate<T extends Normalizer> extends SamplerTemplate<T> {
|
||||
@Value("function")
|
||||
protected NoiseSeeded function;
|
||||
|
||||
+3
-1
@@ -3,9 +3,11 @@ package com.dfsek.terra.config.loaders.palette;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
import com.dfsek.terra.api.world.palette.holder.PaletteHolder;
|
||||
import com.dfsek.terra.api.world.palette.holder.PaletteHolderBuilder;
|
||||
import com.dfsek.terra.config.loaders.Types;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
@@ -19,7 +21,7 @@ public class PaletteHolderLoader implements TypeLoader<PaletteHolder> {
|
||||
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()));
|
||||
builder.add(entry.getValue(), (Palette<BlockData>) configLoader.loadType(Types.BLOCK_DATA_PALETTE_TYPE, entry.getKey()));
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
|
||||
@@ -2,27 +2,36 @@ package com.dfsek.terra.config.pack;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.tectonic.abstraction.AbstractConfigLoader;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
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.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.event.events.config.ConfigPackPostLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structures.loot.LootTable;
|
||||
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.api.structures.script.StructureScript;
|
||||
import com.dfsek.terra.api.util.generic.pair.ImmutablePair;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseProvider;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.flora.Flora;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.dummy.DummyWorld;
|
||||
import com.dfsek.terra.config.factories.BiomeFactory;
|
||||
import com.dfsek.terra.config.factories.CarverFactory;
|
||||
import com.dfsek.terra.config.factories.ConfigFactory;
|
||||
import com.dfsek.terra.config.factories.FloraFactory;
|
||||
import com.dfsek.terra.config.factories.OreFactory;
|
||||
import com.dfsek.terra.config.factories.PaletteFactory;
|
||||
import com.dfsek.terra.config.factories.StructureFactory;
|
||||
import com.dfsek.terra.config.factories.TreeFactory;
|
||||
import com.dfsek.terra.config.fileloaders.FolderLoader;
|
||||
import com.dfsek.terra.config.fileloaders.Loader;
|
||||
import com.dfsek.terra.config.fileloaders.ZIPLoader;
|
||||
@@ -32,16 +41,29 @@ 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.prototype.ConfigType;
|
||||
import com.dfsek.terra.config.prototype.ProtoConfig;
|
||||
import com.dfsek.terra.config.templates.AbstractableTemplate;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.config.templates.CarverTemplate;
|
||||
import com.dfsek.terra.config.templates.FloraTemplate;
|
||||
import com.dfsek.terra.config.templates.OreTemplate;
|
||||
import com.dfsek.terra.config.templates.PaletteTemplate;
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.config.templates.TreeTemplate;
|
||||
import com.dfsek.terra.registry.OpenRegistry;
|
||||
import com.dfsek.terra.registry.config.ConfigTypeRegistry;
|
||||
import com.dfsek.terra.registry.config.BiomeRegistry;
|
||||
import com.dfsek.terra.registry.config.CarverRegistry;
|
||||
import com.dfsek.terra.registry.config.FloraRegistry;
|
||||
import com.dfsek.terra.registry.config.FunctionRegistry;
|
||||
import com.dfsek.terra.registry.config.LootRegistry;
|
||||
import com.dfsek.terra.registry.config.NoiseRegistry;
|
||||
import com.dfsek.terra.registry.config.OreRegistry;
|
||||
import com.dfsek.terra.registry.config.PaletteRegistry;
|
||||
import com.dfsek.terra.registry.config.ScriptRegistry;
|
||||
import com.dfsek.terra.registry.config.StructureRegistry;
|
||||
import com.dfsek.terra.registry.config.TreeRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.dfsek.terra.world.population.items.TerraStructure;
|
||||
import com.dfsek.terra.world.population.items.ores.Ore;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
@@ -52,14 +74,12 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
@@ -69,27 +89,38 @@ import java.util.zip.ZipFile;
|
||||
public class ConfigPack implements LoaderRegistrar {
|
||||
private final ConfigPackTemplate template = new ConfigPackTemplate();
|
||||
|
||||
private final BiomeRegistry biomeRegistry = new BiomeRegistry();
|
||||
private final StructureRegistry structureRegistry = new StructureRegistry();
|
||||
private final PaletteRegistry paletteRegistry;
|
||||
private final FloraRegistry floraRegistry;
|
||||
private final OreRegistry oreRegistry = new OreRegistry();
|
||||
private final TreeRegistry treeRegistry;
|
||||
private final ScriptRegistry scriptRegistry = new ScriptRegistry();
|
||||
private final LootRegistry lootRegistry = new LootRegistry();
|
||||
|
||||
private final CarverRegistry carverRegistry = new CarverRegistry();
|
||||
|
||||
private final NoiseRegistry noiseRegistry = new NoiseRegistry();
|
||||
private final FunctionRegistry functionRegistry = new FunctionRegistry();
|
||||
|
||||
private final AbstractConfigLoader abstractConfigLoader = new AbstractConfigLoader();
|
||||
private final ConfigLoader selfLoader = new ConfigLoader();
|
||||
private final Scope varScope = new Scope();
|
||||
|
||||
private final TerraPlugin main;
|
||||
private final Loader loader;
|
||||
|
||||
private final BiomeProvider.BiomeProviderBuilder biomeProviderBuilder;
|
||||
|
||||
|
||||
private final ConfigTypeRegistry configTypeRegistry;
|
||||
private final Map<Class<?>, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> registryMap = newRegistryMap();
|
||||
|
||||
public ConfigPack(File folder, TerraPlugin main) throws ConfigException {
|
||||
try {
|
||||
this.configTypeRegistry = new ConfigTypeRegistry(this, main, (id, configType) -> {
|
||||
OpenRegistry<?> openRegistry = configType.registrySupplier().get();
|
||||
registryMap.put(configType.getTypeClass(), ImmutablePair.of(openRegistry, new CheckedRegistry<>(openRegistry)));
|
||||
});
|
||||
this.loader = new FolderLoader(folder.toPath());
|
||||
this.main = main;
|
||||
long l = System.nanoTime();
|
||||
|
||||
floraRegistry = new FloraRegistry(main);
|
||||
paletteRegistry = new PaletteRegistry(main);
|
||||
treeRegistry = new TreeRegistry();
|
||||
register(abstractConfigLoader);
|
||||
register(selfLoader);
|
||||
|
||||
@@ -121,16 +152,17 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
public ConfigPack(ZipFile file, TerraPlugin main) throws ConfigException {
|
||||
try {
|
||||
this.configTypeRegistry = new ConfigTypeRegistry(this, main, (id, configType) -> {
|
||||
OpenRegistry<?> openRegistry = configType.registrySupplier().get();
|
||||
registryMap.put(configType.getTypeClass(), ImmutablePair.of(openRegistry, new CheckedRegistry<>(openRegistry)));
|
||||
});
|
||||
this.loader = new ZIPLoader(file);
|
||||
this.main = main;
|
||||
long l = System.nanoTime();
|
||||
|
||||
floraRegistry = new FloraRegistry(main);
|
||||
paletteRegistry = new PaletteRegistry(main);
|
||||
treeRegistry = new TreeRegistry();
|
||||
register(abstractConfigLoader);
|
||||
register(selfLoader);
|
||||
|
||||
main.register(selfLoader);
|
||||
main.register(abstractConfigLoader);
|
||||
|
||||
try {
|
||||
ZipEntry pack = null;
|
||||
@@ -164,36 +196,20 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
toWorldConfig(new TerraWorld(new DummyWorld(), this, main)); // Build now to catch any errors immediately.
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private Map<Class<?>, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> newRegistryMap() {
|
||||
Map<Class<?>, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> map = new HashMap<Class<?>, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>>() {
|
||||
private static final long serialVersionUID = 4015855819914064466L;
|
||||
|
||||
@Override
|
||||
public ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>> put(Class<?> key, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>> value) {
|
||||
selfLoader.registerLoader(key, value.getLeft());
|
||||
abstractConfigLoader.registerLoader(key, value.getLeft());
|
||||
return super.put(key, value);
|
||||
}
|
||||
};
|
||||
|
||||
putPair(map, NoiseProvider.class, new NoiseRegistry());
|
||||
putPair(map, FunctionBuilder.class, (OpenRegistry<FunctionBuilder>) (Object) new FunctionRegistry());
|
||||
putPair(map, LootTable.class, new LootRegistry());
|
||||
putPair(map, StructureScript.class, new ScriptRegistry());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private <R> void putPair(Map<Class<?>, ImmutablePair<OpenRegistry<?>, CheckedRegistry<?>>> map, Class<R> key, OpenRegistry<R> l) {
|
||||
map.put(key, ImmutablePair.of(l, new CheckedRegistry<>(l)));
|
||||
public static <C extends AbstractableTemplate, O> void buildAll(ConfigFactory<C, O> factory, OpenRegistry<O> registry, List<C> configTemplates, TerraPlugin main) throws LoadException {
|
||||
for(C template : configTemplates) registry.add(template.getID(), factory.build(template, main));
|
||||
}
|
||||
|
||||
private void checkDeadEntries(TerraPlugin main) {
|
||||
registryMap.forEach((clazz, pair) -> pair.getLeft().getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in '" + clazz + "' registry: '" + id + "'")));
|
||||
biomeRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in biome registry: '" + id + "'"));
|
||||
paletteRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in palette registry: '" + id + "'"));
|
||||
floraRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in flora registry: '" + id + "'"));
|
||||
carverRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in carver registry: '" + id + "'"));
|
||||
treeRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in tree registry: '" + id + "'"));
|
||||
oreRegistry.getDeadEntries().forEach((id, value) -> main.getDebugLogger().warn("Dead entry in ore registry: '" + id + "'"));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
|
||||
private void load(long start, TerraPlugin main) throws ConfigException {
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this));
|
||||
|
||||
@@ -204,8 +220,8 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
loader.open("structures/data", ".tesf").thenEntries(entries -> {
|
||||
for(Map.Entry<String, InputStream> entry : entries) {
|
||||
try(InputStream stream = entry.getValue()) {
|
||||
StructureScript structureScript = new StructureScript(stream, main, getRegistry(StructureScript.class), getRegistry(LootTable.class), (Registry<FunctionBuilder<?>>) (Object) getRegistry(FunctionBuilder.class));
|
||||
getOpenRegistry(StructureScript.class).add(structureScript.getId(), structureScript);
|
||||
StructureScript structureScript = new StructureScript(stream, main, scriptRegistry, lootRegistry, functionRegistry);
|
||||
scriptRegistry.add(structureScript.getId(), structureScript);
|
||||
} catch(com.dfsek.terra.api.structures.parser.exceptions.ParseException | IOException e) {
|
||||
throw new LoadException("Unable to load script \"" + entry.getKey() + "\"", e);
|
||||
}
|
||||
@@ -213,38 +229,36 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
}).close().open("structures/loot", ".json").thenEntries(entries -> {
|
||||
for(Map.Entry<String, InputStream> entry : entries) {
|
||||
try {
|
||||
getOpenRegistry(LootTable.class).add(entry.getKey(), new LootTable(IOUtils.toString(entry.getValue(), StandardCharsets.UTF_8), main));
|
||||
lootRegistry.add(entry.getKey(), new LootTable(IOUtils.toString(entry.getValue(), StandardCharsets.UTF_8), main));
|
||||
} catch(ParseException | IOException | NullPointerException e) {
|
||||
throw new LoadException("Unable to load loot table \"" + entry.getKey() + "\"", e);
|
||||
}
|
||||
}
|
||||
}).close();
|
||||
|
||||
List<Configuration> configurations = new ArrayList<>();
|
||||
|
||||
loader.open("", ".yml").thenEntries(entries -> entries.forEach(stream -> configurations.add(new Configuration(stream.getValue(), stream.getKey()))));
|
||||
|
||||
Map<ConfigType<? extends ConfigTemplate, ?>, List<Configuration>> configs = new HashMap<>();
|
||||
|
||||
for(Configuration configuration : configurations) {
|
||||
ProtoConfig config = new ProtoConfig();
|
||||
selfLoader.load(config, configuration);
|
||||
configs.computeIfAbsent(config.getType(), configType -> new ArrayList<>()).add(configuration);
|
||||
}
|
||||
|
||||
for(ConfigType<?, ?> configType : configTypeRegistry.entries()) {
|
||||
for(ConfigTemplate config : abstractConfigLoader.loadConfigs(configs.getOrDefault(configType, Collections.emptyList()), () -> configType.getTemplate(this, main))) {
|
||||
((ConfigType) configType).callback(this, main, config);
|
||||
}
|
||||
}
|
||||
loader
|
||||
.open("carving", ".yml").then(streams -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new), main)).close()
|
||||
.open("palettes", ".yml").then(streams -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.load(streams, PaletteTemplate::new), main)).close()
|
||||
.open("ores", ".yml").then(streams -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.load(streams, OreTemplate::new), main)).close()
|
||||
.open("structures/trees", ".yml").then(streams -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.load(streams, TreeTemplate::new), main)).close()
|
||||
.open("structures/structures", ".yml").then(streams -> buildAll(new StructureFactory(), structureRegistry, abstractConfigLoader.load(streams, StructureTemplate::new), main)).close()
|
||||
.open("flora", ".yml").then(streams -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.load(streams, FloraTemplate::new), main)).close()
|
||||
.open("biomes", ".yml").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this, main)), main)).close();
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this));
|
||||
main.logger().info("Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " + (System.nanoTime() - start) / 1000000D + "ms.");
|
||||
}
|
||||
|
||||
public TerraStructure getStructure(String id) {
|
||||
return structureRegistry.get(id);
|
||||
}
|
||||
|
||||
public Set<TerraStructure> getStructures() {
|
||||
return new HashSet<>(getRegistry(TerraStructure.class).entries());
|
||||
return structureRegistry.entries();
|
||||
}
|
||||
|
||||
public List<String> getStructureIDs() {
|
||||
return structureRegistry.entries().stream().map(terraStructure -> terraStructure.getTemplate().getID()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ConfigPackTemplate getTemplate() {
|
||||
@@ -255,45 +269,80 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
return varScope;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> CheckedRegistry<T> getRegistry(Class<T> clazz) {
|
||||
return (CheckedRegistry<T>) registryMap.getOrDefault(clazz, ImmutablePair.ofNull()).getRight();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T> OpenRegistry<T> getOpenRegistry(Class<T> clazz) {
|
||||
return (OpenRegistry<T>) registryMap.getOrDefault(clazz, ImmutablePair.ofNull()).getLeft();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
registry
|
||||
.registerLoader(ConfigType.class, configTypeRegistry)
|
||||
.registerLoader(Palette.class, paletteRegistry)
|
||||
.registerLoader(BiomeBuilder.class, biomeRegistry)
|
||||
.registerLoader(Flora.class, floraRegistry)
|
||||
.registerLoader(Ore.class, oreRegistry)
|
||||
.registerLoader(Tree.class, treeRegistry)
|
||||
.registerLoader(StructureScript.class, scriptRegistry)
|
||||
.registerLoader(TerraStructure.class, structureRegistry)
|
||||
.registerLoader(LootTable.class, lootRegistry)
|
||||
.registerLoader(UserDefinedCarver.class, carverRegistry)
|
||||
.registerLoader(BufferedImage.class, new BufferedImageLoader(loader))
|
||||
.registerLoader(NoiseSeeded.class, new NoiseSamplerBuilderLoader(noiseRegistry))
|
||||
.registerLoader(SingleBiomeProviderTemplate.class, SingleBiomeProviderTemplate::new)
|
||||
.registerLoader(BiomePipelineTemplate.class, () -> new BiomePipelineTemplate(main))
|
||||
.registerLoader(ImageProviderTemplate.class, () -> new ImageProviderTemplate(getRegistry(BiomeBuilder.class)))
|
||||
.registerLoader(ImageSamplerTemplate.class, () -> new ImageProviderTemplate(getRegistry(BiomeBuilder.class)))
|
||||
.registerLoader(NoiseSeeded.class, new NoiseSamplerBuilderLoader(getOpenRegistry(NoiseProvider.class)));
|
||||
.registerLoader(ImageProviderTemplate.class, () -> new ImageProviderTemplate(biomeRegistry))
|
||||
.registerLoader(ImageSamplerTemplate.class, () -> new ImageProviderTemplate(biomeRegistry));
|
||||
}
|
||||
|
||||
public Set<UserDefinedCarver> getCarvers() {
|
||||
return carverRegistry.entries();
|
||||
}
|
||||
|
||||
public BiomeProvider.BiomeProviderBuilder getBiomeProviderBuilder() {
|
||||
return biomeProviderBuilder;
|
||||
}
|
||||
|
||||
public CheckedRegistry<StructureScript> getScriptRegistry() {
|
||||
return new CheckedRegistry<>(scriptRegistry);
|
||||
}
|
||||
|
||||
public WorldConfig toWorldConfig(TerraWorld world) {
|
||||
public CheckedRegistry<BiomeBuilder> getBiomeRegistry() {
|
||||
return new CheckedRegistry<>(biomeRegistry);
|
||||
}
|
||||
|
||||
public CheckedRegistry<Tree> getTreeRegistry() {
|
||||
return new CheckedRegistry<>(treeRegistry);
|
||||
}
|
||||
|
||||
public CheckedRegistry<FunctionBuilder<?>> getFunctionRegistry() {
|
||||
return new CheckedRegistry<>(functionRegistry);
|
||||
}
|
||||
|
||||
public CheckedRegistry<Supplier<ObjectTemplate<NoiseSeeded>>> getNormalizerRegistry() {
|
||||
return new CheckedRegistry<>(noiseRegistry);
|
||||
}
|
||||
|
||||
public CheckedRegistry<UserDefinedCarver> getCarverRegistry() {
|
||||
return new CheckedRegistry<>(carverRegistry);
|
||||
}
|
||||
|
||||
public CheckedRegistry<Flora> getFloraRegistry() {
|
||||
return new CheckedRegistry<>(floraRegistry);
|
||||
}
|
||||
|
||||
public CheckedRegistry<LootTable> getLootRegistry() {
|
||||
return new CheckedRegistry<>(lootRegistry);
|
||||
}
|
||||
|
||||
public CheckedRegistry<Ore> getOreRegistry() {
|
||||
return new CheckedRegistry<>(oreRegistry);
|
||||
}
|
||||
|
||||
public CheckedRegistry<Palette<BlockData>> getPaletteRegistry() {
|
||||
return new CheckedRegistry<>(paletteRegistry);
|
||||
}
|
||||
|
||||
public CheckedRegistry<TerraStructure> getStructureRegistry() {
|
||||
return new CheckedRegistry<>(structureRegistry);
|
||||
}
|
||||
|
||||
public WorldConfig toWorldConfig(TerraWorld world){
|
||||
return new WorldConfig(world, this, main);
|
||||
}
|
||||
|
||||
public CheckedRegistry<ConfigType<?, ?>> getConfigTypeRegistry() {
|
||||
return new CheckedRegistry<ConfigType<?, ?>>(configTypeRegistry) {
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void addUnchecked(String identifier, ConfigType<?, ?> value) {
|
||||
if(contains(identifier)) throw new UnsupportedOperationException("Cannot override values in ConfigTypeRegistry!");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,24 +15,52 @@ import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class ConfigPackTemplate implements ConfigTemplate {
|
||||
|
||||
/**
|
||||
* The ID of the config pack.
|
||||
*/
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* Noise functions to be made available
|
||||
* to noise equations in the config pack.
|
||||
* <p>
|
||||
* Keys are Paralithic function IDs,
|
||||
* values are noise functions.
|
||||
*/
|
||||
@Value("noise")
|
||||
private Map<String, NoiseSeeded> noiseBuilderMap;
|
||||
|
||||
/**
|
||||
* Addons this pack depends on.
|
||||
*/
|
||||
@Value("addons")
|
||||
@Default
|
||||
private Set<TerraAddon> addons = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Variables to be made available
|
||||
* to noise equations in the config pack.
|
||||
* <p>
|
||||
* Keys are variable IDs,
|
||||
* values are variable values.
|
||||
*/
|
||||
@Value("variables")
|
||||
@Default
|
||||
private Map<String, Double> variables = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Whether to enable beta noise
|
||||
* carvers.
|
||||
*/
|
||||
@Value("beta.carving")
|
||||
@Default
|
||||
private boolean betaCarvers = false;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Value("functions")
|
||||
@Default
|
||||
private LinkedHashMap<String, FunctionTemplate> functions = new LinkedHashMap<>();
|
||||
|
||||
@@ -1,51 +1,62 @@
|
||||
package com.dfsek.terra.config.pack;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.structures.loot.LootTable;
|
||||
import com.dfsek.terra.api.structures.script.StructureScript;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.flora.Flora;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.registry.OpenRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.dfsek.terra.world.generation.math.SamplerCache;
|
||||
import com.dfsek.terra.world.population.items.TerraStructure;
|
||||
import com.dfsek.terra.world.population.items.ores.Ore;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class WorldConfig {
|
||||
private final LockedRegistry<StructureScript> scriptRegistry;
|
||||
private final LockedRegistry<TerraBiome> biomeRegistry;
|
||||
private final SamplerCache samplerCache;
|
||||
private final LockedRegistry<UserDefinedCarver> carverRegistry;
|
||||
private final LockedRegistry<Tree> treeRegistry;
|
||||
private final LockedRegistry<Flora> floraRegistry;
|
||||
private final LockedRegistry<LootTable> lootRegistry;
|
||||
private final LockedRegistry<Ore> oreRegistry;
|
||||
private final LockedRegistry<Palette<BlockData>> paletteRegistry;
|
||||
private final LockedRegistry<TerraStructure> structureRegistry;
|
||||
|
||||
private final BiomeProvider provider;
|
||||
|
||||
private final TerraWorld world;
|
||||
private final ConfigPack pack;
|
||||
|
||||
private final Map<Class<?>, LockedRegistry<?>> registryMap = new HashMap<>();
|
||||
|
||||
public WorldConfig(TerraWorld world, ConfigPack pack, TerraPlugin main) {
|
||||
this.world = world;
|
||||
this.pack = pack;
|
||||
this.samplerCache = new SamplerCache(main, world);
|
||||
|
||||
pack.getConfigTypeRegistry().forEach(configType -> registryMap.put(configType.getTypeClass(), new LockedRegistry<>(pack.getRegistry(configType.getTypeClass()))));
|
||||
|
||||
this.scriptRegistry = new LockedRegistry<>(pack.getScriptRegistry());
|
||||
|
||||
OpenRegistry<TerraBiome> biomeOpenRegistry = new OpenRegistry<>();
|
||||
pack.getRegistry(BiomeBuilder.class).forEach((id, biome) -> biomeOpenRegistry.add(id, biome.apply(world.getWorld().getSeed())));
|
||||
registryMap.put(TerraBiome.class, new LockedRegistry<>(biomeOpenRegistry));
|
||||
pack.getBiomeRegistry().forEach((id, biome) -> biomeOpenRegistry.add(id, biome.apply(world.getWorld().getSeed())));
|
||||
|
||||
this.biomeRegistry = new LockedRegistry<>(biomeOpenRegistry);
|
||||
this.carverRegistry = new LockedRegistry<>(pack.getCarverRegistry());
|
||||
this.treeRegistry = new LockedRegistry<>(pack.getTreeRegistry());
|
||||
this.floraRegistry = new LockedRegistry<>(pack.getFloraRegistry());
|
||||
this.lootRegistry = new LockedRegistry<>(pack.getLootRegistry());
|
||||
this.oreRegistry = new LockedRegistry<>(pack.getOreRegistry());
|
||||
this.paletteRegistry = new LockedRegistry<>(pack.getPaletteRegistry());
|
||||
this.structureRegistry = new LockedRegistry<>(pack.getStructureRegistry());
|
||||
|
||||
this.provider = pack.getBiomeProviderBuilder().build(world.getWorld().getSeed());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> LockedRegistry<T> getRegistry(Class<T> clazz) {
|
||||
return (LockedRegistry<T>) registryMap.get(clazz);
|
||||
}
|
||||
|
||||
public TerraWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
@@ -55,7 +66,43 @@ public class WorldConfig {
|
||||
}
|
||||
|
||||
public Set<UserDefinedCarver> getCarvers() {
|
||||
return new HashSet<>(getRegistry(UserDefinedCarver.class).entries());
|
||||
return carverRegistry.entries();
|
||||
}
|
||||
|
||||
public LockedRegistry<StructureScript> getScriptRegistry() {
|
||||
return scriptRegistry;
|
||||
}
|
||||
|
||||
public LockedRegistry<TerraBiome> getBiomeRegistry() {
|
||||
return biomeRegistry;
|
||||
}
|
||||
|
||||
public LockedRegistry<Tree> getTreeRegistry() {
|
||||
return treeRegistry;
|
||||
}
|
||||
|
||||
public LockedRegistry<UserDefinedCarver> getCarverRegistry() {
|
||||
return carverRegistry;
|
||||
}
|
||||
|
||||
public LockedRegistry<Flora> getFloraRegistry() {
|
||||
return floraRegistry;
|
||||
}
|
||||
|
||||
public LockedRegistry<LootTable> getLootRegistry() {
|
||||
return lootRegistry;
|
||||
}
|
||||
|
||||
public LockedRegistry<Ore> getOreRegistry() {
|
||||
return oreRegistry;
|
||||
}
|
||||
|
||||
public LockedRegistry<Palette<BlockData>> getPaletteRegistry() {
|
||||
return paletteRegistry;
|
||||
}
|
||||
|
||||
public LockedRegistry<TerraStructure> getStructureRegistry() {
|
||||
return structureRegistry;
|
||||
}
|
||||
|
||||
public BiomeProvider getProvider() {
|
||||
@@ -63,7 +110,7 @@ public class WorldConfig {
|
||||
}
|
||||
|
||||
public Set<TerraStructure> getStructures() {
|
||||
return new HashSet<>(getRegistry(TerraStructure.class).entries());
|
||||
return structureRegistry.entries();
|
||||
}
|
||||
|
||||
public ConfigPackTemplate getTemplate() {
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.dfsek.terra.config.prototype;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.registry.OpenRegistry;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface ConfigType<T extends ConfigTemplate, R> {
|
||||
T getTemplate(ConfigPack pack, TerraPlugin main);
|
||||
|
||||
void callback(ConfigPack pack, TerraPlugin main, T loadedConfig) throws LoadException;
|
||||
|
||||
Class<R> getTypeClass();
|
||||
|
||||
Supplier<OpenRegistry<R>> registrySupplier();
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.dfsek.terra.config.prototype;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
|
||||
public class ProtoConfig implements ConfigTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("type")
|
||||
private ConfigType<?, ?> type;
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ConfigType<?, ?> getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,12 @@ import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler;
|
||||
import com.dfsek.terra.api.math.paralithic.BlankFunction;
|
||||
import com.dfsek.terra.api.math.paralithic.defined.UserDefinedFunction;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.platform.world.Biome;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
@@ -37,6 +39,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
@AutoDocAlias("TerraBiome")
|
||||
public class BiomeTemplate extends AbstractableTemplate implements ValidatedConfigTemplate {
|
||||
|
||||
private final ConfigPack pack;
|
||||
@@ -123,7 +126,7 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
|
||||
@Value("ocean.palette")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Palette oceanPalette;
|
||||
private Palette<BlockData> oceanPalette;
|
||||
|
||||
@Value("elevation.equation")
|
||||
@Default
|
||||
@@ -158,12 +161,12 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
|
||||
@Value("slabs.palettes")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<BlockType, Palette> slabPalettes;
|
||||
private Map<BlockType, Palette<BlockData>> slabPalettes;
|
||||
|
||||
@Value("slabs.stair-palettes")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<BlockType, Palette> stairPalettes;
|
||||
private Map<BlockType, Palette<BlockData>> stairPalettes;
|
||||
|
||||
@Value("slant.threshold")
|
||||
@Abstractable
|
||||
@@ -246,6 +249,14 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
|
||||
return doSlabs;
|
||||
}
|
||||
|
||||
public Map<BlockType, Palette<BlockData>> getSlabPalettes() {
|
||||
return slabPalettes;
|
||||
}
|
||||
|
||||
public Map<BlockType, Palette<BlockData>> getStairPalettes() {
|
||||
return stairPalettes;
|
||||
}
|
||||
|
||||
public BiomeTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
this.pack = pack;
|
||||
biomeNoise = new NoiseSeeded() {
|
||||
@@ -259,15 +270,7 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
oceanPalette = new SinglePalette(main.getWorldHandle().createBlockData("minecraft:water"));
|
||||
}
|
||||
|
||||
public Map<BlockType, Palette> getSlabPalettes() {
|
||||
return slabPalettes;
|
||||
}
|
||||
|
||||
public Map<BlockType, Palette> getStairPalettes() {
|
||||
return stairPalettes;
|
||||
oceanPalette = new SinglePalette<>(main.getWorldHandle().createBlockData("minecraft:water"));
|
||||
}
|
||||
|
||||
public NoiseSeeded getBiomeNoise() {
|
||||
@@ -290,7 +293,7 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
public Palette getOceanPalette() {
|
||||
public Palette<BlockData> getOceanPalette() {
|
||||
return oceanPalette;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.config.templates;
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
@@ -12,6 +13,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@AutoDocAlias("UserDefinedCarver")
|
||||
public class CarverTemplate extends AbstractableTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.config.templates;
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.api.world.palette.holder.PaletteLayerHolder;
|
||||
import com.dfsek.terra.world.population.items.flora.TerraFlora;
|
||||
@@ -10,6 +11,7 @@ import com.dfsek.terra.world.population.items.flora.TerraFlora;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
@AutoDocAlias("Flora")
|
||||
public class FloraTemplate extends AbstractableTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
@@ -32,7 +34,7 @@ public class FloraTemplate extends AbstractableTemplate {
|
||||
@Value("irrigable")
|
||||
@Abstractable
|
||||
@Default
|
||||
private MaterialSet irrigable = null;
|
||||
private MaterialSet irrigable = new MaterialSet();
|
||||
|
||||
@Value("rotatable")
|
||||
@Abstractable
|
||||
|
||||
@@ -3,12 +3,14 @@ package com.dfsek.terra.config.templates;
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.world.population.items.ores.Ore;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@AutoDocAlias("Ore")
|
||||
public class OreTemplate extends AbstractableTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
@@ -17,7 +19,7 @@ public class OreTemplate extends AbstractableTemplate {
|
||||
@Abstractable
|
||||
private BlockData material;
|
||||
|
||||
@Value("algorithm")
|
||||
@Value("type")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Ore.Type oreType = Ore.Type.VANILLA;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.config.templates;
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
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.seeded.NoiseSeeded;
|
||||
@@ -11,6 +12,7 @@ import com.dfsek.terra.api.world.palette.holder.PaletteLayerHolder;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
@AutoDocAlias("Palette")
|
||||
public class PaletteTemplate extends AbstractableTemplate {
|
||||
@Value("noise")
|
||||
@Abstractable
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.math.GridSpawn;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.structures.script.StructureScript;
|
||||
@@ -13,6 +14,7 @@ import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@AutoDocAlias("TerraStructure")
|
||||
public class StructureTemplate extends AbstractableTemplate implements ConfigTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.dfsek.terra.config.templates;
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.docs.AutoDocAlias;
|
||||
import com.dfsek.terra.api.structures.script.StructureScript;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@AutoDocAlias("Tree")
|
||||
public class TreeTemplate extends AbstractableTemplate {
|
||||
@Value("scripts")
|
||||
@Abstractable
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
/**
|
||||
* Class to hold a profiler data value. Contains formatting method to highlight value based on desired range.
|
||||
*/
|
||||
public class DataHolder {
|
||||
private final long desired;
|
||||
private final DataType type;
|
||||
private final double desiredRangePercent;
|
||||
|
||||
/**
|
||||
* Constructs a DataHolder with a DataType and a desired value, including a percentage around the desired value considered acceptable
|
||||
*
|
||||
* @param type The type of data held in this instance.
|
||||
* @param desired The desired value. This should be the average value of whatever is being measured.
|
||||
* @param desiredRangePercent The percentage around the desired value to be considered acceptable.
|
||||
*/
|
||||
public DataHolder(DataType type, long desired, double desiredRangePercent) {
|
||||
this.desired = desired;
|
||||
this.type = type;
|
||||
this.desiredRangePercent = desiredRangePercent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String, formatted with Bungee ChatColors.<br>
|
||||
* GREEN if the value is better than desired and outside of acceptable range.<br>
|
||||
* YELLOW if the value is better or worse than desired, and within acceptable range.<br>
|
||||
* RED if the value is worse than desired and outside of acceptable range.<br>
|
||||
*
|
||||
* @param data The data to format.
|
||||
* @return String - The formatted data.
|
||||
*/
|
||||
public String getFormattedData(long data) {
|
||||
return type.getFormatted(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
public enum DataType {
|
||||
PERIOD_MILLISECONDS(Desire.LOW, 1000000, "ms"), PERIOD_NANOSECONDS(Desire.LOW, 1, "ns");
|
||||
private final Desire desire;
|
||||
private final long divisor;
|
||||
private final String unit;
|
||||
|
||||
DataType(Desire d, long divisor, String unit) {
|
||||
this.desire = d;
|
||||
this.divisor = divisor;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public String getFormatted(long value) {
|
||||
return (double) FastMath.round(((double) value / divisor) * 100D) / 100D + unit;
|
||||
}
|
||||
|
||||
public Desire getDesire() {
|
||||
return desire;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
|
||||
/**
|
||||
* Enum to represent the "goal" of a value, whether it is desirable for the value to be high (e.g. Frequency), or low (e.g. Period)
|
||||
*/
|
||||
public enum Desire {
|
||||
LOW, HIGH
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
public class Frame {
|
||||
private final String id;
|
||||
private final long start;
|
||||
|
||||
public Frame(String id) {
|
||||
this.id = id;
|
||||
this.start = System.nanoTime();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
import com.dfsek.terra.api.math.MathUtil;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class to record and hold all data for a single type of measurement performed by the profiler.
|
||||
*/
|
||||
public class Measurement {
|
||||
private final List<Long> measurements = new LinkedList<>();
|
||||
private final long desirable;
|
||||
private final DataType type;
|
||||
private long min = Long.MAX_VALUE;
|
||||
private long max = Long.MIN_VALUE;
|
||||
|
||||
/**
|
||||
* Constructs a new Measurement with a desired value and DataType.
|
||||
*
|
||||
* @param desirable The desired value of the measurement.
|
||||
* @param type The type of data the measurement is holding.
|
||||
*/
|
||||
public Measurement(long desirable, DataType type) {
|
||||
this.desirable = desirable;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void record(long value) {
|
||||
max = FastMath.max(value, max);
|
||||
min = FastMath.min(value, min);
|
||||
measurements.add(value);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return measurements.size();
|
||||
}
|
||||
|
||||
public ProfileFuture beginMeasurement() {
|
||||
ProfileFuture future = new ProfileFuture();
|
||||
long current = System.nanoTime();
|
||||
future.thenRun(() -> record(System.nanoTime() - current));
|
||||
return future;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
min = Long.MAX_VALUE;
|
||||
max = Long.MIN_VALUE;
|
||||
measurements.clear();
|
||||
}
|
||||
|
||||
public DataHolder getDataHolder() {
|
||||
return new DataHolder(type, desirable, 0.25);
|
||||
}
|
||||
|
||||
public long getMin() {
|
||||
if(min == Long.MAX_VALUE) return 0;
|
||||
return min;
|
||||
}
|
||||
|
||||
public long getMax() {
|
||||
if(max == Long.MIN_VALUE) return 0;
|
||||
return max;
|
||||
}
|
||||
|
||||
public long average() {
|
||||
BigInteger running = BigInteger.valueOf(0);
|
||||
List<Long> mTemp = new GlueList<>(measurements);
|
||||
for(Long l : mTemp) {
|
||||
running = running.add(BigInteger.valueOf(l));
|
||||
}
|
||||
if(measurements.size() == 0) return 0;
|
||||
return running.divide(BigInteger.valueOf(measurements.size())).longValue();
|
||||
}
|
||||
|
||||
public double getStdDev() {
|
||||
return MathUtil.standardDeviation(new GlueList<>(measurements));
|
||||
}
|
||||
|
||||
public int entries() {
|
||||
return measurements.size();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
public class ProfileFrame implements AutoCloseable {
|
||||
private final Runnable action;
|
||||
|
||||
public ProfileFrame(Runnable action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
action.run();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ProfileFuture extends CompletableFuture<Boolean> implements AutoCloseable {
|
||||
public ProfileFuture() {
|
||||
super();
|
||||
}
|
||||
|
||||
public boolean complete() {
|
||||
return super.complete(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.complete();
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface Profiler {
|
||||
void push(String frame);
|
||||
|
||||
void pop(String frame);
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
|
||||
Map<String, Timings> getTimings();
|
||||
|
||||
default ProfileFrame profile(String frame) {
|
||||
push(frame);
|
||||
return new ProfileFrame(() -> pop(frame));
|
||||
}
|
||||
|
||||
default void reset() {
|
||||
// todo: impl
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
import com.dfsek.terra.profiler.exception.MalformedStackException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
public class ProfilerImpl implements Profiler {
|
||||
private static final ThreadLocal<Stack<Frame>> THREAD_STACK = ThreadLocal.withInitial(Stack::new);
|
||||
private static final ThreadLocal<Map<String, List<Long>>> TIMINGS = ThreadLocal.withInitial(HashMap::new);
|
||||
private final List<Map<String, List<Long>>> accessibleThreadMaps = new ArrayList<>();
|
||||
private volatile boolean running = false;
|
||||
private static boolean instantiated = false;
|
||||
|
||||
private static final ThreadLocal<Boolean> SAFE = ThreadLocal.withInitial(() -> false);
|
||||
private static final ThreadLocal<MutableInteger> STACK_SIZE = ThreadLocal.withInitial(() -> new MutableInteger(0));
|
||||
|
||||
public ProfilerImpl() {
|
||||
if(instantiated) throw new IllegalStateException("Only one instance of Profiler may exist!");
|
||||
instantiated = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push(String frame) {
|
||||
STACK_SIZE.get().increment();
|
||||
if(running && SAFE.get()) {
|
||||
Stack<Frame> stack = THREAD_STACK.get();
|
||||
stack.push(new Frame(stack.isEmpty() ? frame : stack.peek().getId() + "." + frame));
|
||||
} else SAFE.set(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pop(String frame) {
|
||||
MutableInteger size = STACK_SIZE.get();
|
||||
size.decrement();
|
||||
if(running && SAFE.get()) {
|
||||
long time = System.nanoTime();
|
||||
Stack<Frame> stack = THREAD_STACK.get();
|
||||
|
||||
Map<String, List<Long>> timingsMap = TIMINGS.get();
|
||||
|
||||
if(timingsMap.size() == 0) {
|
||||
synchronized(accessibleThreadMaps) {
|
||||
accessibleThreadMaps.add(timingsMap);
|
||||
}
|
||||
}
|
||||
|
||||
Frame top = stack.pop();
|
||||
if((stack.size() != 0 && !top.getId().endsWith("." + frame)) || (stack.size() == 0 && !top.getId().equals(frame)))
|
||||
throw new MalformedStackException("Expected " + frame + ", found " + top);
|
||||
|
||||
List<Long> timings = timingsMap.computeIfAbsent(top.getId(), id -> new ArrayList<>());
|
||||
|
||||
timings.add(time - top.getStart());
|
||||
}
|
||||
if(size.get() == 0) SAFE.set(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
running = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
running = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Timings> getTimings() {
|
||||
Map<String, Timings> map = new HashMap<>();
|
||||
accessibleThreadMaps.forEach(smap -> smap.forEach((key, list) -> {
|
||||
String[] keys = key.split("\\.");
|
||||
Timings timings = map.computeIfAbsent(keys[0], id -> new Timings());
|
||||
for(int i = 1; i < keys.length; i++) {
|
||||
timings = timings.getSubItem(keys[i]);
|
||||
}
|
||||
list.forEach(timings::addTime);
|
||||
}));
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
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;
|
||||
|
||||
public class Timings {
|
||||
private final Map<String, Timings> subItems = new HashMap<>();
|
||||
|
||||
private final List<Long> timings = new ArrayList<>();
|
||||
|
||||
public void addTime(long time) {
|
||||
timings.add(time);
|
||||
}
|
||||
|
||||
public List<Long> getTimings() {
|
||||
return timings;
|
||||
}
|
||||
|
||||
public double average() {
|
||||
return (double) timings.stream().reduce(0L, Long::sum) / timings.size();
|
||||
}
|
||||
|
||||
public long max() {
|
||||
return timings.stream().mapToLong(Long::longValue).max().orElse(0L);
|
||||
}
|
||||
|
||||
public long min() {
|
||||
return timings.stream().mapToLong(Long::longValue).min().orElse(0L);
|
||||
}
|
||||
|
||||
public double sum() {
|
||||
return timings.stream().mapToDouble(Long::doubleValue).sum();
|
||||
}
|
||||
|
||||
public Timings getSubItem(String id) {
|
||||
return subItems.computeIfAbsent(id, s -> new Timings());
|
||||
}
|
||||
|
||||
public String toString(int indent, Timings parent, Set<Integer> branches) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append((double) min() / 1000000).append("ms min / ").append(average() / 1000000).append("ms avg / ")
|
||||
.append((double) max() / 1000000).append("ms max (").append(timings.size()).append(" samples, ")
|
||||
.append((sum() / parent.sum()) * 100).append("% of parent)");
|
||||
|
||||
List<String> frames = new ArrayList<>();
|
||||
Set<Integer> newBranches = new HashSet<>(branches);
|
||||
newBranches.add(indent);
|
||||
subItems.forEach((id, timings) -> frames.add(id + ": " + timings.toString(indent + 1, this, newBranches)));
|
||||
|
||||
for(int i = 0; i < frames.size(); i++) {
|
||||
builder.append('\n');
|
||||
for(int j = 0; j < indent; j++) {
|
||||
if(branches.contains(j)) builder.append("│ ");
|
||||
else builder.append(" ");
|
||||
}
|
||||
if(i == frames.size() - 1 && !frames.get(i).contains("\n")) builder.append("└───");
|
||||
else builder.append("├───");
|
||||
builder.append(frames.get(i));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(1, this, Collections.emptySet());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.dfsek.terra.profiler;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class WorldProfiler {
|
||||
private final BiMap<String, Measurement> measures = HashBiMap.create();
|
||||
private final World world;
|
||||
private boolean isProfiling;
|
||||
|
||||
public WorldProfiler(World w) {
|
||||
if(!TerraWorld.isTerraWorld(w))
|
||||
throw new IllegalArgumentException("Attempted to instantiate profiler on non-Terra managed world!");
|
||||
this.addMeasurement(new Measurement(2500000, DataType.PERIOD_MILLISECONDS), "TotalChunkGenTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "FloraTime")
|
||||
.addMeasurement(new Measurement(10000000, DataType.PERIOD_MILLISECONDS), "TreeTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "OreTime")
|
||||
.addMeasurement(new Measurement(5000000, DataType.PERIOD_MILLISECONDS), "CaveTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "StructureTime");
|
||||
|
||||
isProfiling = false;
|
||||
this.world = w;
|
||||
}
|
||||
|
||||
public String getResultsFormatted() {
|
||||
if(! isProfiling) return "Profiler is not currently running.";
|
||||
StringBuilder result = new StringBuilder("Gaea World Profiler Results (Min / Avg / Max / Std Dev): \n");
|
||||
for(Map.Entry<String, Measurement> e : measures.entrySet()) {
|
||||
result
|
||||
.append(e.getKey())
|
||||
.append(": ")
|
||||
.append(e.getValue().getDataHolder().getFormattedData(e.getValue().getMin()))
|
||||
.append(" / ")
|
||||
.append(e.getValue().getDataHolder().getFormattedData(e.getValue().average()))
|
||||
.append(" / ")
|
||||
.append(e.getValue().getDataHolder().getFormattedData(e.getValue().getMax()))
|
||||
.append(" / ")
|
||||
.append((double) FastMath.round((e.getValue().getStdDev() / 1000000) * 100D) / 100D)
|
||||
.append("ms")
|
||||
.append(" (x").append(e.getValue().size()).append(")\n");
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
for(Map.Entry<String, Measurement> e : measures.entrySet()) {
|
||||
e.getValue().reset();
|
||||
}
|
||||
}
|
||||
|
||||
public com.dfsek.terra.profiler.WorldProfiler addMeasurement(Measurement m, String name) {
|
||||
measures.put(name, m);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMeasurement(String id, long value) {
|
||||
if(isProfiling) measures.get(id).record(value);
|
||||
}
|
||||
|
||||
public ProfileFuture measure(String id) {
|
||||
if(isProfiling) return measures.get(id).beginMeasurement();
|
||||
else return null;
|
||||
}
|
||||
|
||||
public String getID(Measurement m) {
|
||||
return measures.inverse().get(m);
|
||||
}
|
||||
|
||||
public boolean isProfiling() {
|
||||
return isProfiling;
|
||||
}
|
||||
|
||||
public void setProfiling(boolean enabled) {
|
||||
this.isProfiling = enabled;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.dfsek.terra.profiler.exception;
|
||||
|
||||
public class MalformedStackException extends ProfilerException {
|
||||
private static final long serialVersionUID = -3009539681021691054L;
|
||||
|
||||
public MalformedStackException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public MalformedStackException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public MalformedStackException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.dfsek.terra.profiler.exception;
|
||||
|
||||
public class ProfilerException extends RuntimeException {
|
||||
private static final long serialVersionUID = 8206737998791649002L;
|
||||
|
||||
public ProfilerException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ProfilerException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ProfilerException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.registry.exception.DuplicateEntryException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -20,16 +19,7 @@ import java.util.stream.Collectors;
|
||||
* @param <T>
|
||||
*/
|
||||
public class OpenRegistry<T> implements Registry<T> {
|
||||
private final Map<String, Entry<T>> objects;
|
||||
private static final Entry<?> NULL = new Entry<>(null);
|
||||
|
||||
public OpenRegistry() {
|
||||
objects = new HashMap<>();
|
||||
}
|
||||
|
||||
protected OpenRegistry(Map<String, Entry<T>> init) {
|
||||
this.objects = init;
|
||||
}
|
||||
private final Map<String, Entry<T>> objects = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public T load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
@@ -73,10 +63,9 @@ public class OpenRegistry<T> implements Registry<T> {
|
||||
return objects.containsKey(identifier);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T get(String identifier) {
|
||||
return objects.getOrDefault(identifier, (Entry<T>) NULL).getValue();
|
||||
return objects.get(identifier).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,8 +79,8 @@ public class OpenRegistry<T> implements Registry<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<T> entries() {
|
||||
return objects.values().stream().map(Entry::getRaw).collect(Collectors.toList());
|
||||
public Set<T> entries() {
|
||||
return objects.values().stream().map(Entry::getRaw).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user