mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-05-20 16:50:28 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 712df89064 | |||
| ad41c9bd7d | |||
| 806b9080f0 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
import com.dfsek.terra.getGitHash
|
||||
|
||||
val versionObj = Version("5", "3", "3", true)
|
||||
val versionObj = Version("5", "3", "2", true)
|
||||
|
||||
allprojects {
|
||||
version = versionObj
|
||||
|
||||
@@ -14,14 +14,14 @@ fun Project.configureCompilation() {
|
||||
apply(plugin = "idea")
|
||||
|
||||
configure<JavaPluginConvention> {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_14
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
doFirst {
|
||||
options.compilerArgs.add("-Xlint:all")
|
||||
options.compilerArgs.addAll(arrayOf("-Xlint:all", "--release", "8", "-Xplugin:jabel"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ fun Project.configureDependencies() {
|
||||
dependencies {
|
||||
"testImplementation"("org.junit.jupiter:junit-jupiter-api:5.7.0")
|
||||
"testImplementation"("org.junit.jupiter:junit-jupiter-engine:5.7.0")
|
||||
"annotationProcessor"("com.github.bsideup.jabel:jabel-javac-plugin:0.3.0")
|
||||
"api"("org.jetbrains:annotations:20.1.0")
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import com.dfsek.terra.api.addons.TerraAddon;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
@@ -20,8 +19,6 @@ import com.dfsek.terra.world.TerraWorld;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
@@ -78,8 +75,4 @@ public interface TerraPlugin extends LoaderRegistrar {
|
||||
default JarFile getModJar() throws URISyntaxException, IOException {
|
||||
return JarUtil.getJarFile();
|
||||
}
|
||||
|
||||
default Set<Mod> getMods() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-25
@@ -1,9 +1,6 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
import com.dfsek.terra.config.fileloaders.Loader;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
/**
|
||||
@@ -11,34 +8,13 @@ import com.dfsek.terra.config.pack.ConfigPack;
|
||||
*/
|
||||
public abstract class ConfigPackLoadEvent implements PackEvent {
|
||||
private final ConfigPack pack;
|
||||
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
||||
private final Loader loader;
|
||||
|
||||
public ConfigPackLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader, Loader loader) {
|
||||
public ConfigPackLoadEvent(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
this.configLoader = configLoader;
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a custom {@link ConfigTemplate} using the pack manifest.
|
||||
*
|
||||
* @param template Template to register.
|
||||
*/
|
||||
public void loadTemplate(ConfigTemplate template) throws ConfigException {
|
||||
configLoader.accept(template);
|
||||
}
|
||||
|
||||
public interface ExceptionalConsumer<T extends ConfigTemplate> {
|
||||
void accept(T value) throws ConfigException;
|
||||
}
|
||||
|
||||
public Loader getLoader() {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -1,14 +1,12 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.fileloaders.Loader;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
/**
|
||||
* Called when a config pack has finished loading.
|
||||
*/
|
||||
public class ConfigPackPostLoadEvent extends ConfigPackLoadEvent {
|
||||
public ConfigPackPostLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configTemplateLoader, Loader loader) {
|
||||
super(pack, configTemplateLoader, loader);
|
||||
public ConfigPackPostLoadEvent(ConfigPack pack) {
|
||||
super(pack);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -1,14 +1,12 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.fileloaders.Loader;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
/**
|
||||
* Called before a config pack's registries are filled. At this point, the pack manifest has been loaded, and all registries are empty.
|
||||
*/
|
||||
public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent {
|
||||
public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader, Loader loader) {
|
||||
super(pack, configLoader, loader);
|
||||
public ConfigPackPreLoadEvent(ConfigPack pack) {
|
||||
super(pack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,8 @@ public class ExpressionSampler implements NoiseSampler {
|
||||
|
||||
functions.forEach((id, noise) -> {
|
||||
switch(noise.getDimensions()) {
|
||||
case 2:
|
||||
parser.registerFunction(id, new NoiseFunction2(noise.apply(seed)));
|
||||
break;
|
||||
case 3:
|
||||
parser.registerFunction(id, new NoiseFunction3(noise.apply(seed)));
|
||||
break;
|
||||
case 2 -> parser.registerFunction(id, new NoiseFunction2(noise.apply(seed)));
|
||||
case 3 -> parser.registerFunction(id, new NoiseFunction3(noise.apply(seed)));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+30
-60
@@ -333,36 +333,21 @@ public class CellularSampler extends NoiseFunction {
|
||||
}
|
||||
}
|
||||
|
||||
switch(returnType) {
|
||||
case CellValue:
|
||||
return closestHash * (1 / 2147483648.0);
|
||||
case Distance:
|
||||
return distance0 - 1;
|
||||
case Distance2:
|
||||
return distance1 - 1;
|
||||
case Distance2Add:
|
||||
return (distance1 + distance0) * 0.5 - 1;
|
||||
case Distance2Sub:
|
||||
return distance1 - distance0 - 1;
|
||||
case Distance2Mul:
|
||||
return distance1 * distance0 * 0.5 - 1;
|
||||
case Distance2Div:
|
||||
return distance0 / distance1 - 1;
|
||||
case NoiseLookup:
|
||||
return noiseLookup.getNoise(center.getX(), center.getZ());
|
||||
case Distance3:
|
||||
return distance2 - 1;
|
||||
case Distance3Add:
|
||||
return (distance2 + distance0) * 0.5 - 1;
|
||||
case Distance3Sub:
|
||||
return distance2 - distance0 - 1;
|
||||
case Distance3Mul:
|
||||
return distance2 * distance0 - 1;
|
||||
case Distance3Div:
|
||||
return distance0 / distance2 - 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return switch(returnType) {
|
||||
case CellValue -> closestHash * (1 / 2147483648.0);
|
||||
case Distance -> distance0 - 1;
|
||||
case Distance2 -> distance1 - 1;
|
||||
case Distance2Add -> (distance1 + distance0) * 0.5 - 1;
|
||||
case Distance2Sub -> distance1 - distance0 - 1;
|
||||
case Distance2Mul -> distance1 * distance0 * 0.5 - 1;
|
||||
case Distance2Div -> distance0 / distance1 - 1;
|
||||
case NoiseLookup -> noiseLookup.getNoise(center.getX(), center.getZ());
|
||||
case Distance3 -> distance2 - 1;
|
||||
case Distance3Add -> (distance2 + distance0) * 0.5 - 1;
|
||||
case Distance3Sub -> distance2 - distance0 - 1;
|
||||
case Distance3Mul -> distance2 * distance0 - 1;
|
||||
case Distance3Div -> distance0 / distance2 - 1;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -507,36 +492,21 @@ public class CellularSampler extends NoiseFunction {
|
||||
}
|
||||
}
|
||||
|
||||
switch(returnType) {
|
||||
case CellValue:
|
||||
return closestHash * (1 / 2147483648.0);
|
||||
case Distance:
|
||||
return distance0 - 1;
|
||||
case Distance2:
|
||||
return distance1 - 1;
|
||||
case Distance2Add:
|
||||
return (distance1 + distance0) * 0.5 - 1;
|
||||
case Distance2Sub:
|
||||
return distance1 - distance0 - 1;
|
||||
case Distance2Mul:
|
||||
return distance1 * distance0 * 0.5 - 1;
|
||||
case Distance2Div:
|
||||
return distance0 / distance1 - 1;
|
||||
case NoiseLookup:
|
||||
return noiseLookup.getNoise(center.getX(), center.getY(), center.getZ());
|
||||
case Distance3:
|
||||
return distance2 - 1;
|
||||
case Distance3Add:
|
||||
return (distance2 + distance0) * 0.5 - 1;
|
||||
case Distance3Sub:
|
||||
return distance2 - distance0 - 1;
|
||||
case Distance3Mul:
|
||||
return distance2 * distance0 - 1;
|
||||
case Distance3Div:
|
||||
return distance0 / distance2 - 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return switch(returnType) {
|
||||
case CellValue -> closestHash * (1 / 2147483648.0);
|
||||
case Distance -> distance0 - 1;
|
||||
case Distance2 -> distance1 - 1;
|
||||
case Distance2Add -> (distance1 + distance0) * 0.5 - 1;
|
||||
case Distance2Sub -> distance1 - distance0 - 1;
|
||||
case Distance2Mul -> distance1 * distance0 * 0.5 - 1;
|
||||
case Distance2Div -> distance0 / distance1 - 1;
|
||||
case NoiseLookup -> noiseLookup.getNoise(center.getX(), center.getY(), center.getZ());
|
||||
case Distance3 -> distance2 - 1;
|
||||
case Distance3Add -> (distance2 + distance0) * 0.5 - 1;
|
||||
case Distance3Sub -> distance2 - distance0 - 1;
|
||||
case Distance3Mul -> distance2 * distance0 - 1;
|
||||
case Distance3Div -> distance0 / distance2 - 1;
|
||||
};
|
||||
}
|
||||
|
||||
public enum DistanceFunction {
|
||||
|
||||
@@ -83,66 +83,28 @@ public enum BlockFace {
|
||||
|
||||
@NotNull
|
||||
public BlockFace getOppositeFace() {
|
||||
switch(this) {
|
||||
case NORTH:
|
||||
return BlockFace.SOUTH;
|
||||
return switch(this) {
|
||||
case NORTH -> BlockFace.SOUTH;
|
||||
case SOUTH -> BlockFace.NORTH;
|
||||
case EAST -> BlockFace.WEST;
|
||||
case WEST -> BlockFace.EAST;
|
||||
case UP -> BlockFace.DOWN;
|
||||
case DOWN -> BlockFace.UP;
|
||||
case NORTH_EAST -> BlockFace.SOUTH_WEST;
|
||||
case NORTH_WEST -> BlockFace.SOUTH_EAST;
|
||||
case SOUTH_EAST -> BlockFace.NORTH_WEST;
|
||||
case SOUTH_WEST -> BlockFace.NORTH_EAST;
|
||||
case WEST_NORTH_WEST -> BlockFace.EAST_SOUTH_EAST;
|
||||
case NORTH_NORTH_WEST -> BlockFace.SOUTH_SOUTH_EAST;
|
||||
case NORTH_NORTH_EAST -> BlockFace.SOUTH_SOUTH_WEST;
|
||||
case EAST_NORTH_EAST -> BlockFace.WEST_SOUTH_WEST;
|
||||
case EAST_SOUTH_EAST -> BlockFace.WEST_NORTH_WEST;
|
||||
case SOUTH_SOUTH_EAST -> BlockFace.NORTH_NORTH_WEST;
|
||||
case SOUTH_SOUTH_WEST -> BlockFace.NORTH_NORTH_EAST;
|
||||
case WEST_SOUTH_WEST -> BlockFace.EAST_NORTH_EAST;
|
||||
case SELF -> BlockFace.SELF;
|
||||
};
|
||||
|
||||
case SOUTH:
|
||||
return BlockFace.NORTH;
|
||||
|
||||
case EAST:
|
||||
return BlockFace.WEST;
|
||||
|
||||
case WEST:
|
||||
return BlockFace.EAST;
|
||||
|
||||
case UP:
|
||||
return BlockFace.DOWN;
|
||||
|
||||
case DOWN:
|
||||
return BlockFace.UP;
|
||||
|
||||
case NORTH_EAST:
|
||||
return BlockFace.SOUTH_WEST;
|
||||
|
||||
case NORTH_WEST:
|
||||
return BlockFace.SOUTH_EAST;
|
||||
|
||||
case SOUTH_EAST:
|
||||
return BlockFace.NORTH_WEST;
|
||||
|
||||
case SOUTH_WEST:
|
||||
return BlockFace.NORTH_EAST;
|
||||
|
||||
case WEST_NORTH_WEST:
|
||||
return BlockFace.EAST_SOUTH_EAST;
|
||||
|
||||
case NORTH_NORTH_WEST:
|
||||
return BlockFace.SOUTH_SOUTH_EAST;
|
||||
|
||||
case NORTH_NORTH_EAST:
|
||||
return BlockFace.SOUTH_SOUTH_WEST;
|
||||
|
||||
case EAST_NORTH_EAST:
|
||||
return BlockFace.WEST_SOUTH_WEST;
|
||||
|
||||
case EAST_SOUTH_EAST:
|
||||
return BlockFace.WEST_NORTH_WEST;
|
||||
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return BlockFace.NORTH_NORTH_WEST;
|
||||
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return BlockFace.NORTH_NORTH_EAST;
|
||||
|
||||
case WEST_SOUTH_WEST:
|
||||
return BlockFace.EAST_NORTH_EAST;
|
||||
|
||||
case SELF:
|
||||
return BlockFace.SELF;
|
||||
}
|
||||
|
||||
return BlockFace.SELF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.dfsek.terra.api.platform.modloader;
|
||||
|
||||
public interface Mod {
|
||||
String getID();
|
||||
|
||||
String getVersion();
|
||||
|
||||
String getName();
|
||||
}
|
||||
@@ -43,8 +43,7 @@ public class Entry {
|
||||
if(entry.containsKey("functions")) {
|
||||
for(Object function : (JSONArray) entry.get("functions")) {
|
||||
switch(((String) ((JSONObject) function).get("function"))) {
|
||||
case "minecraft:set_count":
|
||||
case "set_count":
|
||||
case "minecraft:set_count", "set_count" -> {
|
||||
Object loot = ((JSONObject) function).get("count");
|
||||
long max, min;
|
||||
if(loot instanceof Long) {
|
||||
@@ -55,22 +54,20 @@ public class Entry {
|
||||
min = (long) ((JSONObject) loot).get("min");
|
||||
}
|
||||
functions.add(new AmountFunction(FastMath.toIntExact(min), FastMath.toIntExact(max)));
|
||||
break;
|
||||
case "minecraft:set_damage":
|
||||
case "set_damage":
|
||||
}
|
||||
case "minecraft:set_damage", "set_damage" -> {
|
||||
long maxDamage = (long) ((JSONObject) ((JSONObject) function).get("damage")).get("max");
|
||||
long minDamage = (long) ((JSONObject) ((JSONObject) function).get("damage")).get("min");
|
||||
functions.add(new DamageFunction(FastMath.toIntExact(minDamage), FastMath.toIntExact(maxDamage)));
|
||||
break;
|
||||
case "minecraft:enchant_with_levels":
|
||||
case "enchant_with_levels":
|
||||
}
|
||||
case "minecraft:enchant_with_levels", "enchant_with_levels" -> {
|
||||
long maxEnchant = (long) ((JSONObject) ((JSONObject) function).get("levels")).get("max");
|
||||
long minEnchant = (long) ((JSONObject) ((JSONObject) function).get("levels")).get("min");
|
||||
JSONArray disabled = null;
|
||||
if(((JSONObject) function).containsKey("disabled_enchants"))
|
||||
disabled = (JSONArray) ((JSONObject) function).get("disabled_enchants");
|
||||
functions.add(new EnchantFunction(FastMath.toIntExact(minEnchant), FastMath.toIntExact(maxEnchant), disabled, main));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,16 +96,12 @@ public class Parser {
|
||||
|
||||
ParserUtil.checkType(tokens.consume(), Token.Type.GROUP_BEGIN);
|
||||
|
||||
switch(identifier.getType()) {
|
||||
case FOR_LOOP:
|
||||
return parseForLoop(tokens, variableMap, identifier.getPosition());
|
||||
case IF_STATEMENT:
|
||||
return parseIfStatement(tokens, variableMap, identifier.getPosition(), loop);
|
||||
case WHILE_LOOP:
|
||||
return parseWhileLoop(tokens, variableMap, identifier.getPosition());
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown keyword " + identifier.getContent() + ": " + identifier.getPosition());
|
||||
}
|
||||
return switch(identifier.getType()) {
|
||||
case FOR_LOOP -> parseForLoop(tokens, variableMap, identifier.getPosition());
|
||||
case IF_STATEMENT -> parseIfStatement(tokens, variableMap, identifier.getPosition(), loop);
|
||||
case WHILE_LOOP -> parseWhileLoop(tokens, variableMap, identifier.getPosition());
|
||||
default -> throw new UnsupportedOperationException("Unknown keyword " + identifier.getContent() + ": " + identifier.getPosition());
|
||||
};
|
||||
}
|
||||
|
||||
private WhileKeyword parseWhileLoop(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap, Position start) throws ParseException {
|
||||
@@ -233,17 +229,13 @@ public class Parser {
|
||||
private ConstantExpression<?> parseConstantExpression(Tokenizer tokens) throws ParseException {
|
||||
Token constantToken = tokens.consume();
|
||||
Position position = constantToken.getPosition();
|
||||
switch(constantToken.getType()) {
|
||||
case NUMBER:
|
||||
String content = constantToken.getContent();
|
||||
return new NumericConstant(content.contains(".") ? Double.parseDouble(content) : Integer.parseInt(content), position);
|
||||
case STRING:
|
||||
return new StringConstant(constantToken.getContent(), position);
|
||||
case BOOLEAN:
|
||||
return new BooleanConstant(Boolean.parseBoolean(constantToken.getContent()), position);
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unsupported constant token: " + constantToken.getType() + " at position: " + position);
|
||||
}
|
||||
String content = constantToken.getContent();
|
||||
return switch(constantToken.getType()) {
|
||||
case NUMBER -> new NumericConstant(content.contains(".") ? Double.parseDouble(content) : Integer.parseInt(content), position);
|
||||
case STRING -> new StringConstant(content, position);
|
||||
case BOOLEAN -> new BooleanConstant(Boolean.parseBoolean(content), position);
|
||||
default -> throw new UnsupportedOperationException("Unsupported constant token: " + constantToken.getType() + " at position: " + position);
|
||||
};
|
||||
}
|
||||
|
||||
private Returnable<?> parseGroup(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap) throws ParseException {
|
||||
|
||||
@@ -79,16 +79,12 @@ public class ParserUtil {
|
||||
}
|
||||
|
||||
public static Returnable.ReturnType getVariableReturnType(Token varToken) throws ParseException {
|
||||
switch(varToken.getType()) {
|
||||
case NUMBER_VARIABLE:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case STRING_VARIABLE:
|
||||
return Returnable.ReturnType.STRING;
|
||||
case BOOLEAN_VARIABLE:
|
||||
return Returnable.ReturnType.BOOLEAN;
|
||||
default:
|
||||
throw new ParseException("Unexpected token " + varToken.getType() + "; expected variable declaration", varToken.getPosition());
|
||||
}
|
||||
return switch(varToken.getType()) {
|
||||
case NUMBER_VARIABLE -> Returnable.ReturnType.NUMBER;
|
||||
case STRING_VARIABLE -> Returnable.ReturnType.STRING;
|
||||
case BOOLEAN_VARIABLE -> Returnable.ReturnType.BOOLEAN;
|
||||
default -> throw new ParseException("Unexpected token " + varToken.getType() + "; expected variable declaration", varToken.getPosition());
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean hasPrecedence(Token.Type first, Token.Type second) {
|
||||
|
||||
+3
-9
@@ -32,15 +32,9 @@ public class Declaration<T> implements Item<T> {
|
||||
public T apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
||||
T result = value.apply(implementationArguments, variableMap);
|
||||
switch(type) {
|
||||
case NUMBER:
|
||||
variableMap.put(identifier, new NumberVariable((Number) result, position));
|
||||
break;
|
||||
case BOOLEAN:
|
||||
variableMap.put(identifier, new BooleanVariable((Boolean) result, position));
|
||||
break;
|
||||
case STRING:
|
||||
variableMap.put(identifier, new StringVariable((String) result, position));
|
||||
break;
|
||||
case NUMBER -> variableMap.put(identifier, new NumberVariable((Number) result, position));
|
||||
case BOOLEAN -> variableMap.put(identifier, new BooleanVariable((Boolean) result, position));
|
||||
case STRING -> variableMap.put(identifier, new StringVariable((String) result, position));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+4
-8
@@ -28,13 +28,9 @@ public class BiomeFunctionBuilder implements FunctionBuilder<BiomeFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+6
-12
@@ -39,17 +39,11 @@ public class BlockFunctionBuilder implements FunctionBuilder<AbstractBlockFuncti
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
case 4:
|
||||
return Returnable.ReturnType.BOOLEAN;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
case 4 -> Returnable.ReturnType.BOOLEAN;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+4
-8
@@ -21,13 +21,9 @@ public class CheckBlockFunctionBuilder implements FunctionBuilder<CheckBlockFunc
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+4
-9
@@ -6,7 +6,6 @@ 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.functions.CheckFunction;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import com.dfsek.terra.world.generation.math.SamplerCache;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,13 +29,9 @@ public class CheckFunctionBuilder implements FunctionBuilder<CheckFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+5
-10
@@ -29,15 +29,10 @@ public class EntityFunctionBuilder implements FunctionBuilder<EntityFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+4
-8
@@ -25,13 +25,9 @@ public class GetMarkFunctionBuilder implements FunctionBuilder<GetMarkFunction>
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+5
-10
@@ -34,15 +34,10 @@ public class LootFunctionBuilder implements FunctionBuilder<LootFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+5
-10
@@ -29,15 +29,10 @@ public class PullFunctionBuilder implements FunctionBuilder<PullFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+5
-10
@@ -26,15 +26,10 @@ public class SetMarkFunctionBuilder implements FunctionBuilder<SetMarkFunction>
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+5
-10
@@ -30,15 +30,10 @@ public class StateFunctionBuilder implements FunctionBuilder<StateFunction> {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
case 3:
|
||||
return Returnable.ReturnType.STRING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
case 3 -> Returnable.ReturnType.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+4
-8
@@ -36,13 +36,9 @@ public class StructureFunctionBuilder implements FunctionBuilder<StructureFuncti
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return Returnable.ReturnType.STRING;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Returnable.ReturnType.NUMBER;
|
||||
default -> Returnable.ReturnType.STRING;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,18 +12,13 @@ public enum Rotation {
|
||||
}
|
||||
|
||||
public static Rotation fromDegrees(int deg) {
|
||||
switch(FastMath.floorMod(deg, 360)) {
|
||||
case 0:
|
||||
return Rotation.NONE;
|
||||
case 90:
|
||||
return Rotation.CW_90;
|
||||
case 180:
|
||||
return Rotation.CW_180;
|
||||
case 270:
|
||||
return Rotation.CCW_90;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return switch(FastMath.floorMod(deg, 360)) {
|
||||
case 0 -> Rotation.NONE;
|
||||
case 90 -> Rotation.CW_90;
|
||||
case 180 -> Rotation.CW_180;
|
||||
case 270 -> Rotation.CCW_90;
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
}
|
||||
|
||||
public int getDegrees() {
|
||||
@@ -31,18 +26,12 @@ public enum Rotation {
|
||||
}
|
||||
|
||||
public Rotation inverse() {
|
||||
switch(this) {
|
||||
case NONE:
|
||||
return NONE;
|
||||
case CCW_90:
|
||||
return CW_90;
|
||||
case CW_90:
|
||||
return CCW_90;
|
||||
case CW_180:
|
||||
return CW_180;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return switch(this) {
|
||||
case NONE -> NONE;
|
||||
case CCW_90 -> CW_90;
|
||||
case CW_90 -> CCW_90;
|
||||
case CW_180 -> CW_180;
|
||||
};
|
||||
}
|
||||
|
||||
public Rotation rotate(Rotation rotation) {
|
||||
|
||||
@@ -30,15 +30,9 @@ public class RotationUtil {
|
||||
public static void rotateVector(Vector2 orig, Rotation r) {
|
||||
Vector2 copy = orig.clone();
|
||||
switch(r) {
|
||||
case CW_90:
|
||||
copy.setX(orig.getZ()).setZ(-orig.getX());
|
||||
break;
|
||||
case CCW_90:
|
||||
copy.setX(-orig.getZ()).setZ(orig.getX());
|
||||
break;
|
||||
case CW_180:
|
||||
copy.multiply(-1);
|
||||
break;
|
||||
case CW_90 -> copy.setX(orig.getZ()).setZ(-orig.getX());
|
||||
case CCW_90 -> copy.setX(-orig.getZ()).setZ(orig.getX());
|
||||
case CW_180 -> copy.multiply(-1);
|
||||
}
|
||||
orig.setX(copy.getX());
|
||||
orig.setZ(copy.getZ());
|
||||
@@ -68,42 +62,25 @@ public class RotationUtil {
|
||||
* @return integer representation of BlockFace
|
||||
*/
|
||||
public static int faceRotation(BlockFace f) {
|
||||
switch(f) {
|
||||
case NORTH:
|
||||
return 0;
|
||||
case NORTH_NORTH_EAST:
|
||||
return 1;
|
||||
case NORTH_EAST:
|
||||
return 2;
|
||||
case EAST_NORTH_EAST:
|
||||
return 3;
|
||||
case EAST:
|
||||
return 4;
|
||||
case EAST_SOUTH_EAST:
|
||||
return 5;
|
||||
case SOUTH_EAST:
|
||||
return 6;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return 7;
|
||||
case SOUTH:
|
||||
return 8;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return 9;
|
||||
case SOUTH_WEST:
|
||||
return 10;
|
||||
case WEST_SOUTH_WEST:
|
||||
return 11;
|
||||
case WEST:
|
||||
return 12;
|
||||
case WEST_NORTH_WEST:
|
||||
return 13;
|
||||
case NORTH_WEST:
|
||||
return 14;
|
||||
case NORTH_NORTH_WEST:
|
||||
return 15;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return switch(f) {
|
||||
case NORTH -> 0;
|
||||
case NORTH_NORTH_EAST -> 1;
|
||||
case NORTH_EAST -> 2;
|
||||
case EAST_NORTH_EAST -> 3;
|
||||
case EAST -> 4;
|
||||
case EAST_SOUTH_EAST -> 5;
|
||||
case SOUTH_EAST -> 6;
|
||||
case SOUTH_SOUTH_EAST -> 7;
|
||||
case SOUTH -> 8;
|
||||
case SOUTH_SOUTH_WEST -> 9;
|
||||
case SOUTH_WEST -> 10;
|
||||
case WEST_SOUTH_WEST -> 11;
|
||||
case WEST -> 12;
|
||||
case WEST_NORTH_WEST -> 13;
|
||||
case NORTH_WEST -> 14;
|
||||
case NORTH_NORTH_WEST -> 15;
|
||||
default -> -1;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,42 +90,25 @@ public class RotationUtil {
|
||||
* @return BlockFace represented by integer.
|
||||
*/
|
||||
public static BlockFace fromRotation(int r) {
|
||||
switch(FastMath.floorMod(r, 16)) {
|
||||
case 0:
|
||||
return BlockFace.NORTH;
|
||||
case 1:
|
||||
return BlockFace.NORTH_NORTH_EAST;
|
||||
case 2:
|
||||
return BlockFace.NORTH_EAST;
|
||||
case 3:
|
||||
return BlockFace.EAST_NORTH_EAST;
|
||||
case 4:
|
||||
return BlockFace.EAST;
|
||||
case 5:
|
||||
return BlockFace.EAST_SOUTH_EAST;
|
||||
case 6:
|
||||
return BlockFace.SOUTH_EAST;
|
||||
case 7:
|
||||
return BlockFace.SOUTH_SOUTH_EAST;
|
||||
case 8:
|
||||
return BlockFace.SOUTH;
|
||||
case 9:
|
||||
return BlockFace.SOUTH_SOUTH_WEST;
|
||||
case 10:
|
||||
return BlockFace.SOUTH_WEST;
|
||||
case 11:
|
||||
return BlockFace.WEST_SOUTH_WEST;
|
||||
case 12:
|
||||
return BlockFace.WEST;
|
||||
case 13:
|
||||
return BlockFace.WEST_NORTH_WEST;
|
||||
case 14:
|
||||
return BlockFace.NORTH_WEST;
|
||||
case 15:
|
||||
return BlockFace.NORTH_NORTH_WEST;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return switch(FastMath.floorMod(r, 16)) {
|
||||
case 0 -> BlockFace.NORTH;
|
||||
case 1 -> BlockFace.NORTH_NORTH_EAST;
|
||||
case 2 -> BlockFace.NORTH_EAST;
|
||||
case 3 -> BlockFace.EAST_NORTH_EAST;
|
||||
case 4 -> BlockFace.EAST;
|
||||
case 5 -> BlockFace.EAST_SOUTH_EAST;
|
||||
case 6 -> BlockFace.SOUTH_EAST;
|
||||
case 7 -> BlockFace.SOUTH_SOUTH_EAST;
|
||||
case 8 -> BlockFace.SOUTH;
|
||||
case 9 -> BlockFace.SOUTH_SOUTH_WEST;
|
||||
case 10 -> BlockFace.SOUTH_WEST;
|
||||
case 11 -> BlockFace.WEST_SOUTH_WEST;
|
||||
case 12 -> BlockFace.WEST;
|
||||
case 13 -> BlockFace.WEST_NORTH_WEST;
|
||||
case 14 -> BlockFace.NORTH_WEST;
|
||||
case 15 -> BlockFace.NORTH_NORTH_WEST;
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
}
|
||||
|
||||
public static Axis getRotatedAxis(Axis orig, Rotation r) {
|
||||
@@ -174,78 +134,45 @@ public class RotationUtil {
|
||||
*/
|
||||
@SuppressWarnings("fallthrough")
|
||||
public static Rail.Shape getRotatedRail(Rail.Shape orig, Rotation r) {
|
||||
switch(r) {
|
||||
case CCW_90:
|
||||
switch(orig) {
|
||||
case NORTH_WEST:
|
||||
return Rail.Shape.SOUTH_WEST;
|
||||
case NORTH_SOUTH:
|
||||
return Rail.Shape.EAST_WEST;
|
||||
case SOUTH_WEST:
|
||||
return Rail.Shape.SOUTH_EAST;
|
||||
case SOUTH_EAST:
|
||||
return Rail.Shape.NORTH_EAST;
|
||||
case EAST_WEST:
|
||||
return Rail.Shape.NORTH_SOUTH;
|
||||
case NORTH_EAST:
|
||||
return Rail.Shape.NORTH_WEST;
|
||||
case ASCENDING_EAST:
|
||||
return Rail.Shape.ASCENDING_NORTH;
|
||||
case ASCENDING_WEST:
|
||||
return Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_NORTH:
|
||||
return Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_SOUTH:
|
||||
return Rail.Shape.ASCENDING_EAST;
|
||||
}
|
||||
case CW_90:
|
||||
switch(orig) {
|
||||
case NORTH_WEST:
|
||||
return Rail.Shape.NORTH_EAST;
|
||||
case NORTH_SOUTH:
|
||||
return Rail.Shape.EAST_WEST;
|
||||
case SOUTH_WEST:
|
||||
return Rail.Shape.NORTH_WEST;
|
||||
case SOUTH_EAST:
|
||||
return Rail.Shape.SOUTH_WEST;
|
||||
case EAST_WEST:
|
||||
return Rail.Shape.NORTH_SOUTH;
|
||||
case NORTH_EAST:
|
||||
return Rail.Shape.SOUTH_EAST;
|
||||
case ASCENDING_EAST:
|
||||
return Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_WEST:
|
||||
return Rail.Shape.ASCENDING_NORTH;
|
||||
case ASCENDING_NORTH:
|
||||
return Rail.Shape.ASCENDING_EAST;
|
||||
case ASCENDING_SOUTH:
|
||||
return Rail.Shape.ASCENDING_WEST;
|
||||
}
|
||||
case CW_180:
|
||||
switch(orig) {
|
||||
case NORTH_WEST:
|
||||
return Rail.Shape.SOUTH_EAST;
|
||||
case NORTH_SOUTH:
|
||||
return Rail.Shape.NORTH_SOUTH;
|
||||
case SOUTH_WEST:
|
||||
return Rail.Shape.NORTH_EAST;
|
||||
case SOUTH_EAST:
|
||||
return Rail.Shape.NORTH_WEST;
|
||||
case EAST_WEST:
|
||||
return Rail.Shape.EAST_WEST;
|
||||
case NORTH_EAST:
|
||||
return Rail.Shape.SOUTH_WEST;
|
||||
case ASCENDING_EAST:
|
||||
return Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_WEST:
|
||||
return Rail.Shape.ASCENDING_EAST;
|
||||
case ASCENDING_NORTH:
|
||||
return Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_SOUTH:
|
||||
return Rail.Shape.ASCENDING_NORTH;
|
||||
}
|
||||
}
|
||||
return orig;
|
||||
return switch(r) {
|
||||
case CCW_90 -> switch(orig) {
|
||||
case NORTH_WEST -> Rail.Shape.SOUTH_WEST;
|
||||
case NORTH_SOUTH -> Rail.Shape.EAST_WEST;
|
||||
case SOUTH_WEST -> Rail.Shape.SOUTH_EAST;
|
||||
case SOUTH_EAST -> Rail.Shape.NORTH_EAST;
|
||||
case EAST_WEST -> Rail.Shape.NORTH_SOUTH;
|
||||
case NORTH_EAST -> Rail.Shape.NORTH_WEST;
|
||||
case ASCENDING_EAST -> Rail.Shape.ASCENDING_NORTH;
|
||||
case ASCENDING_WEST -> Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_NORTH -> Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_SOUTH -> Rail.Shape.ASCENDING_EAST;
|
||||
};
|
||||
case CW_90 -> switch(orig) {
|
||||
case NORTH_WEST -> Rail.Shape.NORTH_EAST;
|
||||
case NORTH_SOUTH -> Rail.Shape.EAST_WEST;
|
||||
case SOUTH_WEST -> Rail.Shape.NORTH_WEST;
|
||||
case SOUTH_EAST -> Rail.Shape.SOUTH_WEST;
|
||||
case EAST_WEST -> Rail.Shape.NORTH_SOUTH;
|
||||
case NORTH_EAST -> Rail.Shape.SOUTH_EAST;
|
||||
case ASCENDING_EAST -> Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_WEST -> Rail.Shape.ASCENDING_NORTH;
|
||||
case ASCENDING_NORTH -> Rail.Shape.ASCENDING_EAST;
|
||||
case ASCENDING_SOUTH -> Rail.Shape.ASCENDING_WEST;
|
||||
};
|
||||
case CW_180 -> switch(orig) {
|
||||
case NORTH_WEST -> Rail.Shape.SOUTH_EAST;
|
||||
case NORTH_SOUTH -> Rail.Shape.NORTH_SOUTH;
|
||||
case SOUTH_WEST -> Rail.Shape.NORTH_EAST;
|
||||
case SOUTH_EAST -> Rail.Shape.NORTH_WEST;
|
||||
case EAST_WEST -> Rail.Shape.EAST_WEST;
|
||||
case NORTH_EAST -> Rail.Shape.SOUTH_WEST;
|
||||
case ASCENDING_EAST -> Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_WEST -> Rail.Shape.ASCENDING_EAST;
|
||||
case ASCENDING_NORTH -> Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_SOUTH -> Rail.Shape.ASCENDING_NORTH;
|
||||
};
|
||||
default -> orig;
|
||||
};
|
||||
}
|
||||
|
||||
public static void rotateBlockData(BlockData data, Rotation r) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.api.transform;
|
||||
|
||||
public class NotNullValidator<T> implements Validator<T> {
|
||||
@Override
|
||||
public boolean validate(T value) {
|
||||
return !(value == null);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,6 @@
|
||||
package com.dfsek.terra.api.transform;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public interface Validator<T> {
|
||||
boolean validate(T value) throws TransformException;
|
||||
|
||||
static <T> Validator<T> notNull() {
|
||||
return Objects::nonNull;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,12 +60,8 @@ public class UserDefinedCarver extends Carver {
|
||||
|
||||
functions.forEach((id, noise) -> {
|
||||
switch(noise.getDimensions()) {
|
||||
case 2:
|
||||
p.registerFunction(id, new NoiseFunction2(noise.apply(hash)));
|
||||
break;
|
||||
case 3:
|
||||
p.registerFunction(id, new NoiseFunction3(noise.apply(hash)));
|
||||
break;
|
||||
case 2 -> p.registerFunction(id, new NoiseFunction2(noise.apply(hash)));
|
||||
case 3 -> p.registerFunction(id, new NoiseFunction3(noise.apply(hash)));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -46,8 +46,6 @@ import com.dfsek.terra.config.loaders.config.sampler.templates.ImageSamplerTempl
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.ClampNormalizerTemplate;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.LinearNormalizerTemplate;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.NormalNormalizerTemplate;
|
||||
import com.dfsek.terra.config.loaders.mod.ModDependentConfigSection;
|
||||
import com.dfsek.terra.config.loaders.mod.ModDependentConfigSectionLoader;
|
||||
import com.dfsek.terra.config.loaders.palette.CarverPaletteLoader;
|
||||
import com.dfsek.terra.config.loaders.palette.PaletteHolderLoader;
|
||||
import com.dfsek.terra.config.loaders.palette.PaletteLayerLoader;
|
||||
@@ -110,8 +108,7 @@ public class GenericLoaders implements LoaderRegistrar {
|
||||
|
||||
if(main != null) {
|
||||
registry.registerLoader(TerraAddon.class, main.getAddons())
|
||||
.registerLoader(BlockType.class, (t, object, cf) -> main.getWorldHandle().createBlockData((String) object).getBlockType())
|
||||
.registerLoader(ModDependentConfigSection.class, new ModDependentConfigSectionLoader(main));
|
||||
.registerLoader(BlockType.class, (t, object, cf) -> main.getWorldHandle().createBlockData((String) object).getBlockType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package com.dfsek.terra.config.builder;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.ExpressionSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.world.palette.holder.PaletteHolder;
|
||||
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
||||
import com.dfsek.terra.world.generation.WorldGenerator;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeneratorBuilder {
|
||||
private final Map<Long, WorldGenerator> gens = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
private String noiseEquation;
|
||||
|
||||
private String elevationEquation;
|
||||
|
||||
private String carvingEquation;
|
||||
|
||||
private Scope varScope;
|
||||
|
||||
private Map<String, NoiseSeeded> noiseBuilderMap;
|
||||
|
||||
private Map<String, FunctionTemplate> functionTemplateMap;
|
||||
|
||||
private PaletteHolder palettes;
|
||||
|
||||
private PaletteHolder slantPalettes;
|
||||
|
||||
private boolean preventInterpolation;
|
||||
|
||||
private boolean interpolateElevation;
|
||||
|
||||
private NoiseSeeded biomeNoise;
|
||||
|
||||
private double elevationWeight;
|
||||
|
||||
private int blendDistance;
|
||||
|
||||
private int blendStep;
|
||||
|
||||
private double blendWeight;
|
||||
|
||||
public WorldGenerator build(long seed) {
|
||||
synchronized(gens) {
|
||||
return gens.computeIfAbsent(seed, k -> {
|
||||
NoiseSampler noise;
|
||||
NoiseSampler elevation;
|
||||
NoiseSampler carving;
|
||||
try {
|
||||
noise = new ExpressionSampler(noiseEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
|
||||
elevation = elevationEquation == null ? new ConstantSampler(0) : new ExpressionSampler(elevationEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
|
||||
carving = new ExpressionSampler(carvingEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
|
||||
} catch(ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return new WorldGenerator(palettes, slantPalettes, noise, elevation, carving, biomeNoise.apply(seed), elevationWeight, blendDistance, blendStep, blendWeight);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlendWeight(double blendWeight) {
|
||||
this.blendWeight = blendWeight;
|
||||
}
|
||||
|
||||
public void setFunctionTemplateMap(Map<String, FunctionTemplate> functionTemplateMap) {
|
||||
this.functionTemplateMap = functionTemplateMap;
|
||||
}
|
||||
|
||||
public void setBlendStep(int blendStep) {
|
||||
this.blendStep = blendStep;
|
||||
}
|
||||
|
||||
public void setBlendDistance(int blendDistance) {
|
||||
this.blendDistance = blendDistance;
|
||||
}
|
||||
|
||||
public void setBiomeNoise(NoiseSeeded biomeNoise) {
|
||||
this.biomeNoise = biomeNoise;
|
||||
}
|
||||
|
||||
public void setElevationWeight(double elevationWeight) {
|
||||
this.elevationWeight = elevationWeight;
|
||||
}
|
||||
|
||||
public void setNoiseEquation(String noiseEquation) {
|
||||
this.noiseEquation = noiseEquation;
|
||||
}
|
||||
|
||||
public void setElevationEquation(String elevationEquation) {
|
||||
this.elevationEquation = elevationEquation;
|
||||
}
|
||||
|
||||
public void setCarvingEquation(String carvingEquation) {
|
||||
this.carvingEquation = carvingEquation;
|
||||
}
|
||||
|
||||
public Scope getVarScope() {
|
||||
return varScope;
|
||||
}
|
||||
|
||||
public void setVarScope(Scope varScope) {
|
||||
this.varScope = varScope;
|
||||
}
|
||||
|
||||
public void setNoiseBuilderMap(Map<String, NoiseSeeded> noiseBuilderMap) {
|
||||
this.noiseBuilderMap = noiseBuilderMap;
|
||||
}
|
||||
|
||||
public PaletteHolder getPalettes() {
|
||||
return palettes;
|
||||
}
|
||||
|
||||
public void setPalettes(PaletteHolder palettes) {
|
||||
this.palettes = palettes;
|
||||
}
|
||||
|
||||
public PaletteHolder getSlantPalettes() {
|
||||
return slantPalettes;
|
||||
}
|
||||
|
||||
public void setSlantPalettes(PaletteHolder slantPalettes) {
|
||||
this.slantPalettes = slantPalettes;
|
||||
}
|
||||
|
||||
public boolean isPreventInterpolation() {
|
||||
return preventInterpolation;
|
||||
}
|
||||
|
||||
public void setPreventInterpolation(boolean preventInterpolation) {
|
||||
this.preventInterpolation = preventInterpolation;
|
||||
}
|
||||
|
||||
public void setInterpolateElevation(boolean interpolateElevation) {
|
||||
this.interpolateElevation = interpolateElevation;
|
||||
}
|
||||
|
||||
public boolean interpolateElevation() {
|
||||
return interpolateElevation;
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,9 @@ public class OreFactory implements ConfigFactory<OreTemplate, Ore> {
|
||||
@Override
|
||||
public Ore build(OreTemplate config, TerraPlugin main) {
|
||||
BlockData m = config.getMaterial();
|
||||
switch(config.getType()) {
|
||||
case SPHERE:
|
||||
return new DeformedSphereOre(m, config.getReplaceable(), config.doPhysics(), config.getDeform(), config.getDeformFrequency(), config.getSize(), main);
|
||||
case VANILLA:
|
||||
return new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize(), main);
|
||||
}
|
||||
return null;
|
||||
return switch(config.getType()) {
|
||||
case SPHERE -> new DeformedSphereOre(m, config.getReplaceable(), config.doPhysics(), config.getDeform(), config.getDeformFrequency(), config.getSize(), main);
|
||||
case VANILLA -> new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize(), main);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
@@ -21,7 +20,7 @@ public class ZIPLoader extends Loader {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(!entry.isDirectory() && entry.getName().equals(singleFile)) return file.getInputStream(entry);
|
||||
}
|
||||
throw new FileNotFoundException("No such file: " + singleFile);
|
||||
throw new IllegalArgumentException("No such file: " + singleFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-10
@@ -21,15 +21,10 @@ public class BiomeProviderBuilderLoader implements TypeLoader<BiomeProvider.Biom
|
||||
public BiomeProvider.BiomeProviderBuilder load(Type t, Object c, ConfigLoader loader) throws LoadException { // TODO: clean this up
|
||||
Map<String, Object> map = (Map<String, Object>) c;
|
||||
|
||||
switch(loader.loadClass(BiomeProvider.Type.class, map.get("type"))) {
|
||||
case IMAGE:
|
||||
return loader.loadClass(ImageProviderTemplate.class, map);
|
||||
case PIPELINE:
|
||||
return loader.loadClass(BiomePipelineTemplate.class, map);
|
||||
case SINGLE:
|
||||
return loader.loadClass(SingleBiomeProviderTemplate.class, map);
|
||||
}
|
||||
|
||||
throw new LoadException("No such biome provider type: " + map.get("type"));
|
||||
return switch(loader.loadClass(BiomeProvider.Type.class, map.get("type"))) {
|
||||
case IMAGE -> loader.loadClass(ImageProviderTemplate.class, map);
|
||||
case PIPELINE -> loader.loadClass(BiomePipelineTemplate.class, map);
|
||||
case SINGLE -> loader.loadClass(SingleBiomeProviderTemplate.class, map);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+7
-14
@@ -38,20 +38,13 @@ public class StageBuilderLoader implements TypeLoader<StageSeeded> {
|
||||
return loader.loadClass(ExpanderStageTemplate.class, mutator);
|
||||
} else throw new LoadException("No such expander \"" + stageType + "\"");
|
||||
} else if(entry.getKey().equals("mutate")) {
|
||||
switch(loader.loadClass(MutatorStage.Type.class, mutator.get("type"))) {
|
||||
case SMOOTH:
|
||||
return loader.loadClass(SmoothMutatorTemplate.class, mutator);
|
||||
case REPLACE:
|
||||
return loader.loadClass(ReplaceMutatorTemplate.class, mutator);
|
||||
case REPLACE_LIST:
|
||||
return loader.loadClass(ReplaceListMutatorTemplate.class, mutator);
|
||||
case BORDER:
|
||||
return loader.loadClass(BorderMutatorTemplate.class, mutator);
|
||||
case BORDER_LIST:
|
||||
return loader.loadClass(BorderListMutatorTemplate.class, mutator);
|
||||
default:
|
||||
throw new LoadException("No such mutator type \"" + mutator.get("type"));
|
||||
}
|
||||
return switch(loader.loadClass(MutatorStage.Type.class, mutator.get("type"))) {
|
||||
case SMOOTH -> loader.loadClass(SmoothMutatorTemplate.class, mutator);
|
||||
case REPLACE -> loader.loadClass(ReplaceMutatorTemplate.class, mutator);
|
||||
case REPLACE_LIST -> loader.loadClass(ReplaceListMutatorTemplate.class, mutator);
|
||||
case BORDER -> loader.loadClass(BorderMutatorTemplate.class, mutator);
|
||||
case BORDER_LIST -> loader.loadClass(BorderListMutatorTemplate.class, mutator);
|
||||
};
|
||||
}
|
||||
throw new LoadException("No such mutator \"" + entry.getKey() + "\"");
|
||||
}
|
||||
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.mod;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModDependentConfigSection<T> {
|
||||
private static final Object NULL = new Object(); // Null object
|
||||
private final TerraPlugin main;
|
||||
private final Map<String, T> results = new HashMap<>();
|
||||
private final T defaultValue;
|
||||
@SuppressWarnings("unchecked")
|
||||
private T value = (T) NULL;
|
||||
|
||||
protected ModDependentConfigSection(TerraPlugin main, T defaultValue) {
|
||||
this.main = main;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public void add(String id, T value) {
|
||||
results.put(id, value);
|
||||
}
|
||||
|
||||
public static <T1> ModDependentConfigSection<T1> withDefault(T1 defaultValue) {
|
||||
return new ModDependentConfigSection<>(null, defaultValue);
|
||||
}
|
||||
|
||||
public T get() {
|
||||
if(value == NULL) value = compute(); // Cache the value.
|
||||
return value;
|
||||
}
|
||||
|
||||
private T compute() {
|
||||
if(main != null) {
|
||||
Set<String> mods = main.getMods().stream().map(Mod::getID).collect(Collectors.toSet());
|
||||
for(Map.Entry<String, T> entry : results.entrySet()) {
|
||||
if(mods.contains(entry.getKey())) return entry.getValue();
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.mod;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModDependentConfigSectionLoader implements TypeLoader<ModDependentConfigSection<?>> {
|
||||
private final TerraPlugin main;
|
||||
|
||||
public ModDependentConfigSectionLoader(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ModDependentConfigSection<?> load(Type type, Object c, ConfigLoader loader) throws LoadException {
|
||||
if(type instanceof ParameterizedType) {
|
||||
ParameterizedType pType = (ParameterizedType) type;
|
||||
Type generic = pType.getActualTypeArguments()[0];
|
||||
|
||||
if(c instanceof Map && ((Map<?, ?>) c).containsKey("default")) {
|
||||
Map<String, ?> map = (Map<String, ?>) c;
|
||||
|
||||
ModDependentConfigSection<Object> configSection = new ModDependentConfigSection<>(main, loader.loadType(generic, map.get("default")));
|
||||
|
||||
if(map.containsKey("mods")) {
|
||||
for(Map.Entry<String, ?> modEntry : ((Map<String, ?>) map.get("mods")).entrySet()) {
|
||||
configSection.add(modEntry.getKey(), loader.loadType(generic, modEntry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
return configSection;
|
||||
} else {
|
||||
return ModDependentConfigSection.withDefault(loader.loadType(generic, c)); // Load the original type otherwise.
|
||||
}
|
||||
} else throw new LoadException("Unable to load config! Could not retrieve parameterized type: " + type);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.dfsek.terra.config.pack;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.tectonic.abstraction.AbstractConfigLoader;
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
@@ -111,8 +110,6 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
private final TerraPlugin main;
|
||||
private final Loader loader;
|
||||
|
||||
private final Configuration configuration;
|
||||
|
||||
private final BiomeProvider.BiomeProviderBuilder biomeProviderBuilder;
|
||||
|
||||
|
||||
@@ -133,15 +130,11 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
File pack = new File(folder, "pack.yml");
|
||||
|
||||
try {
|
||||
configuration = new Configuration(new FileInputStream(pack));
|
||||
selfLoader.load(template, configuration);
|
||||
selfLoader.load(template, new FileInputStream(pack));
|
||||
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration), loader));
|
||||
|
||||
load(l, main);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
selfLoader.load(packPostTemplate, new FileInputStream(pack));
|
||||
biomeProviderBuilder = packPostTemplate.getProviderBuilder();
|
||||
@@ -181,12 +174,9 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
if(pack == null) throw new LoadException("No pack.yml file found in " + file.getName());
|
||||
|
||||
configuration = new Configuration(file.getInputStream(pack));
|
||||
selfLoader.load(template, configuration);
|
||||
selfLoader.load(template, file.getInputStream(pack));
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration), loader));
|
||||
|
||||
load(l, main);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
@@ -221,6 +211,8 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
|
||||
private void load(long start, TerraPlugin main) throws ConfigException {
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this));
|
||||
|
||||
for(Map.Entry<String, Double> var : template.getVariables().entrySet()) {
|
||||
varScope.create(var.getKey(), var.getValue());
|
||||
}
|
||||
@@ -253,7 +245,7 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
.open("flora", ".yml").then(configs -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.loadConfigs(configs, FloraTemplate::new), main)).close()
|
||||
.open("biomes", ".yml").then(configs -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.loadConfigs(configs, () -> new BiomeTemplate(this, main)), main)).close();
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration), loader));
|
||||
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.");
|
||||
}
|
||||
|
||||
|
||||
@@ -6,14 +6,12 @@ import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.api.addons.TerraAddon;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
||||
import com.dfsek.terra.config.loaders.mod.ModDependentConfigSection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class ConfigPackTemplate implements ConfigTemplate {
|
||||
@@ -41,7 +39,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
|
||||
@Value("structures.locatable")
|
||||
@Default
|
||||
private Map<String, ModDependentConfigSection<String>> locatable = new HashMap<>();
|
||||
private Map<String, String> locatable = new HashMap<>();
|
||||
|
||||
@Value("blend.terrain.elevation")
|
||||
@Default
|
||||
@@ -49,19 +47,19 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
|
||||
@Value("vanilla.mobs")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> vanillaMobs = ModDependentConfigSection.withDefault(true);
|
||||
private boolean vanillaMobs = true;
|
||||
|
||||
@Value("vanilla.caves")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> vanillaCaves = ModDependentConfigSection.withDefault(false);
|
||||
private boolean vanillaCaves = false;
|
||||
|
||||
@Value("vanilla.decorations")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> vanillaDecorations = ModDependentConfigSection.withDefault(false);
|
||||
private boolean vanillaDecorations = false;
|
||||
|
||||
@Value("vanilla.structures")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> vanillaStructures = ModDependentConfigSection.withDefault(false);
|
||||
private boolean vanillaStructures = false;
|
||||
|
||||
@Value("author")
|
||||
@Default
|
||||
@@ -69,7 +67,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
|
||||
@Value("disable.sapling")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableSaplings = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableSaplings = false;
|
||||
|
||||
@Value("version")
|
||||
@Default
|
||||
@@ -77,42 +75,42 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
|
||||
@Value("disable.carvers")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableCarvers = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableCarvers = false;
|
||||
|
||||
@Value("disable.structures")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableStructures = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableStructures = false;
|
||||
|
||||
@Value("disable.ores")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableOres = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableOres = false;
|
||||
|
||||
@Value("disable.trees")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableTrees = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableTrees = false;
|
||||
|
||||
@Value("disable.flora")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableFlora = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableFlora = false;
|
||||
|
||||
public boolean disableCarvers() {
|
||||
return disableCarvers.get();
|
||||
return disableCarvers;
|
||||
}
|
||||
|
||||
public boolean disableFlora() {
|
||||
return disableFlora.get();
|
||||
return disableFlora;
|
||||
}
|
||||
|
||||
public boolean disableOres() {
|
||||
return disableOres.get();
|
||||
return disableOres;
|
||||
}
|
||||
|
||||
public boolean disableStructures() {
|
||||
return disableStructures.get();
|
||||
return disableStructures;
|
||||
}
|
||||
|
||||
public boolean disableTrees() {
|
||||
return disableTrees.get();
|
||||
return disableTrees;
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, FunctionTemplate> getFunctions() {
|
||||
@@ -124,7 +122,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
}
|
||||
|
||||
public boolean isDisableSaplings() {
|
||||
return disableSaplings.get();
|
||||
return disableSaplings;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
@@ -136,19 +134,19 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
}
|
||||
|
||||
public boolean vanillaMobs() {
|
||||
return vanillaMobs.get();
|
||||
return vanillaMobs;
|
||||
}
|
||||
|
||||
public boolean vanillaCaves() {
|
||||
return vanillaCaves.get();
|
||||
return vanillaCaves;
|
||||
}
|
||||
|
||||
public boolean vanillaDecorations() {
|
||||
return vanillaDecorations.get();
|
||||
return vanillaDecorations;
|
||||
}
|
||||
|
||||
public boolean vanillaStructures() {
|
||||
return vanillaStructures.get();
|
||||
return vanillaStructures;
|
||||
}
|
||||
|
||||
public Map<String, NoiseSeeded> getNoiseBuilderMap() {
|
||||
@@ -164,7 +162,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
}
|
||||
|
||||
public Map<String, String> getLocatable() {
|
||||
return locatable.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get()));
|
||||
return locatable;
|
||||
}
|
||||
|
||||
public boolean doBetaCarvers() {
|
||||
|
||||
@@ -70,7 +70,7 @@ public class TerraWorld {
|
||||
double noise = sampler.sample(fdX, y, fdZ);
|
||||
if(noise > 0) {
|
||||
int level = 0;
|
||||
for(int yi = world.getMaxHeight()-1; yi > y; yi--) {
|
||||
for(int yi = world.getMaxHeight(); yi > y; yi--) {
|
||||
if(sampler.sample(fdX, yi, fdZ) > 0) level++;
|
||||
else level = 0;
|
||||
}
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
enable:
|
||||
- "Pokud se vám líbí Terra, můžete nás podpořit na Patreon!"
|
||||
- "Získáte přístup k experimentálním funkcím, než budou vydány!"
|
||||
- "Podpořit projekt můžete zde: https://www.patreon.com/dfsek"
|
||||
disable:
|
||||
- "Děkujeme, že používáte Terra!"
|
||||
command:
|
||||
debug-only: "Tento příkaz musí být použit se zapnutým debug modem!"
|
||||
player-only: "Tento příkaz je pouze pro hráče!"
|
||||
invalid: "Neznámý příkaz. (Očekáváno %1$s argumentů, nalezeno %2$s)."
|
||||
players-only: "Příkaz je pouze pro použití hráčem."
|
||||
world: "Tento příkaz musí být použit v Terra světě!"
|
||||
reload: "Obnoven Terra konfig."
|
||||
reload-error: "Nastaly chyby při obnově Terra konfigurace. Podívejte se do logů pro více informací."
|
||||
version: "Na tomto serveru běží Terra verze \"%1$s\", na platformě \"%2$s\""
|
||||
main-menu:
|
||||
- "--------------------Terra--------------------"
|
||||
- "reload - Obnoví konfigurační data"
|
||||
- "biome - Ukáže aktuální biom"
|
||||
- "ore - Generuje žílu rud v lokaci, ve směru kam se koukáte (Pro debugging)"
|
||||
- "save-data - Uložit populační data"
|
||||
- "structure - Nahrát a exportovat struktury"
|
||||
- "profile - Profiler možnosti"
|
||||
- "image - Obrázek/GUI možnosti"
|
||||
biome:
|
||||
biome-found: "Lokalizován biom na (%1$s, %2$s)"
|
||||
unable-to-locate: "Nelze lokalizovat biom."
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
invalid: "Nesprávné ID bomu: \"%s\""
|
||||
in: "Jste v \"%s\""
|
||||
packs:
|
||||
main: "Aktuální instalované konfigurační balíčky:"
|
||||
pack: " - %1$s v%3$s od %2$s"
|
||||
none: "Žádné konfigurační balíčky nejsou nainstalovány."
|
||||
ore:
|
||||
main-menu:
|
||||
- "---------------Terra/ore---------------"
|
||||
- "Generuje žílu rud na bloku, na který koukáte."
|
||||
out-of-range: "Blok mimo dosah"
|
||||
invalid-ore: "Nelze nalézt Rudu \"%s\""
|
||||
geometry:
|
||||
main-menu:
|
||||
- "---------------Terra/geometry----------------"
|
||||
- "Různé voxel geometrické debugging příkazy"
|
||||
- "sphere - Generuje kouli"
|
||||
- "deformsphere - Generuje deformovanou kouli"
|
||||
- "tube - Generuje válec"
|
||||
deform:
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
invalid-deform: "Nesprávná deformace: \"%s\""
|
||||
invalid-frequency: "Nesprávná frekvence: \"%s\""
|
||||
sphere:
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
tube:
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
image:
|
||||
main-menu:
|
||||
- "---------------Terra/image---------------"
|
||||
- "render - Vykreslí obrázek s danou šířkou a výškou, který může být později importován jako svět."
|
||||
- "gui - Otevřít debug GUI (Musí být zapnuto v konfigu)"
|
||||
gui:
|
||||
main-menu:
|
||||
- "-------------Terra/image/gui-------------"
|
||||
- "raw - Otevře GUI s raw Biom daty"
|
||||
- "step - Znovu vykreslí data k lepšímu zobrazení borderu"
|
||||
debug: "Debug mod musí být zapnutý pro použití této možnosti! Debug GUI NENÍ PRODUKČNĚ BEZPEČNÉ!"
|
||||
render:
|
||||
save: "Uložen obrázek jako \"%s\""
|
||||
error: "Nastala chyba při generování obrázku!"
|
||||
profile:
|
||||
main-menu:
|
||||
- "---------------Terra/profile---------------"
|
||||
- "start - Zapne profiler"
|
||||
- "stop - Vypne profiler"
|
||||
- "query - Ukáže profiler data"
|
||||
- "reset - Resetuje profiler data"
|
||||
reset: "Profiler byl resetován."
|
||||
start: "Profiler byl zapnut."
|
||||
stop: "Profiler byl vypnut."
|
||||
structure:
|
||||
main-menu:
|
||||
- "---------------Terra/structure---------------"
|
||||
- "export - Export vašeho výběru WorldEdit jako Terra struktura."
|
||||
- "load - Načíst Terra strukturu"
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
invalid-rotation: "Nesprávná rotace: \"%s\""
|
||||
invalid: "Nesprávné ID struktury: \"%s\""
|
||||
export: "Uložena struktura do \"%s\""
|
||||
world-config:
|
||||
load: "Načteny konfigurační hodnoty světa pro svět \"%s\"..."
|
||||
not-found: "Konfigurace pro svět \"%s\" nenalezena. Kopíruji defaultní konfig."
|
||||
using-image: "Načítám svět z obrázku."
|
||||
error: "Nelze načíst konfigurace pro svět %s"
|
||||
done: "Načítání světa \"%1$s\" dokončeno. Uplynulý čas: %2$sms"
|
||||
config-pack:
|
||||
loaded: "Konfigurační balíček %1$s v%4$s od %3$s byl načten za %2$sms."
|
||||
config:
|
||||
loaded: "Načten %1$s ze souboru %2$s"
|
||||
loaded-all: "Načteno %1$s %2$s(s) za %3$sms."
|
||||
error:
|
||||
invalid-failover: "Nesprávný typ failover: \"%s\""
|
||||
duplicate: "Duplikační ID nalezeno v souboru: %s"
|
||||
file:
|
||||
- "Konfigurační chyba pro Terra objekt. Soubor: %1$s"
|
||||
- "%2$s"
|
||||
- "Opravte jej před pokračováním!"
|
||||
generic:
|
||||
- "Nastala chyba při načítání konfigurace."
|
||||
- "Prosíme nahlašte to na Terra."
|
||||
warning:
|
||||
no-population: "Žádné populační chunky nebyly načteny. Pokud je to poprvé, co zapínáte server s Terra, či vytváříte nový svět, je tohle normální."
|
||||
error:
|
||||
severe-config: "Vážná konfigurační chyba zabránila Terra ze správné generace terénu na koordinátech: %1$s, %2$s. Prosíme zkontrolujte konfiguraci pro chyby. Jakékoli konfigurační chyby jsou vypsány výše."
|
||||
debug:
|
||||
data-save : "Uložena populační data."
|
||||
use-paper:
|
||||
- "Vypadá to, že používáte Spigot/CraftBukkit."
|
||||
- "Ačkoli Terra &ofunguje&r na Spigot, některé funkce budou ztraceny. (Terra je netestována na CraftBukkit; žádná podpora nebude dána pro CraftBukkit)."
|
||||
- "Pro nejvíce funkcí s Terra, použijte Paper."
|
||||
- "Navíc, Paper přináší obrovské výkonnostní zlepešení než Spigot, a všechny Spigot pluginy by měli fungovat s Paper!"
|
||||
- "Pro nejlepší zážitek s Terra a všemi pluginy, použijte prosím Paper."
|
||||
- "Více info najdete na stránce Paperu: https://papermc.io/"
|
||||
@@ -36,14 +36,11 @@ public class ParserTest {
|
||||
|
||||
@Override
|
||||
public Returnable.ReturnType getArgument(int position) {
|
||||
switch(position) {
|
||||
case 0:
|
||||
return Returnable.ReturnType.STRING;
|
||||
case 1:
|
||||
return Returnable.ReturnType.NUMBER;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch(position) {
|
||||
case 0 -> Returnable.ReturnType.STRING;
|
||||
case 1 -> Returnable.ReturnType.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class BukkitPlugin implements Mod {
|
||||
private final Plugin plugin;
|
||||
|
||||
public BukkitPlugin(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return plugin.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return plugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return plugin.getName();
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import com.dfsek.terra.api.event.TerraEventManager;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
import com.dfsek.terra.api.platform.world.Biome;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
@@ -58,12 +57,9 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
@@ -310,11 +306,6 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
genericLoaders.register(registry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Mod> getMods() {
|
||||
return Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(BukkitPlugin::new).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockedRegistry<TerraAddon> getAddons() {
|
||||
return addonLockedRegistry;
|
||||
|
||||
@@ -50,20 +50,13 @@ public final class BukkitAdapter {
|
||||
|
||||
|
||||
public static Stairs.Shape adapt(org.bukkit.block.data.type.Stairs.Shape shape) {
|
||||
switch(shape) {
|
||||
case STRAIGHT:
|
||||
return Stairs.Shape.STRAIGHT;
|
||||
case INNER_LEFT:
|
||||
return Stairs.Shape.INNER_LEFT;
|
||||
case OUTER_LEFT:
|
||||
return Stairs.Shape.OUTER_LEFT;
|
||||
case INNER_RIGHT:
|
||||
return Stairs.Shape.INNER_RIGHT;
|
||||
case OUTER_RIGHT:
|
||||
return Stairs.Shape.OUTER_RIGHT;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(shape) {
|
||||
case STRAIGHT -> Stairs.Shape.STRAIGHT;
|
||||
case INNER_LEFT -> Stairs.Shape.INNER_LEFT;
|
||||
case OUTER_LEFT -> Stairs.Shape.OUTER_LEFT;
|
||||
case INNER_RIGHT -> Stairs.Shape.INNER_RIGHT;
|
||||
case OUTER_RIGHT -> Stairs.Shape.OUTER_RIGHT;
|
||||
};
|
||||
}
|
||||
|
||||
public static BlockData adapt(org.bukkit.block.data.BlockData data) {
|
||||
@@ -75,265 +68,154 @@ public final class BukkitAdapter {
|
||||
}
|
||||
|
||||
public static Axis adapt(org.bukkit.Axis axis) {
|
||||
switch(axis) {
|
||||
case X:
|
||||
return Axis.X;
|
||||
case Y:
|
||||
return Axis.Y;
|
||||
case Z:
|
||||
return Axis.Z;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(axis) {
|
||||
case X -> Axis.X;
|
||||
case Y -> Axis.Y;
|
||||
case Z -> Axis.Z;
|
||||
};
|
||||
}
|
||||
|
||||
public static Bisected.Half adapt(org.bukkit.block.data.Bisected.Half half) {
|
||||
switch(half) {
|
||||
case BOTTOM:
|
||||
return Bisected.Half.BOTTOM;
|
||||
case TOP:
|
||||
return Bisected.Half.TOP;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(half) {
|
||||
case BOTTOM -> Bisected.Half.BOTTOM;
|
||||
case TOP -> Bisected.Half.TOP;
|
||||
};
|
||||
}
|
||||
|
||||
public static BlockFace adapt(org.bukkit.block.BlockFace face) {
|
||||
switch(face) {
|
||||
case DOWN:
|
||||
return BlockFace.DOWN;
|
||||
case UP:
|
||||
return BlockFace.UP;
|
||||
case NORTH_WEST:
|
||||
return BlockFace.NORTH_WEST;
|
||||
case NORTH_EAST:
|
||||
return BlockFace.NORTH_EAST;
|
||||
case SOUTH_EAST:
|
||||
return BlockFace.SOUTH_EAST;
|
||||
case SOUTH_WEST:
|
||||
return BlockFace.SOUTH_WEST;
|
||||
case NORTH_NORTH_WEST:
|
||||
return BlockFace.NORTH_NORTH_WEST;
|
||||
case WEST_NORTH_WEST:
|
||||
return BlockFace.WEST_NORTH_WEST;
|
||||
case WEST_SOUTH_WEST:
|
||||
return BlockFace.WEST_SOUTH_WEST;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return BlockFace.SOUTH_SOUTH_WEST;
|
||||
case EAST_NORTH_EAST:
|
||||
return BlockFace.EAST_NORTH_EAST;
|
||||
case WEST:
|
||||
return BlockFace.WEST;
|
||||
case SOUTH:
|
||||
return BlockFace.SOUTH;
|
||||
case EAST:
|
||||
return BlockFace.EAST;
|
||||
case NORTH:
|
||||
return BlockFace.NORTH;
|
||||
case SELF:
|
||||
return BlockFace.SELF;
|
||||
case EAST_SOUTH_EAST:
|
||||
return BlockFace.EAST_SOUTH_EAST;
|
||||
case NORTH_NORTH_EAST:
|
||||
return BlockFace.NORTH_NORTH_EAST;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return BlockFace.SOUTH_SOUTH_EAST;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(face) {
|
||||
case DOWN -> BlockFace.DOWN;
|
||||
case UP -> BlockFace.UP;
|
||||
case NORTH_WEST -> BlockFace.NORTH_WEST;
|
||||
case NORTH_EAST -> BlockFace.NORTH_EAST;
|
||||
case SOUTH_EAST -> BlockFace.SOUTH_EAST;
|
||||
case SOUTH_WEST -> BlockFace.SOUTH_WEST;
|
||||
case NORTH_NORTH_WEST -> BlockFace.NORTH_NORTH_WEST;
|
||||
case WEST_NORTH_WEST -> BlockFace.WEST_NORTH_WEST;
|
||||
case WEST_SOUTH_WEST -> BlockFace.WEST_SOUTH_WEST;
|
||||
case SOUTH_SOUTH_WEST -> BlockFace.SOUTH_SOUTH_WEST;
|
||||
case EAST_NORTH_EAST -> BlockFace.EAST_NORTH_EAST;
|
||||
case WEST -> BlockFace.WEST;
|
||||
case SOUTH -> BlockFace.SOUTH;
|
||||
case EAST -> BlockFace.EAST;
|
||||
case NORTH -> BlockFace.NORTH;
|
||||
case SELF -> BlockFace.SELF;
|
||||
case EAST_SOUTH_EAST -> BlockFace.EAST_SOUTH_EAST;
|
||||
case NORTH_NORTH_EAST -> BlockFace.NORTH_NORTH_EAST;
|
||||
case SOUTH_SOUTH_EAST -> BlockFace.SOUTH_SOUTH_EAST;
|
||||
};
|
||||
}
|
||||
|
||||
public static Slab.Type adapt(org.bukkit.block.data.type.Slab.Type type) {
|
||||
switch(type) {
|
||||
case BOTTOM:
|
||||
return Slab.Type.BOTTOM;
|
||||
case TOP:
|
||||
return Slab.Type.TOP;
|
||||
case DOUBLE:
|
||||
return Slab.Type.DOUBLE;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(type) {
|
||||
case BOTTOM -> Slab.Type.BOTTOM;
|
||||
case TOP -> Slab.Type.TOP;
|
||||
case DOUBLE -> Slab.Type.DOUBLE;
|
||||
};
|
||||
}
|
||||
|
||||
public static RedstoneWire.Connection adapt(org.bukkit.block.data.type.RedstoneWire.Connection connection) {
|
||||
switch(connection) {
|
||||
case NONE:
|
||||
return RedstoneWire.Connection.NONE;
|
||||
case UP:
|
||||
return RedstoneWire.Connection.UP;
|
||||
case SIDE:
|
||||
return RedstoneWire.Connection.SIDE;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(connection) {
|
||||
case NONE -> RedstoneWire.Connection.NONE;
|
||||
case UP -> RedstoneWire.Connection.UP;
|
||||
case SIDE -> RedstoneWire.Connection.SIDE;
|
||||
};
|
||||
}
|
||||
|
||||
public static org.bukkit.block.data.type.RedstoneWire.Connection adapt(RedstoneWire.Connection connection) {
|
||||
switch(connection) {
|
||||
case SIDE:
|
||||
return org.bukkit.block.data.type.RedstoneWire.Connection.SIDE;
|
||||
case UP:
|
||||
return org.bukkit.block.data.type.RedstoneWire.Connection.UP;
|
||||
case NONE:
|
||||
return org.bukkit.block.data.type.RedstoneWire.Connection.NONE;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(connection) {
|
||||
case SIDE -> org.bukkit.block.data.type.RedstoneWire.Connection.SIDE;
|
||||
case UP -> org.bukkit.block.data.type.RedstoneWire.Connection.UP;
|
||||
case NONE -> org.bukkit.block.data.type.RedstoneWire.Connection.NONE;
|
||||
};
|
||||
}
|
||||
|
||||
public static org.bukkit.block.data.type.Stairs.Shape adapt(Stairs.Shape shape) {
|
||||
switch(shape) {
|
||||
case STRAIGHT:
|
||||
return org.bukkit.block.data.type.Stairs.Shape.STRAIGHT;
|
||||
case INNER_LEFT:
|
||||
return org.bukkit.block.data.type.Stairs.Shape.INNER_LEFT;
|
||||
case OUTER_LEFT:
|
||||
return org.bukkit.block.data.type.Stairs.Shape.OUTER_LEFT;
|
||||
case INNER_RIGHT:
|
||||
return org.bukkit.block.data.type.Stairs.Shape.INNER_RIGHT;
|
||||
case OUTER_RIGHT:
|
||||
return org.bukkit.block.data.type.Stairs.Shape.OUTER_RIGHT;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(shape) {
|
||||
case STRAIGHT -> org.bukkit.block.data.type.Stairs.Shape.STRAIGHT;
|
||||
case INNER_LEFT -> org.bukkit.block.data.type.Stairs.Shape.INNER_LEFT;
|
||||
case OUTER_LEFT -> org.bukkit.block.data.type.Stairs.Shape.OUTER_LEFT;
|
||||
case INNER_RIGHT -> org.bukkit.block.data.type.Stairs.Shape.INNER_RIGHT;
|
||||
case OUTER_RIGHT -> org.bukkit.block.data.type.Stairs.Shape.OUTER_RIGHT;
|
||||
};
|
||||
}
|
||||
|
||||
public static Rail.Shape adapt(org.bukkit.block.data.Rail.Shape shape) {
|
||||
switch(shape) {
|
||||
case SOUTH_WEST:
|
||||
return Rail.Shape.SOUTH_WEST;
|
||||
case SOUTH_EAST:
|
||||
return Rail.Shape.SOUTH_EAST;
|
||||
case NORTH_EAST:
|
||||
return Rail.Shape.NORTH_EAST;
|
||||
case NORTH_WEST:
|
||||
return Rail.Shape.NORTH_WEST;
|
||||
case ASCENDING_EAST:
|
||||
return Rail.Shape.ASCENDING_EAST;
|
||||
case ASCENDING_WEST:
|
||||
return Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_SOUTH:
|
||||
return Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_NORTH:
|
||||
return Rail.Shape.ASCENDING_NORTH;
|
||||
case NORTH_SOUTH:
|
||||
return Rail.Shape.NORTH_SOUTH;
|
||||
case EAST_WEST:
|
||||
return Rail.Shape.EAST_WEST;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(shape) {
|
||||
case SOUTH_WEST -> Rail.Shape.SOUTH_WEST;
|
||||
case SOUTH_EAST -> Rail.Shape.SOUTH_EAST;
|
||||
case NORTH_EAST -> Rail.Shape.NORTH_EAST;
|
||||
case NORTH_WEST -> Rail.Shape.NORTH_WEST;
|
||||
case ASCENDING_EAST -> Rail.Shape.ASCENDING_EAST;
|
||||
case ASCENDING_WEST -> Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_SOUTH -> Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_NORTH -> Rail.Shape.ASCENDING_NORTH;
|
||||
case NORTH_SOUTH -> Rail.Shape.NORTH_SOUTH;
|
||||
case EAST_WEST -> Rail.Shape.EAST_WEST;
|
||||
};
|
||||
}
|
||||
|
||||
public static org.bukkit.block.data.Rail.Shape adapt(Rail.Shape shape) {
|
||||
switch(shape) {
|
||||
case EAST_WEST:
|
||||
return org.bukkit.block.data.Rail.Shape.EAST_WEST;
|
||||
case NORTH_SOUTH:
|
||||
return org.bukkit.block.data.Rail.Shape.NORTH_SOUTH;
|
||||
case ASCENDING_NORTH:
|
||||
return org.bukkit.block.data.Rail.Shape.ASCENDING_NORTH;
|
||||
case ASCENDING_SOUTH:
|
||||
return org.bukkit.block.data.Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_WEST:
|
||||
return org.bukkit.block.data.Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_EAST:
|
||||
return org.bukkit.block.data.Rail.Shape.ASCENDING_EAST;
|
||||
case NORTH_WEST:
|
||||
return org.bukkit.block.data.Rail.Shape.NORTH_WEST;
|
||||
case NORTH_EAST:
|
||||
return org.bukkit.block.data.Rail.Shape.NORTH_EAST;
|
||||
case SOUTH_EAST:
|
||||
return org.bukkit.block.data.Rail.Shape.SOUTH_EAST;
|
||||
case SOUTH_WEST:
|
||||
return org.bukkit.block.data.Rail.Shape.SOUTH_WEST;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(shape) {
|
||||
case EAST_WEST -> org.bukkit.block.data.Rail.Shape.EAST_WEST;
|
||||
case NORTH_SOUTH -> org.bukkit.block.data.Rail.Shape.NORTH_SOUTH;
|
||||
case ASCENDING_NORTH -> org.bukkit.block.data.Rail.Shape.ASCENDING_NORTH;
|
||||
case ASCENDING_SOUTH -> org.bukkit.block.data.Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_WEST -> org.bukkit.block.data.Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_EAST -> org.bukkit.block.data.Rail.Shape.ASCENDING_EAST;
|
||||
case NORTH_WEST -> org.bukkit.block.data.Rail.Shape.NORTH_WEST;
|
||||
case NORTH_EAST -> org.bukkit.block.data.Rail.Shape.NORTH_EAST;
|
||||
case SOUTH_EAST -> org.bukkit.block.data.Rail.Shape.SOUTH_EAST;
|
||||
case SOUTH_WEST -> org.bukkit.block.data.Rail.Shape.SOUTH_WEST;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static org.bukkit.block.data.Bisected.Half adapt(Bisected.Half half) {
|
||||
switch(half) {
|
||||
case TOP:
|
||||
return org.bukkit.block.data.Bisected.Half.TOP;
|
||||
case BOTTOM:
|
||||
return org.bukkit.block.data.Bisected.Half.BOTTOM;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(half) {
|
||||
case TOP -> org.bukkit.block.data.Bisected.Half.TOP;
|
||||
case BOTTOM -> org.bukkit.block.data.Bisected.Half.BOTTOM;
|
||||
};
|
||||
}
|
||||
|
||||
public static org.bukkit.Axis adapt(Axis axis) {
|
||||
switch(axis) {
|
||||
case Z:
|
||||
return org.bukkit.Axis.Z;
|
||||
case Y:
|
||||
return org.bukkit.Axis.Y;
|
||||
case X:
|
||||
return org.bukkit.Axis.X;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(axis) {
|
||||
case Z -> org.bukkit.Axis.Z;
|
||||
case Y -> org.bukkit.Axis.Y;
|
||||
case X -> org.bukkit.Axis.X;
|
||||
};
|
||||
}
|
||||
|
||||
public static org.bukkit.block.BlockFace adapt(BlockFace face) {
|
||||
switch(face) {
|
||||
case DOWN:
|
||||
return org.bukkit.block.BlockFace.DOWN;
|
||||
case UP:
|
||||
return org.bukkit.block.BlockFace.UP;
|
||||
case NORTH_WEST:
|
||||
return org.bukkit.block.BlockFace.NORTH_WEST;
|
||||
case NORTH_EAST:
|
||||
return org.bukkit.block.BlockFace.NORTH_EAST;
|
||||
case SOUTH_EAST:
|
||||
return org.bukkit.block.BlockFace.SOUTH_EAST;
|
||||
case SOUTH_WEST:
|
||||
return org.bukkit.block.BlockFace.SOUTH_WEST;
|
||||
case NORTH_NORTH_WEST:
|
||||
return org.bukkit.block.BlockFace.NORTH_NORTH_WEST;
|
||||
case WEST_NORTH_WEST:
|
||||
return org.bukkit.block.BlockFace.WEST_NORTH_WEST;
|
||||
case WEST_SOUTH_WEST:
|
||||
return org.bukkit.block.BlockFace.WEST_SOUTH_WEST;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return org.bukkit.block.BlockFace.SOUTH_SOUTH_WEST;
|
||||
case EAST_NORTH_EAST:
|
||||
return org.bukkit.block.BlockFace.EAST_NORTH_EAST;
|
||||
case WEST:
|
||||
return org.bukkit.block.BlockFace.WEST;
|
||||
case SOUTH:
|
||||
return org.bukkit.block.BlockFace.SOUTH;
|
||||
case EAST:
|
||||
return org.bukkit.block.BlockFace.EAST;
|
||||
case NORTH:
|
||||
return org.bukkit.block.BlockFace.NORTH;
|
||||
case SELF:
|
||||
return org.bukkit.block.BlockFace.SELF;
|
||||
case EAST_SOUTH_EAST:
|
||||
return org.bukkit.block.BlockFace.EAST_SOUTH_EAST;
|
||||
case NORTH_NORTH_EAST:
|
||||
return org.bukkit.block.BlockFace.NORTH_NORTH_EAST;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return org.bukkit.block.BlockFace.SOUTH_SOUTH_EAST;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(face) {
|
||||
case DOWN -> org.bukkit.block.BlockFace.DOWN;
|
||||
case UP -> org.bukkit.block.BlockFace.UP;
|
||||
case NORTH_WEST -> org.bukkit.block.BlockFace.NORTH_WEST;
|
||||
case NORTH_EAST -> org.bukkit.block.BlockFace.NORTH_EAST;
|
||||
case SOUTH_EAST -> org.bukkit.block.BlockFace.SOUTH_EAST;
|
||||
case SOUTH_WEST -> org.bukkit.block.BlockFace.SOUTH_WEST;
|
||||
case NORTH_NORTH_WEST -> org.bukkit.block.BlockFace.NORTH_NORTH_WEST;
|
||||
case WEST_NORTH_WEST -> org.bukkit.block.BlockFace.WEST_NORTH_WEST;
|
||||
case WEST_SOUTH_WEST -> org.bukkit.block.BlockFace.WEST_SOUTH_WEST;
|
||||
case SOUTH_SOUTH_WEST -> org.bukkit.block.BlockFace.SOUTH_SOUTH_WEST;
|
||||
case EAST_NORTH_EAST -> org.bukkit.block.BlockFace.EAST_NORTH_EAST;
|
||||
case WEST -> org.bukkit.block.BlockFace.WEST;
|
||||
case SOUTH -> org.bukkit.block.BlockFace.SOUTH;
|
||||
case EAST -> org.bukkit.block.BlockFace.EAST;
|
||||
case NORTH -> org.bukkit.block.BlockFace.NORTH;
|
||||
case SELF -> org.bukkit.block.BlockFace.SELF;
|
||||
case EAST_SOUTH_EAST -> org.bukkit.block.BlockFace.EAST_SOUTH_EAST;
|
||||
case NORTH_NORTH_EAST -> org.bukkit.block.BlockFace.NORTH_NORTH_EAST;
|
||||
case SOUTH_SOUTH_EAST -> org.bukkit.block.BlockFace.SOUTH_SOUTH_EAST;
|
||||
};
|
||||
}
|
||||
|
||||
public static org.bukkit.block.data.type.Slab.Type adapt(Slab.Type type) {
|
||||
switch(type) {
|
||||
case TOP:
|
||||
return org.bukkit.block.data.type.Slab.Type.TOP;
|
||||
case DOUBLE:
|
||||
return org.bukkit.block.data.type.Slab.Type.DOUBLE;
|
||||
case BOTTOM:
|
||||
return org.bukkit.block.data.type.Slab.Type.BOTTOM;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(type) {
|
||||
case TOP -> org.bukkit.block.data.type.Slab.Type.TOP;
|
||||
case DOUBLE -> org.bukkit.block.data.type.Slab.Type.DOUBLE;
|
||||
case BOTTOM -> org.bukkit.block.data.type.Slab.Type.BOTTOM;
|
||||
};
|
||||
}
|
||||
|
||||
public static Location adapt(com.dfsek.terra.api.math.vector.Location location) {
|
||||
|
||||
@@ -24,21 +24,15 @@ public class BukkitTree implements Tree {
|
||||
|
||||
private MaterialSet getSpawnable(TreeType type) {
|
||||
WorldHandle handle = main.getWorldHandle();
|
||||
switch(type) {
|
||||
case CRIMSON_FUNGUS:
|
||||
return MaterialSet.get(handle.createBlockData("minecraft:crimson_nylium"));
|
||||
case WARPED_FUNGUS:
|
||||
return MaterialSet.get(handle.createBlockData("minecraft:warped_nylium"));
|
||||
case BROWN_MUSHROOM:
|
||||
case RED_MUSHROOM:
|
||||
return MaterialSet.get(handle.createBlockData("minecraft:mycelium"), handle.createBlockData("minecraft:grass_block"),
|
||||
handle.createBlockData("minecraft:podzol"));
|
||||
case CHORUS_PLANT:
|
||||
return MaterialSet.get(handle.createBlockData("minecraft:end_stone"));
|
||||
default:
|
||||
return MaterialSet.get(handle.createBlockData("minecraft:grass_block"), handle.createBlockData("minecraft:dirt"),
|
||||
handle.createBlockData("minecraft:podzol"));
|
||||
}
|
||||
return switch(type) {
|
||||
case CRIMSON_FUNGUS -> MaterialSet.get(handle.createBlockData("minecraft:crimson_nylium"));
|
||||
case WARPED_FUNGUS -> MaterialSet.get(handle.createBlockData("minecraft:warped_nylium"));
|
||||
case BROWN_MUSHROOM, RED_MUSHROOM -> MaterialSet.get(handle.createBlockData("minecraft:mycelium"), handle.createBlockData("minecraft:grass_block"),
|
||||
handle.createBlockData("minecraft:podzol"));
|
||||
case CHORUS_PLANT -> MaterialSet.get(handle.createBlockData("minecraft:end_stone"));
|
||||
default -> MaterialSet.get(handle.createBlockData("minecraft:grass_block"), handle.createBlockData("minecraft:dirt"),
|
||||
handle.createBlockData("minecraft:podzol"));
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
-20
@@ -20,29 +20,19 @@ public class BukkitWall extends BukkitWaterlogged implements Wall {
|
||||
}
|
||||
|
||||
public static org.bukkit.block.data.type.Wall.Height adapt(com.dfsek.terra.api.platform.block.data.Wall.Height height) {
|
||||
switch(height) {
|
||||
case NONE:
|
||||
return org.bukkit.block.data.type.Wall.Height.NONE;
|
||||
case LOW:
|
||||
return org.bukkit.block.data.type.Wall.Height.LOW;
|
||||
case TALL:
|
||||
return org.bukkit.block.data.type.Wall.Height.TALL;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(height) {
|
||||
case NONE -> org.bukkit.block.data.type.Wall.Height.NONE;
|
||||
case LOW -> org.bukkit.block.data.type.Wall.Height.LOW;
|
||||
case TALL -> org.bukkit.block.data.type.Wall.Height.TALL;
|
||||
};
|
||||
}
|
||||
|
||||
public static com.dfsek.terra.api.platform.block.data.Wall.Height adapt(org.bukkit.block.data.type.Wall.Height height) {
|
||||
switch(height) {
|
||||
case TALL:
|
||||
return com.dfsek.terra.api.platform.block.data.Wall.Height.TALL;
|
||||
case LOW:
|
||||
return com.dfsek.terra.api.platform.block.data.Wall.Height.LOW;
|
||||
case NONE:
|
||||
return com.dfsek.terra.api.platform.block.data.Wall.Height.NONE;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(height) {
|
||||
case TALL -> Height.TALL;
|
||||
case LOW -> Height.LOW;
|
||||
case NONE -> Height.NONE;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
-26
@@ -96,32 +96,15 @@ public class BukkitMobSpawner extends BukkitBlockState implements MobSpawner {
|
||||
public void applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
switch(k) {
|
||||
case "type":
|
||||
setSpawnedType(new BukkitEntityType(org.bukkit.entity.EntityType.valueOf(v.toUpperCase())));
|
||||
return;
|
||||
case "delay":
|
||||
setDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "min_delay":
|
||||
setMinSpawnDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "max_delay":
|
||||
setMaxSpawnDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "spawn_count":
|
||||
setSpawnCount(Integer.parseInt(v));
|
||||
return;
|
||||
case "spawn_range":
|
||||
setSpawnRange(Integer.parseInt(v));
|
||||
return;
|
||||
case "max_nearby":
|
||||
setMaxNearbyEntities(Integer.parseInt(v));
|
||||
return;
|
||||
case "required_player_range":
|
||||
setRequiredPlayerRange(Integer.parseInt(v));
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid property: " + k);
|
||||
case "type" -> setSpawnedType(new BukkitEntityType(org.bukkit.entity.EntityType.valueOf(v.toUpperCase())));
|
||||
case "delay" -> setDelay(Integer.parseInt(v));
|
||||
case "min_delay" -> setMinSpawnDelay(Integer.parseInt(v));
|
||||
case "max_delay" -> setMaxSpawnDelay(Integer.parseInt(v));
|
||||
case "spawn_count" -> setSpawnCount(Integer.parseInt(v));
|
||||
case "spawn_range" -> setSpawnRange(Integer.parseInt(v));
|
||||
case "max_nearby" -> setMaxNearbyEntities(Integer.parseInt(v));
|
||||
case "required_player_range" -> setRequiredPlayerRange(Integer.parseInt(v));
|
||||
default -> throw new IllegalArgumentException("Invalid property: " + k);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ dependencies {
|
||||
"mappings"("net.fabricmc:yarn:1.16.5+build.5:v2")
|
||||
"modImplementation"("net.fabricmc:fabric-loader:0.11.2")
|
||||
|
||||
"modImplementation"("net.fabricmc.fabric-api:fabric-api:0.31.0+1.16")
|
||||
|
||||
"modCompileOnly"("com.sk89q.worldedit:worldedit-fabric-mc1.16:7.2.0-SNAPSHOT") {
|
||||
exclude(group = "com.google.guava", module = "guava")
|
||||
exclude(group = "com.google.code.gson", module = "gson")
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
|
||||
|
||||
public class FabricMod implements Mod {
|
||||
private final ModContainer mod;
|
||||
|
||||
public FabricMod(ModContainer mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return mod.getMetadata().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return mod.getMetadata().getVersion().getFriendlyString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return mod.getMetadata().getName();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
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.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addons.TerraAddon;
|
||||
@@ -12,135 +8,144 @@ import com.dfsek.terra.api.addons.annotations.Author;
|
||||
import com.dfsek.terra.api.addons.annotations.Version;
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
import com.dfsek.terra.api.command.TerraCommandManager;
|
||||
import com.dfsek.terra.api.command.exception.CommandException;
|
||||
import com.dfsek.terra.api.command.exception.MalformedCommandException;
|
||||
import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.TerraEventManager;
|
||||
import com.dfsek.terra.api.event.annotations.Global;
|
||||
import com.dfsek.terra.api.event.annotations.Priority;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.transform.NotNullValidator;
|
||||
import com.dfsek.terra.api.transform.Transformer;
|
||||
import com.dfsek.terra.api.transform.Validator;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.api.util.logging.Logger;
|
||||
import com.dfsek.terra.commands.CommandUtil;
|
||||
import com.dfsek.terra.config.GenericLoaders;
|
||||
import com.dfsek.terra.config.PluginConfig;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.lang.Language;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.generation.PopulatorFeature;
|
||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.handle.FabricItemHandle;
|
||||
import com.dfsek.terra.fabric.handle.FabricWorldHandle;
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
|
||||
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
|
||||
import com.dfsek.terra.profiler.Profiler;
|
||||
import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
import com.dfsek.terra.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.biome.BiomeEffects;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import net.minecraft.world.gen.decorator.Decorator;
|
||||
import net.minecraft.world.gen.decorator.NopeDecoratorConfig;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeatures;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.FeatureConfig;
|
||||
import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder;
|
||||
import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
|
||||
public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
private final org.apache.logging.log4j.Logger log4jLogger = LogManager.getLogger();
|
||||
|
||||
public static final PopulatorFeature POPULATOR_FEATURE = new PopulatorFeature(DefaultFeatureConfig.CODEC);
|
||||
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE));
|
||||
private static TerraFabricPlugin instance;
|
||||
private final Map<DimensionType, Pair<ServerWorld, TerraWorld>> worldMap = new HashMap<>();
|
||||
|
||||
public Map<DimensionType, Pair<ServerWorld, TerraWorld>> getWorldMap() {
|
||||
return worldMap;
|
||||
}
|
||||
|
||||
private final Map<Long, TerraWorld> worldMap = new HashMap<>();
|
||||
private final EventManager eventManager = new TerraEventManager(this);
|
||||
private final GenericLoaders genericLoaders = new GenericLoaders(this);
|
||||
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
|
||||
private final Logger logger = new Logger() {
|
||||
private final org.apache.logging.log4j.Logger logger = LogManager.getLogger();
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
log4jLogger.info(message);
|
||||
logger.info(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(String message) {
|
||||
log4jLogger.warn(message);
|
||||
logger.warn(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String message) {
|
||||
log4jLogger.error(message);
|
||||
logger.error(message);
|
||||
}
|
||||
};
|
||||
|
||||
private final DebugLogger debugLogger = new DebugLogger(logger);
|
||||
private final ItemHandle itemHandle = new FabricItemHandle();
|
||||
private final WorldHandle worldHandle = new FabricWorldHandle();
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final CheckedRegistry<ConfigPack> checkedRegistry = new CheckedRegistry<>(registry);
|
||||
|
||||
private final FabricAddon fabricAddon = new FabricAddon(this);
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(fabricAddon, this);
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(new FabricAddon(this), this);
|
||||
private final LockedRegistry<TerraAddon> addonLockedRegistry = new LockedRegistry<>(addonRegistry);
|
||||
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
|
||||
private final Transformer<String, Biome> biomeFixer = new Transformer.Builder<String, Biome>()
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), Validator.notNull())
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), Validator.notNull()).build();
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), new NotNullValidator<>())
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build();
|
||||
private File dataFolder;
|
||||
private final CommandManager manager = new TerraCommandManager(this);
|
||||
|
||||
public CommandManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
public static TerraFabricPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static String createBiomeID(ConfigPack pack, String biomeID) {
|
||||
return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldHandle getWorldHandle() {
|
||||
return worldHandle;
|
||||
@@ -148,12 +153,15 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
@Override
|
||||
public TerraWorld getWorld(World world) {
|
||||
return getWorld(((WorldAccess) world).getDimension());
|
||||
return worldMap.computeIfAbsent(world.getSeed(), w -> {
|
||||
logger.info("Loading world " + w);
|
||||
return new TerraWorld(world, ((FabricChunkGeneratorWrapper) world.getGenerator()).getPack(), this);
|
||||
});
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(DimensionType type) {
|
||||
TerraWorld world = worldMap.get(type).getRight();
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with dimension type " + type);
|
||||
public TerraWorld getWorld(long seed) {
|
||||
TerraWorld world = worldMap.get(seed);
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with seed " + seed);
|
||||
return world;
|
||||
}
|
||||
|
||||
@@ -174,7 +182,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return config.isDebug();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -197,11 +205,14 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
config.load(this);
|
||||
LangUtil.load(config.getLanguage(), this); // Load language.
|
||||
boolean succeed = registry.loadAll(this);
|
||||
worldMap.forEach((seed, pair) -> {
|
||||
pair.getRight().getConfig().getSamplerCache().clear();
|
||||
String packID = pair.getRight().getConfig().getTemplate().getID();
|
||||
pair.setRight(new TerraWorld(pair.getRight().getWorld(), registry.get(packID), this));
|
||||
Map<Long, TerraWorld> newMap = new HashMap<>();
|
||||
worldMap.forEach((seed, tw) -> {
|
||||
tw.getConfig().getSamplerCache().clear();
|
||||
String packID = tw.getConfig().getTemplate().getID();
|
||||
newMap.put(seed, new TerraWorld(tw.getWorld(), registry.get(packID), this));
|
||||
});
|
||||
worldMap.clear();
|
||||
worldMap.putAll(newMap);
|
||||
return succeed;
|
||||
}
|
||||
|
||||
@@ -235,19 +246,71 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
genericLoaders.register(registry);
|
||||
registry
|
||||
.registerLoader(BlockData.class, (t, o, l) -> worldHandle.createBlockData((String) o))
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> biomeFixer.translate((String) o))
|
||||
.registerLoader(Identifier.class, (t, o, l) -> {
|
||||
Identifier identifier = Identifier.tryParse((String) o);
|
||||
if(identifier == null) throw new LoadException("Invalid identifier: " + o);
|
||||
return identifier;
|
||||
});
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> biomeFixer.translate((String) o));
|
||||
}
|
||||
|
||||
private Biome createBiome(BiomeBuilder biome) {
|
||||
BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = template.getColors();
|
||||
|
||||
Biome vanilla = (Biome) (new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
|
||||
|
||||
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
|
||||
generationSettings.surfaceBuilder(SurfaceBuilder.DEFAULT.withConfig(new TernarySurfaceConfig(Blocks.GRASS_BLOCK.getDefaultState(), Blocks.DIRT.getDefaultState(), Blocks.GRAVEL.getDefaultState()))); // It needs a surfacebuilder, even though we dont use it.
|
||||
generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
|
||||
BiomeEffectsAccessor accessor = (BiomeEffectsAccessor) vanilla.getEffects();
|
||||
BiomeEffects.Builder effects = new BiomeEffects.Builder()
|
||||
.waterColor(colors.getOrDefault("water", accessor.getWaterColor()))
|
||||
.waterFogColor(colors.getOrDefault("water-fog", accessor.getWaterFogColor()))
|
||||
.fogColor(colors.getOrDefault("fog", accessor.getFogColor()))
|
||||
.skyColor(colors.getOrDefault("sky", accessor.getSkyColor()))
|
||||
.grassColorModifier(accessor.getGrassColorModifier());
|
||||
|
||||
if(colors.containsKey("grass")) {
|
||||
effects.grassColor(colors.get("grass"));
|
||||
} else {
|
||||
accessor.getGrassColor().ifPresent(effects::grassColor);
|
||||
}
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColor(colors.get("foliage"));
|
||||
} else {
|
||||
accessor.getFoliageColor().ifPresent(effects::foliageColor);
|
||||
}
|
||||
|
||||
return new Biome.Builder()
|
||||
.precipitation(vanilla.getPrecipitation())
|
||||
.category(vanilla.getCategory())
|
||||
.depth(vanilla.getDepth())
|
||||
.scale(vanilla.getScale())
|
||||
.temperature(vanilla.getTemperature())
|
||||
.downfall(vanilla.getDownfall())
|
||||
.effects(effects.build())
|
||||
.spawnSettings(vanilla.getSpawnSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public void packInit() {
|
||||
logger.info("Loading config packs...");
|
||||
registry.loadAll(this);
|
||||
|
||||
registry.forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> Registry.register(BuiltinRegistries.BIOME, new Identifier("terra", FabricUtil.createBiomeID(pack, id)), FabricUtil.createBiome(fabricAddon, biome, pack)))); // Register all Terra biomes.
|
||||
registry.forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> Registry.register(BuiltinRegistries.BIOME, new Identifier("terra", createBiomeID(pack, id)), createBiome(biome)))); // Register all Terra biomes.
|
||||
|
||||
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
registry.forEach(pack -> {
|
||||
final GeneratorType generatorType = new GeneratorType("terra." + pack.getTemplate().getID()) {
|
||||
@Override
|
||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||
}
|
||||
};
|
||||
//noinspection ConstantConditions
|
||||
((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID()));
|
||||
GeneratorTypeAccessor.getValues().add(generatorType);
|
||||
});
|
||||
}
|
||||
|
||||
logger.info("Loaded packs.");
|
||||
}
|
||||
@@ -259,7 +322,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
this.dataFolder = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra");
|
||||
saveDefaultConfig();
|
||||
config.load(this);
|
||||
debugLogger.setDebug(config.isDebug());
|
||||
LangUtil.load(config.getLanguage(), this);
|
||||
logger.info("Initializing Terra...");
|
||||
|
||||
@@ -269,33 +331,82 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
logger.info("Loaded addons.");
|
||||
|
||||
|
||||
Registry.register(Registry.FEATURE, new Identifier("terra", "populator"), POPULATOR_FEATURE);
|
||||
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("terra", "populator"));
|
||||
|
||||
Registry.register(Registry.FEATURE, new Identifier("terra", "flora_populator"), POPULATOR_FEATURE);
|
||||
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("terra", "flora_populator"));
|
||||
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, floraKey.getValue(), POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);
|
||||
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
|
||||
|
||||
CommandManager manager = new TerraCommandManager(this);
|
||||
try {
|
||||
CommandUtil.registerAll(manager);
|
||||
} catch(MalformedCommandException e) {
|
||||
e.printStackTrace(); // TODO do something here even though this should literally never happen
|
||||
}
|
||||
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
|
||||
int max = manager.getMaxArgumentDepth();
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
|
||||
for(int i = 0; i < max; i++) {
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
|
||||
|
||||
arg = next.then(assemble(arg, manager));
|
||||
}
|
||||
|
||||
dispatcher.register(literal("terra").executes(context -> 1).then(assemble(arg, manager)));
|
||||
dispatcher.register(literal("te").executes(context -> 1).then(assemble(arg, manager)));
|
||||
//dispatcher.register(literal("te").redirect(root));
|
||||
}
|
||||
);
|
||||
logger.info("Finished initialization.");
|
||||
}
|
||||
|
||||
private RequiredArgumentBuilder<ServerCommandSource, String> assemble(RequiredArgumentBuilder<ServerCommandSource, String> in, CommandManager manager) {
|
||||
return in.suggests((context, builder) -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
||||
} catch(CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}).executes(context -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.execute(args.remove(0), sender, args);
|
||||
} catch(CommandException e) {
|
||||
context.getSource().sendError(new LiteralText(e.getMessage()));
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
private List<String> parseCommand(String command) {
|
||||
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
|
||||
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
|
||||
List<String> c = new ArrayList<>(Arrays.asList(command.split(" ")));
|
||||
if(command.endsWith(" ")) c.add("");
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EventManager getEventManager() {
|
||||
return eventManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Mod> getMods() {
|
||||
return FabricLoader.getInstance().getAllMods().stream().map(FabricMod::new).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profiler getProfiler() {
|
||||
return profiler;
|
||||
@@ -304,19 +415,12 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
@Addon("Terra-Fabric")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public static final class FabricAddon extends TerraAddon implements EventListener {
|
||||
private static final class FabricAddon extends TerraAddon implements EventListener {
|
||||
|
||||
private final TerraPlugin main;
|
||||
|
||||
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
||||
|
||||
private final Map<ConfigPack, Configuration> compatConfigs = new HashMap<>();
|
||||
|
||||
private final ConfigLoader compatLoader = new ConfigLoader();
|
||||
|
||||
private FabricAddon(TerraPlugin main) {
|
||||
this.main = main;
|
||||
main.register(compatLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -347,56 +451,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
injectTree(treeRegistry, "MEGA_SPRUCE", ConfiguredFeatures.MEGA_SPRUCE);
|
||||
injectTree(treeRegistry, "CRIMSON_FUNGUS", ConfiguredFeatures.CRIMSON_FUNGI);
|
||||
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
||||
|
||||
Configuration compat;
|
||||
|
||||
try {
|
||||
compat = new Configuration(event.getLoader().get("compat.yml"));
|
||||
main.logger().info("Loading compatibility options from compat.yml.");
|
||||
} catch(FileNotFoundException e) {
|
||||
compat = new Configuration(new HashMap<>()); // blank config
|
||||
main.logger().info("No compat.yml found, not loading compatibility options.");
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException("Failed to load compatibility config", e); // Something went wrong.
|
||||
}
|
||||
|
||||
compatConfigs.put(event.getPack(), compat);
|
||||
|
||||
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
|
||||
|
||||
try {
|
||||
compatLoader.load(template, compat);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(template.doRegistryInjection()) {
|
||||
BuiltinRegistries.CONFIGURED_FEATURE.getEntries().forEach(entry -> {
|
||||
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getValue())) {
|
||||
try {
|
||||
event.getPack().getTreeRegistry().add(entry.getKey().getValue().toString(), (Tree) entry.getValue());
|
||||
main.getDebugLogger().info("Injected ConfiguredFeature " + entry.getKey().getValue() + " as Tree.");
|
||||
} catch(DuplicateEntryException ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
templates.put(event.getPack(), Pair.of(template, null));
|
||||
|
||||
}
|
||||
|
||||
@Priority(Priority.HIGHEST)
|
||||
@Global
|
||||
public void createInjectionOptions(ConfigPackPostLoadEvent event) {
|
||||
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
|
||||
|
||||
try {
|
||||
compatLoader.load(template, compatConfigs.get(event.getPack()));
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
templates.get(event.getPack()).setRight(template);
|
||||
}
|
||||
|
||||
|
||||
@@ -406,9 +460,5 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
} catch(DuplicateEntryException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-16
@@ -17,22 +17,14 @@ public class FabricDirectional extends FabricBlockData implements Directional {
|
||||
|
||||
@Override
|
||||
public BlockFace getFacing() {
|
||||
switch(delegate.get(property)) {
|
||||
case SOUTH:
|
||||
return BlockFace.SOUTH;
|
||||
case DOWN:
|
||||
return BlockFace.DOWN;
|
||||
case UP:
|
||||
return BlockFace.UP;
|
||||
case EAST:
|
||||
return BlockFace.EAST;
|
||||
case WEST:
|
||||
return BlockFace.WEST;
|
||||
case NORTH:
|
||||
return BlockFace.NORTH;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(delegate.get(property)) {
|
||||
case SOUTH -> BlockFace.SOUTH;
|
||||
case DOWN -> BlockFace.DOWN;
|
||||
case UP -> BlockFace.UP;
|
||||
case EAST -> BlockFace.EAST;
|
||||
case WEST -> BlockFace.WEST;
|
||||
case NORTH -> BlockFace.NORTH;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-18
@@ -29,24 +29,12 @@ public class FabricMultipleFacing extends FabricBlockData implements MultipleFac
|
||||
@Override
|
||||
public void setFace(BlockFace face, boolean facing) {
|
||||
switch(face) {
|
||||
case NORTH:
|
||||
delegate = delegate.with(Properties.NORTH, facing);
|
||||
break;
|
||||
case SOUTH:
|
||||
delegate = delegate.with(Properties.SOUTH, facing);
|
||||
break;
|
||||
case EAST:
|
||||
delegate = delegate.with(Properties.EAST, facing);
|
||||
break;
|
||||
case WEST:
|
||||
delegate = delegate.with(Properties.WEST, facing);
|
||||
break;
|
||||
case UP:
|
||||
delegate = delegate.with(Properties.UP, facing);
|
||||
break;
|
||||
case DOWN:
|
||||
delegate = delegate.with(Properties.DOWN, facing);
|
||||
break;
|
||||
case NORTH -> delegate = delegate.with(Properties.NORTH, facing);
|
||||
case SOUTH -> delegate = delegate.with(Properties.SOUTH, facing);
|
||||
case EAST -> delegate = delegate.with(Properties.EAST, facing);
|
||||
case WEST -> delegate = delegate.with(Properties.WEST, facing);
|
||||
case UP -> delegate = delegate.with(Properties.UP, facing);
|
||||
case DOWN -> delegate = delegate.with(Properties.DOWN, facing);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+36
-87
@@ -14,98 +14,47 @@ public class FabricRotatable extends FabricBlockData implements Rotatable {
|
||||
@Override
|
||||
public BlockFace getRotation() {
|
||||
int r = delegate.get(Properties.ROTATION);
|
||||
switch(r) {
|
||||
case 0:
|
||||
return BlockFace.SOUTH;
|
||||
case 1:
|
||||
return BlockFace.SOUTH_SOUTH_WEST;
|
||||
case 2:
|
||||
return BlockFace.SOUTH_WEST;
|
||||
case 3:
|
||||
return BlockFace.WEST_SOUTH_WEST;
|
||||
case 4:
|
||||
return BlockFace.WEST;
|
||||
case 5:
|
||||
return BlockFace.WEST_NORTH_WEST;
|
||||
case 6:
|
||||
return BlockFace.NORTH_WEST;
|
||||
case 7:
|
||||
return BlockFace.NORTH_NORTH_WEST;
|
||||
case 8:
|
||||
return BlockFace.NORTH;
|
||||
case 9:
|
||||
return BlockFace.NORTH_NORTH_EAST;
|
||||
case 10:
|
||||
return BlockFace.NORTH_EAST;
|
||||
case 11:
|
||||
return BlockFace.EAST_NORTH_EAST;
|
||||
case 12:
|
||||
return BlockFace.EAST;
|
||||
case 13:
|
||||
return BlockFace.EAST_SOUTH_EAST;
|
||||
case 14:
|
||||
return BlockFace.SOUTH_EAST;
|
||||
case 15:
|
||||
return BlockFace.SOUTH_SOUTH_EAST;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown rotation " + r);
|
||||
}
|
||||
return switch(r) {
|
||||
case 0 -> BlockFace.SOUTH;
|
||||
case 1 -> BlockFace.SOUTH_SOUTH_WEST;
|
||||
case 2 -> BlockFace.SOUTH_WEST;
|
||||
case 3 -> BlockFace.WEST_SOUTH_WEST;
|
||||
case 4 -> BlockFace.WEST;
|
||||
case 5 -> BlockFace.WEST_NORTH_WEST;
|
||||
case 6 -> BlockFace.NORTH_WEST;
|
||||
case 7 -> BlockFace.NORTH_NORTH_WEST;
|
||||
case 8 -> BlockFace.NORTH;
|
||||
case 9 -> BlockFace.NORTH_NORTH_EAST;
|
||||
case 10 -> BlockFace.NORTH_EAST;
|
||||
case 11 -> BlockFace.EAST_NORTH_EAST;
|
||||
case 12 -> BlockFace.EAST;
|
||||
case 13 -> BlockFace.EAST_SOUTH_EAST;
|
||||
case 14 -> BlockFace.SOUTH_EAST;
|
||||
case 15 -> BlockFace.SOUTH_SOUTH_EAST;
|
||||
default -> throw new IllegalArgumentException("Unknown rotation " + r);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(BlockFace face) {
|
||||
switch(face) {
|
||||
case UP:
|
||||
case DOWN:
|
||||
throw new IllegalArgumentException("Illegal rotation " + face);
|
||||
case SOUTH:
|
||||
delegate = delegate.with(Properties.ROTATION, 0);
|
||||
return;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
delegate = delegate.with(Properties.ROTATION, 1);
|
||||
return;
|
||||
case SOUTH_WEST:
|
||||
delegate = delegate.with(Properties.ROTATION, 2);
|
||||
return;
|
||||
case WEST_SOUTH_WEST:
|
||||
delegate = delegate.with(Properties.ROTATION, 3);
|
||||
return;
|
||||
case WEST:
|
||||
delegate = delegate.with(Properties.ROTATION, 4);
|
||||
return;
|
||||
case WEST_NORTH_WEST:
|
||||
delegate = delegate.with(Properties.ROTATION, 5);
|
||||
return;
|
||||
case NORTH_WEST:
|
||||
delegate = delegate.with(Properties.ROTATION, 6);
|
||||
return;
|
||||
case NORTH_NORTH_WEST:
|
||||
delegate = delegate.with(Properties.ROTATION, 7);
|
||||
return;
|
||||
case NORTH:
|
||||
delegate = delegate.with(Properties.ROTATION, 8);
|
||||
return;
|
||||
case NORTH_NORTH_EAST:
|
||||
delegate = delegate.with(Properties.ROTATION, 9);
|
||||
return;
|
||||
case NORTH_EAST:
|
||||
delegate = delegate.with(Properties.ROTATION, 10);
|
||||
return;
|
||||
case EAST_NORTH_EAST:
|
||||
delegate = delegate.with(Properties.ROTATION, 11);
|
||||
return;
|
||||
case EAST:
|
||||
delegate = delegate.with(Properties.ROTATION, 12);
|
||||
return;
|
||||
case EAST_SOUTH_EAST:
|
||||
delegate = delegate.with(Properties.ROTATION, 13);
|
||||
return;
|
||||
case SOUTH_EAST:
|
||||
delegate = delegate.with(Properties.ROTATION, 14);
|
||||
return;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
delegate = delegate.with(Properties.ROTATION, 15);
|
||||
return;
|
||||
case UP, DOWN -> throw new IllegalArgumentException("Illegal rotation " + face);
|
||||
case SOUTH -> delegate = delegate.with(Properties.ROTATION, 0);
|
||||
case SOUTH_SOUTH_WEST -> delegate = delegate.with(Properties.ROTATION, 1);
|
||||
case SOUTH_WEST -> delegate = delegate.with(Properties.ROTATION, 2);
|
||||
case WEST_SOUTH_WEST -> delegate = delegate.with(Properties.ROTATION, 3);
|
||||
case WEST -> delegate = delegate.with(Properties.ROTATION, 4);
|
||||
case WEST_NORTH_WEST -> delegate = delegate.with(Properties.ROTATION, 5);
|
||||
case NORTH_WEST -> delegate = delegate.with(Properties.ROTATION, 6);
|
||||
case NORTH_NORTH_WEST -> delegate = delegate.with(Properties.ROTATION, 7);
|
||||
case NORTH -> delegate = delegate.with(Properties.ROTATION, 8);
|
||||
case NORTH_NORTH_EAST -> delegate = delegate.with(Properties.ROTATION, 9);
|
||||
case NORTH_EAST -> delegate = delegate.with(Properties.ROTATION, 10);
|
||||
case EAST_NORTH_EAST -> delegate = delegate.with(Properties.ROTATION, 11);
|
||||
case EAST -> delegate = delegate.with(Properties.ROTATION, 12);
|
||||
case EAST_SOUTH_EAST -> delegate = delegate.with(Properties.ROTATION, 13);
|
||||
case SOUTH_EAST -> delegate = delegate.with(Properties.ROTATION, 14);
|
||||
case SOUTH_SOUTH_EAST -> delegate = delegate.with(Properties.ROTATION, 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.dfsek.terra.fabric.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PostLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("structures.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<Identifier>> excludedPerBiomeStructures = new HashMap<>();
|
||||
|
||||
@Value("features.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<Identifier>> excludedPerBiomeFeatures = new HashMap<>();
|
||||
|
||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeFeatures() {
|
||||
return excludedPerBiomeFeatures;
|
||||
}
|
||||
|
||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeStructures() {
|
||||
return excludedPerBiomeStructures;
|
||||
}
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package com.dfsek.terra.fabric.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PreLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("features.inject-registry.enable")
|
||||
@Default
|
||||
private boolean doRegistryInjection = false;
|
||||
|
||||
@Value("features.inject-namespaces")
|
||||
@Default
|
||||
private Set<String> featureNamespaces = new HashSet<>();
|
||||
|
||||
@Value("structures.inject-namespaces")
|
||||
@Default
|
||||
private Set<String> structureNamespaces = new HashSet<>();
|
||||
|
||||
@Value("features.inject-registry.excluded-features")
|
||||
@Default
|
||||
private Set<Identifier> excludedRegistryFeatures = new HashSet<>();
|
||||
|
||||
|
||||
public Set<String> getFeatureNamespaces() {
|
||||
return featureNamespaces;
|
||||
}
|
||||
|
||||
public Set<String> getStructureNamespaces() {
|
||||
return structureNamespaces;
|
||||
}
|
||||
|
||||
public boolean doRegistryInjection() {
|
||||
return doRegistryInjection;
|
||||
}
|
||||
|
||||
public Set<Identifier> getExcludedRegistryFeatures() {
|
||||
return excludedRegistryFeatures;
|
||||
}
|
||||
}
|
||||
+26
-70
@@ -4,12 +4,10 @@ import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkData;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
|
||||
@@ -20,7 +18,6 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.jafama.FastMath;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -30,14 +27,9 @@ import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.SpawnHelper;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.SpawnSettings;
|
||||
import net.minecraft.world.biome.source.BiomeAccess;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.ChunkRandom;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
@@ -46,7 +38,6 @@ import net.minecraft.world.gen.chunk.VerticalBlockSample;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -64,14 +55,13 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
PACK_CODEC.fieldOf("pack").stable().forGetter(generator -> generator.pack))
|
||||
.apply(instance, instance.stable(FabricChunkGeneratorWrapper::new)));
|
||||
private final ConfigPack pack;
|
||||
private DimensionType dimensionType;
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) {
|
||||
super(biomeSource, new StructuresConfig(configPack.getTemplate().vanillaStructures()));
|
||||
super(biomeSource, new StructuresConfig(false));
|
||||
this.pack = configPack;
|
||||
|
||||
this.delegate = new DefaultChunkGenerator3D(pack, TerraFabricPlugin.getInstance());
|
||||
@@ -97,31 +87,26 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
|
||||
}
|
||||
|
||||
public void setDimensionType(DimensionType dimensionType) {
|
||||
this.dimensionType = dimensionType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockPos locateStructure(ServerWorld world, StructureFeature<?> feature, BlockPos center, int radius, boolean skipExistingChunks) {
|
||||
if(!pack.getTemplate().disableStructures()) {
|
||||
String name = Objects.requireNonNull(Registry.STRUCTURE_FEATURE.getId(feature)).toString();
|
||||
TerraWorld terraWorld = TerraFabricPlugin.getInstance().getWorld((World) world);
|
||||
TerraStructure located = pack.getStructure(pack.getTemplate().getLocatable().get(name));
|
||||
if(located != null) {
|
||||
CompletableFuture<BlockPos> result = new CompletableFuture<>();
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, FabricAdapter.adapt(center).toLocation((World) world), 0, 500, location -> {
|
||||
result.complete(FabricAdapter.adapt(location));
|
||||
}, TerraFabricPlugin.getInstance());
|
||||
finder.run(); // Do this synchronously.
|
||||
try {
|
||||
return result.get();
|
||||
} catch(InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
String name = Objects.requireNonNull(Registry.STRUCTURE_FEATURE.getId(feature)).toString();
|
||||
TerraWorld terraWorld = TerraFabricPlugin.getInstance().getWorld((World) world);
|
||||
TerraStructure located = pack.getStructure(pack.getTemplate().getLocatable().get(name));
|
||||
if(located != null) {
|
||||
CompletableFuture<BlockPos> result = new CompletableFuture<>();
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, FabricAdapter.adapt(center).toLocation((World) world), 0, 500, location -> {
|
||||
result.complete(FabricAdapter.adapt(location));
|
||||
}, TerraFabricPlugin.getInstance());
|
||||
finder.run(); // Do this synchronously.
|
||||
try {
|
||||
return result.get();
|
||||
} catch(InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return super.locateStructure(world, feature, center, radius, skipExistingChunks);
|
||||
TerraFabricPlugin.getInstance().logger().warning("No overrides are defined for \"" + name + "\"");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,28 +127,32 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
|
||||
@Override
|
||||
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
|
||||
if(pack.getTemplate().vanillaStructures()) return super.isStrongholdStartingChunk(chunkPos);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight(int x, int z, Heightmap.Type heightmapType) {
|
||||
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
|
||||
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(seed);
|
||||
Sampler sampler = world.getConfig().getSamplerCache().getChunk(FastMath.floorDiv(x, 16), FastMath.floorDiv(z, 16));
|
||||
int cx = FastMath.floorMod(x, 16);
|
||||
int cz = FastMath.floorMod(z, 16);
|
||||
|
||||
int height = world.getWorld().getMaxHeight();
|
||||
while(height >= 0 && !heightmapType.getBlockPredicate().test(((FabricBlockData) world.getUngeneratedBlock(x, height - 1, z)).getHandle())) {
|
||||
|
||||
while (height >= 0 && sampler.sample(cx, height - 1, cz) < 0) {
|
||||
height--;
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockView getColumnSample(int x, int z) {
|
||||
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
|
||||
int height = getHeight(x, z, Heightmap.Type.WORLD_SURFACE);
|
||||
int height = 64; // TODO: implementation
|
||||
BlockState[] array = new BlockState[256];
|
||||
for(int y = 255; y >= 0; y--) {
|
||||
if(y > height) {
|
||||
if(y > ((UserDefinedBiome) world.getBiomeProvider().getBiome(x, z)).getConfig().getSeaLevel()) {
|
||||
if(y > getSeaLevel()) {
|
||||
array[y] = Blocks.AIR.getDefaultState();
|
||||
} else {
|
||||
array[y] = Blocks.WATER.getDefaultState();
|
||||
@@ -176,39 +165,6 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
return new VerticalBlockSample(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SpawnSettings.SpawnEntry> getEntitySpawnList(Biome biome, StructureAccessor accessor, SpawnGroup group, BlockPos pos) {
|
||||
if(pack.getTemplate().vanillaStructures()) {
|
||||
if(accessor.getStructureAt(pos, true, StructureFeature.SWAMP_HUT).hasChildren()) {
|
||||
if(group == SpawnGroup.MONSTER) return StructureFeature.SWAMP_HUT.getMonsterSpawns();
|
||||
if(group == SpawnGroup.CREATURE) return StructureFeature.SWAMP_HUT.getCreatureSpawns();
|
||||
}
|
||||
|
||||
if(group == SpawnGroup.MONSTER) {
|
||||
if(accessor.getStructureAt(pos, false, StructureFeature.PILLAGER_OUTPOST).hasChildren()) {
|
||||
return StructureFeature.PILLAGER_OUTPOST.getMonsterSpawns();
|
||||
} else if(accessor.getStructureAt(pos, false, StructureFeature.MONUMENT).hasChildren()) {
|
||||
return StructureFeature.MONUMENT.getMonsterSpawns();
|
||||
} else if(accessor.getStructureAt(pos, true, StructureFeature.FORTRESS).hasChildren()) {
|
||||
return StructureFeature.FORTRESS.getMonsterSpawns();
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.getEntitySpawnList(biome, accessor, group, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateEntities(ChunkRegion region) {
|
||||
if(pack.getTemplate().vanillaMobs()) {
|
||||
int cx = region.getCenterChunkX();
|
||||
int cy = region.getCenterChunkZ();
|
||||
Biome biome = region.getBiome((new ChunkPos(cx, cy)).getStartPos());
|
||||
ChunkRandom chunkRandom = new ChunkRandom();
|
||||
chunkRandom.setPopulationSeed(region.getSeed(), cx << 4, cy << 4);
|
||||
SpawnHelper.populateEntities(region, biome, cx, cy, chunkRandom);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraChunkGenerator getHandle() {
|
||||
return delegate;
|
||||
|
||||
+11
-6
@@ -4,7 +4,6 @@ import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.util.Identifier;
|
||||
@@ -12,8 +11,8 @@ import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryLookupCodec;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TerraBiomeSource extends BiomeSource {
|
||||
@@ -32,9 +31,7 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public TerraBiomeSource(Registry<Biome> biomes, long seed, ConfigPack pack) {
|
||||
super(biomes.stream()
|
||||
.filter(biome -> Objects.requireNonNull(biomes.getId(biome)).getNamespace().equals("terra")) // Filter out non-Terra biomes.
|
||||
.collect(Collectors.toList()));
|
||||
super(biomes.stream().collect(Collectors.toList()));
|
||||
this.biomeRegistry = biomes;
|
||||
this.seed = seed;
|
||||
this.grid = pack.getBiomeProviderBuilder().build(seed);
|
||||
@@ -54,6 +51,14 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
@Override
|
||||
public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) {
|
||||
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(biomeX << 2, biomeZ << 2);
|
||||
return biomeRegistry.get(new Identifier("terra", FabricUtil.createBiomeID(pack, biome.getID())));
|
||||
return biomeRegistry.get(new Identifier("terra", TerraFabricPlugin.createBiomeID(pack, biome.getID())));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasStructureFeature(StructureFeature<?> feature) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.dfsek.terra.fabric.generation;
|
||||
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
|
||||
public class TerraGeneratorType extends GeneratorType {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public TerraGeneratorType(ConfigPack pack) {
|
||||
super("terra." + pack.getTemplate().getID());
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.dfsek.terra.fabric.mixin;
|
||||
|
||||
import com.dfsek.terra.api.command.exception.CommandException;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
@Mixin(CommandManager.class)
|
||||
public abstract class CommandManagerMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private CommandDispatcher<ServerCommandSource> dispatcher;
|
||||
|
||||
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;findAmbiguities(Lcom/mojang/brigadier/AmbiguityConsumer;)V", remap = false))
|
||||
private void injectTerraCommands(CommandManager.RegistrationEnvironment environment, CallbackInfo ci) {
|
||||
com.dfsek.terra.api.command.CommandManager manager = TerraFabricPlugin.getInstance().getManager();
|
||||
int max = manager.getMaxArgumentDepth();
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
|
||||
for(int i = 0; i < max; i++) {
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
|
||||
|
||||
arg = next.then(assemble(arg, manager));
|
||||
}
|
||||
|
||||
dispatcher.register(literal("terra").executes(context -> 1).then(assemble(arg, manager)));
|
||||
dispatcher.register(literal("te").executes(context -> 1).then(assemble(arg, manager)));
|
||||
}
|
||||
|
||||
private RequiredArgumentBuilder<ServerCommandSource, String> assemble(RequiredArgumentBuilder<ServerCommandSource, String> in, com.dfsek.terra.api.command.CommandManager manager) {
|
||||
return in.suggests((context, builder) -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
||||
} catch(CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}).executes(context -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.execute(args.remove(0), sender, args);
|
||||
} catch(CommandException e) {
|
||||
context.getSource().sendError(new LiteralText(e.getMessage()));
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
private List<String> parseCommand(String command) {
|
||||
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
|
||||
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
|
||||
List<String> c = new ArrayList<>(Arrays.asList(command.split(" ")));
|
||||
if(command.endsWith(" ")) c.add("");
|
||||
return c;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.dfsek.terra.fabric.mixin;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldGenerationProgressListener;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.Spawner;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.ServerWorldProperties;
|
||||
import net.minecraft.world.level.storage.LevelStorage;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
public abstract class ServerWorldMixin {
|
||||
@Inject(method = "<init>", at = @At(value = "RETURN"))
|
||||
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
|
||||
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
|
||||
TerraFabricPlugin.getInstance().getWorldMap().put(dimensionType, Pair.of((ServerWorld) (Object) this, new TerraWorld((com.dfsek.terra.api.platform.world.World) this, ((FabricChunkGeneratorWrapper) chunkGenerator).getPack(), TerraFabricPlugin.getInstance())));
|
||||
((FabricChunkGeneratorWrapper) chunkGenerator).setDimensionType(dimensionType);
|
||||
TerraFabricPlugin.getInstance().logger().info("Registered world " + this + " to dimension type " + dimensionType);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-26
@@ -87,32 +87,15 @@ public abstract class MobSpawnerBlockEntityMixin {
|
||||
public void terra$applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
switch(k) {
|
||||
case "type":
|
||||
terra$setSpawnedType(TerraFabricPlugin.getInstance().getWorldHandle().getEntity(v));
|
||||
return;
|
||||
case "delay":
|
||||
terra$setDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "min_delay":
|
||||
terra$setMinSpawnDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "max_delay":
|
||||
terra$setMaxSpawnDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "spawn_count":
|
||||
terra$setSpawnCount(Integer.parseInt(v));
|
||||
return;
|
||||
case "spawn_range":
|
||||
terra$setSpawnRange(Integer.parseInt(v));
|
||||
return;
|
||||
case "max_nearby":
|
||||
terra$setMaxNearbyEntities(Integer.parseInt(v));
|
||||
return;
|
||||
case "required_player_range":
|
||||
terra$setRequiredPlayerRange(Integer.parseInt(v));
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid property: " + k);
|
||||
case "type" -> terra$setSpawnedType(TerraFabricPlugin.getInstance().getWorldHandle().getEntity(v));
|
||||
case "delay" -> terra$setDelay(Integer.parseInt(v));
|
||||
case "min_delay" -> terra$setMinSpawnDelay(Integer.parseInt(v));
|
||||
case "max_delay" -> terra$setMaxSpawnDelay(Integer.parseInt(v));
|
||||
case "spawn_count" -> terra$setSpawnCount(Integer.parseInt(v));
|
||||
case "spawn_range" -> terra$setSpawnRange(Integer.parseInt(v));
|
||||
case "max_nearby" -> terra$setMaxNearbyEntities(Integer.parseInt(v));
|
||||
case "required_player_range" -> terra$setRequiredPlayerRange(Integer.parseInt(v));
|
||||
default -> throw new IllegalArgumentException("Invalid property: " + k);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
-10
@@ -1,12 +1,8 @@
|
||||
package com.dfsek.terra.fabric.mixin.init;
|
||||
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.generation.TerraGeneratorType;
|
||||
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.RunArgs;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -19,11 +15,5 @@ public class MinecraftClientMixin {
|
||||
shift = At.Shift.BEFORE))
|
||||
public void injectConstructor(RunArgs args, CallbackInfo callbackInfo) {
|
||||
TerraFabricPlugin.getInstance().packInit(); // Load during MinecraftClient construction, after other mods have registered blocks and stuff
|
||||
TerraFabricPlugin.getInstance().getConfigRegistry().forEach(pack -> {
|
||||
final GeneratorType generatorType = new TerraGeneratorType(pack);
|
||||
//noinspection ConstantConditions
|
||||
((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID()));
|
||||
GeneratorTypeAccessor.getValues().add(1, generatorType);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,22 +62,15 @@ public final class FabricAdapter {
|
||||
}
|
||||
|
||||
public static Direction adapt(BlockFace face) {
|
||||
switch(face) {
|
||||
case NORTH:
|
||||
return Direction.NORTH;
|
||||
case WEST:
|
||||
return Direction.WEST;
|
||||
case SOUTH:
|
||||
return Direction.SOUTH;
|
||||
case EAST:
|
||||
return Direction.EAST;
|
||||
case UP:
|
||||
return Direction.UP;
|
||||
case DOWN:
|
||||
return Direction.DOWN;
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal direction: " + face);
|
||||
}
|
||||
return switch(face) {
|
||||
case NORTH -> Direction.NORTH;
|
||||
case WEST -> Direction.WEST;
|
||||
case SOUTH -> Direction.SOUTH;
|
||||
case EAST -> Direction.EAST;
|
||||
case UP -> Direction.UP;
|
||||
case DOWN -> Direction.DOWN;
|
||||
default -> throw new IllegalArgumentException("Illegal direction: " + face);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -96,129 +89,79 @@ public final class FabricAdapter {
|
||||
}
|
||||
|
||||
public static Stairs.Shape adapt(StairShape shape) {
|
||||
switch(shape) {
|
||||
case OUTER_RIGHT:
|
||||
return Stairs.Shape.OUTER_RIGHT;
|
||||
case INNER_RIGHT:
|
||||
return Stairs.Shape.INNER_RIGHT;
|
||||
case OUTER_LEFT:
|
||||
return Stairs.Shape.OUTER_LEFT;
|
||||
case INNER_LEFT:
|
||||
return Stairs.Shape.INNER_LEFT;
|
||||
case STRAIGHT:
|
||||
return Stairs.Shape.STRAIGHT;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(shape) {
|
||||
case OUTER_RIGHT -> Stairs.Shape.OUTER_RIGHT;
|
||||
case INNER_RIGHT -> Stairs.Shape.INNER_RIGHT;
|
||||
case OUTER_LEFT -> Stairs.Shape.OUTER_LEFT;
|
||||
case INNER_LEFT -> Stairs.Shape.INNER_LEFT;
|
||||
case STRAIGHT -> Stairs.Shape.STRAIGHT;
|
||||
};
|
||||
}
|
||||
|
||||
public static Bisected.Half adapt(BlockHalf half) {
|
||||
switch(half) {
|
||||
case BOTTOM:
|
||||
return Bisected.Half.BOTTOM;
|
||||
case TOP:
|
||||
return Bisected.Half.TOP;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(half) {
|
||||
case BOTTOM -> Bisected.Half.BOTTOM;
|
||||
case TOP -> Bisected.Half.TOP;
|
||||
};
|
||||
}
|
||||
|
||||
public static BlockFace adapt(Direction direction) {
|
||||
switch(direction) {
|
||||
case DOWN:
|
||||
return BlockFace.DOWN;
|
||||
case UP:
|
||||
return BlockFace.UP;
|
||||
case WEST:
|
||||
return BlockFace.WEST;
|
||||
case EAST:
|
||||
return BlockFace.EAST;
|
||||
case NORTH:
|
||||
return BlockFace.NORTH;
|
||||
case SOUTH:
|
||||
return BlockFace.SOUTH;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(direction) {
|
||||
case DOWN -> BlockFace.DOWN;
|
||||
case UP -> BlockFace.UP;
|
||||
case WEST -> BlockFace.WEST;
|
||||
case EAST -> BlockFace.EAST;
|
||||
case NORTH -> BlockFace.NORTH;
|
||||
case SOUTH -> BlockFace.SOUTH;
|
||||
};
|
||||
}
|
||||
|
||||
public static Slab.Type adapt(SlabType type) {
|
||||
switch(type) {
|
||||
case BOTTOM:
|
||||
return Slab.Type.BOTTOM;
|
||||
case TOP:
|
||||
return Slab.Type.TOP;
|
||||
case DOUBLE:
|
||||
return Slab.Type.DOUBLE;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(type) {
|
||||
case BOTTOM -> Slab.Type.BOTTOM;
|
||||
case TOP -> Slab.Type.TOP;
|
||||
case DOUBLE -> Slab.Type.DOUBLE;
|
||||
};
|
||||
}
|
||||
|
||||
public static StairShape adapt(Stairs.Shape shape) {
|
||||
switch(shape) {
|
||||
case STRAIGHT:
|
||||
return StairShape.STRAIGHT;
|
||||
case INNER_LEFT:
|
||||
return StairShape.INNER_LEFT;
|
||||
case OUTER_LEFT:
|
||||
return StairShape.OUTER_LEFT;
|
||||
case INNER_RIGHT:
|
||||
return StairShape.INNER_RIGHT;
|
||||
case OUTER_RIGHT:
|
||||
return StairShape.OUTER_RIGHT;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(shape) {
|
||||
case STRAIGHT -> StairShape.STRAIGHT;
|
||||
case INNER_LEFT -> StairShape.INNER_LEFT;
|
||||
case OUTER_LEFT -> StairShape.OUTER_LEFT;
|
||||
case INNER_RIGHT -> StairShape.INNER_RIGHT;
|
||||
case OUTER_RIGHT -> StairShape.OUTER_RIGHT;
|
||||
};
|
||||
}
|
||||
|
||||
public static BlockHalf adapt(Bisected.Half half) {
|
||||
switch(half) {
|
||||
case TOP:
|
||||
return BlockHalf.TOP;
|
||||
case BOTTOM:
|
||||
return BlockHalf.BOTTOM;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(half) {
|
||||
case TOP -> BlockHalf.TOP;
|
||||
case BOTTOM -> BlockHalf.BOTTOM;
|
||||
};
|
||||
}
|
||||
|
||||
public static SlabType adapt(Slab.Type type) {
|
||||
switch(type) {
|
||||
case DOUBLE:
|
||||
return SlabType.DOUBLE;
|
||||
case TOP:
|
||||
return SlabType.TOP;
|
||||
case BOTTOM:
|
||||
return SlabType.BOTTOM;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(type) {
|
||||
case DOUBLE -> SlabType.DOUBLE;
|
||||
case TOP -> SlabType.TOP;
|
||||
case BOTTOM -> SlabType.BOTTOM;
|
||||
};
|
||||
}
|
||||
|
||||
public static Axis adapt(Direction.Axis axis) {
|
||||
switch(axis) {
|
||||
case X:
|
||||
return Axis.X;
|
||||
case Y:
|
||||
return Axis.Y;
|
||||
case Z:
|
||||
return Axis.Z;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(axis) {
|
||||
case X -> Axis.X;
|
||||
case Y -> Axis.Y;
|
||||
case Z -> Axis.Z;
|
||||
};
|
||||
}
|
||||
|
||||
public static Direction.Axis adapt(Axis axis) {
|
||||
switch(axis) {
|
||||
case Z:
|
||||
return Direction.Axis.Z;
|
||||
case Y:
|
||||
return Direction.Axis.Y;
|
||||
case X:
|
||||
return Direction.Axis.X;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(axis) {
|
||||
case Z -> Direction.Axis.Z;
|
||||
case Y -> Direction.Axis.Y;
|
||||
case X -> Direction.Axis.X;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
package com.dfsek.terra.fabric.util;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeEffects;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.carver.ConfiguredCarver;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.ConfiguredStructureFeature;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class FabricUtil {
|
||||
public static String createBiomeID(ConfigPack pack, String biomeID) {
|
||||
return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
|
||||
*
|
||||
* @param fabricAddon The Fabric addon instance.
|
||||
* @param biome The Terra BiomeBuilder.
|
||||
* @param pack The ConfigPack this biome belongs to.
|
||||
* @return The Minecraft delegate biome.
|
||||
*/
|
||||
public static Biome createBiome(TerraFabricPlugin.FabricAddon fabricAddon, BiomeBuilder biome, ConfigPack pack) {
|
||||
BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = template.getColors();
|
||||
|
||||
Biome vanilla = (Biome) (new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
|
||||
|
||||
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
|
||||
|
||||
generationSettings.surfaceBuilder(vanilla.getGenerationSettings().getSurfaceBuilder()); // It needs a surfacebuilder, even though we dont use it.
|
||||
|
||||
generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, TerraFabricPlugin.POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
if(pack.getTemplate().vanillaCaves()) {
|
||||
for(GenerationStep.Carver carver : GenerationStep.Carver.values()) {
|
||||
for(Supplier<ConfiguredCarver<?>> configuredCarverSupplier : vanilla.getGenerationSettings().getCarversForStep(carver)) {
|
||||
generationSettings.carver(carver, configuredCarverSupplier.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions> pair = fabricAddon.getTemplates().get(pack);
|
||||
PreLoadCompatibilityOptions compatibilityOptions = pair.getLeft();
|
||||
PostLoadCompatibilityOptions postLoadCompatibilityOptions = pair.getRight();
|
||||
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injecting Vanilla structures and features into Terra biome " + biome.getTemplate().getID());
|
||||
|
||||
for(Supplier<ConfiguredStructureFeature<?, ?>> structureFeature : vanilla.getGenerationSettings().getStructureFeatures()) {
|
||||
Identifier key = Objects.requireNonNull(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getId(structureFeature.get()));
|
||||
if(compatibilityOptions.getStructureNamespaces().contains(key.getNamespace()) && !postLoadCompatibilityOptions.getExcludedPerBiomeStructures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.structureFeature(structureFeature.get());
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected structure " + key);
|
||||
}
|
||||
}
|
||||
|
||||
for(int step = 0; step < vanilla.getGenerationSettings().getFeatures().size(); step++) {
|
||||
for(Supplier<ConfiguredFeature<?, ?>> featureSupplier : vanilla.getGenerationSettings().getFeatures().get(step)) {
|
||||
Identifier key = Objects.requireNonNull(BuiltinRegistries.CONFIGURED_FEATURE.getId(featureSupplier.get()));
|
||||
if(compatibilityOptions.getFeatureNamespaces().contains(key.getNamespace()) && !postLoadCompatibilityOptions.getExcludedPerBiomeFeatures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.feature(step, featureSupplier);
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected feature " + key + " at stage " + step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BiomeEffectsAccessor accessor = (BiomeEffectsAccessor) vanilla.getEffects();
|
||||
BiomeEffects.Builder effects = new BiomeEffects.Builder()
|
||||
.waterColor(colors.getOrDefault("water", accessor.getWaterColor()))
|
||||
.waterFogColor(colors.getOrDefault("water-fog", accessor.getWaterFogColor()))
|
||||
.fogColor(colors.getOrDefault("fog", accessor.getFogColor()))
|
||||
.skyColor(colors.getOrDefault("sky", accessor.getSkyColor()))
|
||||
.grassColorModifier(accessor.getGrassColorModifier());
|
||||
|
||||
if(colors.containsKey("grass")) {
|
||||
effects.grassColor(colors.get("grass"));
|
||||
} else {
|
||||
accessor.getGrassColor().ifPresent(effects::grassColor);
|
||||
}
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColor(colors.get("foliage"));
|
||||
} else {
|
||||
accessor.getFoliageColor().ifPresent(effects::foliageColor);
|
||||
}
|
||||
|
||||
return new Biome.Builder()
|
||||
.precipitation(vanilla.getPrecipitation())
|
||||
.category(vanilla.getCategory())
|
||||
.depth(vanilla.getDepth())
|
||||
.scale(vanilla.getScale())
|
||||
.temperature(vanilla.getTemperature())
|
||||
.downfall(vanilla.getDownfall())
|
||||
.effects(effects.build())
|
||||
.spawnSettings(vanilla.getSpawnSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
"accessWidener": "terra.accesswidener"
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
"package": "com.dfsek.terra.fabric.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"CommandManagerMixin",
|
||||
"GeneratorOptionsMixin",
|
||||
"ServerWorldMixin",
|
||||
"access.BiomeEffectsAccessor",
|
||||
"access.MobSpawnerLogicAccessor",
|
||||
"access.StateAccessor",
|
||||
|
||||
@@ -70,21 +70,14 @@ public final class ForgeAdapter {
|
||||
}
|
||||
|
||||
public static Direction adapt(BlockFace face) {
|
||||
switch(face) {
|
||||
case NORTH:
|
||||
return Direction.NORTH;
|
||||
case WEST:
|
||||
return Direction.WEST;
|
||||
case SOUTH:
|
||||
return Direction.SOUTH;
|
||||
case EAST:
|
||||
return Direction.EAST;
|
||||
case UP:
|
||||
return Direction.UP;
|
||||
case DOWN:
|
||||
return Direction.DOWN;
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal direction: " + face);
|
||||
}
|
||||
return switch(face) {
|
||||
case NORTH -> Direction.NORTH;
|
||||
case WEST -> Direction.WEST;
|
||||
case SOUTH -> Direction.SOUTH;
|
||||
case EAST -> Direction.EAST;
|
||||
case UP -> Direction.UP;
|
||||
case DOWN -> Direction.DOWN;
|
||||
default -> throw new IllegalArgumentException("Illegal direction: " + face);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||
|
||||
public class ForgeMod implements Mod {
|
||||
private final ModInfo mod;
|
||||
|
||||
public ForgeMod(ModInfo mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return mod.getModId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return mod.getVersion().getQualifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return mod.getDisplayName();
|
||||
}
|
||||
}
|
||||
@@ -1,78 +1,36 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.forge.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.config.PreLoadCompatibilityOptions;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.WorldGenRegistries;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeAmbience;
|
||||
import net.minecraft.world.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.gen.GenerationStage;
|
||||
import net.minecraft.world.gen.carver.ConfiguredCarver;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
|
||||
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilderConfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class ForgeUtil {
|
||||
public static String createBiomeID(ConfigPack pack, String biomeID) {
|
||||
return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public static Biome createBiome(BiomeBuilder biome, ConfigPack pack, TerraForgePlugin.ForgeAddon forgeAddon) {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public static Biome createBiome(BiomeBuilder biome) {
|
||||
BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = template.getColors();
|
||||
|
||||
Biome vanilla = (Biome) (new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
|
||||
Biome vanilla = (Biome) ((Object) new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0));
|
||||
|
||||
BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder();
|
||||
|
||||
generationSettings.surfaceBuilder(vanilla.getGenerationSettings().getSurfaceBuilder()); // It needs a surfacebuilder, even though we dont use it.
|
||||
|
||||
generationSettings.surfaceBuilder(SurfaceBuilder.DEFAULT.configured(new SurfaceBuilderConfig(Blocks.GRASS_BLOCK.defaultBlockState(), Blocks.DIRT.defaultBlockState(), Blocks.GRAVEL.defaultBlockState()))); // It needs a surfacebuilder, even though we dont use it.
|
||||
generationSettings.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, TerraForgePlugin.POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
if(pack.getTemplate().vanillaCaves()) {
|
||||
for(GenerationStage.Carving carver : GenerationStage.Carving.values()) {
|
||||
for(Supplier<ConfiguredCarver<?>> configuredCarverSupplier : vanilla.getGenerationSettings().getCarvers(carver)) {
|
||||
generationSettings.addCarver(carver, configuredCarverSupplier.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions> pair = forgeAddon.getTemplates().get(pack);
|
||||
PreLoadCompatibilityOptions compatibilityOptions = pair.getLeft();
|
||||
PostLoadCompatibilityOptions postLoadCompatibilityOptions = pair.getRight();
|
||||
|
||||
TerraForgePlugin.getInstance().getDebugLogger().info("Injecting Vanilla structures and features into Terra biome " + biome.getTemplate().getID());
|
||||
|
||||
for(Supplier<StructureFeature<?, ?>> structureFeature : vanilla.getGenerationSettings().structures()) {
|
||||
ResourceLocation key = WorldGenRegistries.CONFIGURED_STRUCTURE_FEATURE.getKey(structureFeature.get());
|
||||
if(!compatibilityOptions.getExcludedBiomeStructures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeStructures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.addStructureStart(structureFeature.get());
|
||||
TerraForgePlugin.getInstance().getDebugLogger().info("Injected structure " + key);
|
||||
}
|
||||
}
|
||||
|
||||
if(compatibilityOptions.doBiomeInjection()) {
|
||||
for(int step = 0; step < vanilla.getGenerationSettings().features().size(); step++) {
|
||||
for(Supplier<ConfiguredFeature<?, ?>> featureSupplier : vanilla.getGenerationSettings().features().get(step)) {
|
||||
ResourceLocation key = WorldGenRegistries.CONFIGURED_FEATURE.getKey(featureSupplier.get());
|
||||
if(!compatibilityOptions.getExcludedBiomeFeatures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeFeatures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.addFeature(step, featureSupplier);
|
||||
TerraForgePlugin.getInstance().getDebugLogger().info("Injected feature " + key + " at stage " + step);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BiomeAmbience vanillaEffects = vanilla.getSpecialEffects();
|
||||
BiomeAmbience.Builder effects = new BiomeAmbience.Builder()
|
||||
.waterColor(colors.getOrDefault("water", vanillaEffects.getWaterColor()))
|
||||
@@ -86,7 +44,7 @@ public final class ForgeUtil {
|
||||
} else {
|
||||
vanillaEffects.getGrassColorOverride().ifPresent(effects::grassColorOverride);
|
||||
}
|
||||
|
||||
vanillaEffects.getFoliageColorOverride().ifPresent(effects::foliageColorOverride);
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColorOverride(colors.get("foliage"));
|
||||
} else {
|
||||
@@ -103,7 +61,6 @@ public final class ForgeUtil {
|
||||
.specialEffects(effects.build())
|
||||
.mobSpawnSettings(vanilla.getMobSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build()
|
||||
.setRegistryName("terra", createBiomeID(template.getPack(), template.getID()));
|
||||
.build().setRegistryName("terra", createBiomeID(template.getPack(), template.getID()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addons.TerraAddon;
|
||||
@@ -16,7 +14,6 @@ import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.TerraEventManager;
|
||||
import com.dfsek.terra.api.event.annotations.Global;
|
||||
import com.dfsek.terra.api.event.annotations.Priority;
|
||||
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.handle.ItemHandle;
|
||||
@@ -25,10 +22,9 @@ import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.transform.NotNullValidator;
|
||||
import com.dfsek.terra.api.transform.Transformer;
|
||||
import com.dfsek.terra.api.transform.Validator;
|
||||
import com.dfsek.terra.api.util.JarUtil;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.commands.CommandUtil;
|
||||
import com.dfsek.terra.config.GenericLoaders;
|
||||
@@ -36,8 +32,6 @@ import com.dfsek.terra.config.PluginConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.lang.Language;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.forge.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.forge.generation.PopulatorFeature;
|
||||
import com.dfsek.terra.forge.generation.TerraBiomeSource;
|
||||
@@ -51,9 +45,6 @@ import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.WorldGenRegistries;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.Features;
|
||||
@@ -61,12 +52,10 @@ import net.minecraft.world.gen.feature.IFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.NoFeatureConfig;
|
||||
import net.minecraft.world.gen.placement.DecoratedPlacement;
|
||||
import net.minecraft.world.gen.placement.NoPlacementConfig;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.objectweb.asm.Type;
|
||||
@@ -79,9 +68,7 @@ import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
@Mod("terra")
|
||||
@@ -91,7 +78,7 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configured(IFeatureConfig.NONE).decorated(DecoratedPlacement.NOPE.configured(NoPlacementConfig.INSTANCE));
|
||||
|
||||
private static TerraForgePlugin INSTANCE;
|
||||
private final Map<DimensionType, Pair<ServerWorld, TerraWorld>> worldMap = new HashMap<>();
|
||||
private final Map<Long, TerraWorld> worldMap = new HashMap<>();
|
||||
private final EventManager eventManager = new TerraEventManager(this);
|
||||
private final GenericLoaders genericLoaders = new GenericLoaders(this);
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
@@ -122,15 +109,12 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
private final WorldHandle worldHandle = new ForgeWorldHandle();
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final CheckedRegistry<ConfigPack> checkedRegistry = new CheckedRegistry<>(registry);
|
||||
|
||||
private final ForgeAddon addon = new ForgeAddon(this);
|
||||
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(addon, this);
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(new ForgeAddon(this), this);
|
||||
private final LockedRegistry<TerraAddon> addonLockedRegistry = new LockedRegistry<>(addonRegistry);
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
private final Transformer<String, Biome> biomeFixer = new Transformer.Builder<String, Biome>()
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse(id)), Validator.notNull())
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse("minecraft:" + id.toLowerCase())), Validator.notNull()).build();
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse(id)), new NotNullValidator<>())
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build();
|
||||
private final File dataFolder;
|
||||
|
||||
public TerraForgePlugin() {
|
||||
@@ -139,7 +123,6 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
this.dataFolder = Paths.get("config", "Terra").toFile();
|
||||
saveDefaultConfig();
|
||||
config.load(this);
|
||||
debugLogger.setDebug(config.isDebug());
|
||||
LangUtil.load(config.getLanguage(), this);
|
||||
try {
|
||||
CommandUtil.registerAll(manager);
|
||||
@@ -160,7 +143,7 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
public void init() {
|
||||
public void setup() {
|
||||
logger.info("Initializing Terra...");
|
||||
|
||||
if(!addonRegistry.loadAll()) {
|
||||
@@ -170,10 +153,6 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
|
||||
registry.loadAll(this);
|
||||
logger.info("Loaded packs.");
|
||||
|
||||
((ForgeRegistry<Biome>) ForgeRegistries.BIOMES).unfreeze(); // Evil
|
||||
getConfigRegistry().forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> ForgeRegistries.BIOMES.register(ForgeUtil.createBiome(biome, pack, addon)))); // Register all Terra biomes.
|
||||
((ForgeRegistry<Biome>) ForgeRegistries.BIOMES).freeze();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,13 +162,10 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
|
||||
@Override
|
||||
public TerraWorld getWorld(World world) {
|
||||
return getWorld(((IWorld) world).dimensionType());
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(DimensionType type) {
|
||||
TerraWorld world = worldMap.get(type).getRight();
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with dimension type " + type);
|
||||
return world;
|
||||
return worldMap.computeIfAbsent(world.getSeed(), w -> {
|
||||
logger.info("Loading world " + w);
|
||||
return new TerraWorld(world, ((ForgeChunkGeneratorWrapper) world.getGenerator()).getPack(), this);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,6 +191,12 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
return JarUtil.getJarFile();
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(long seed) {
|
||||
TerraWorld world = worldMap.get(seed);
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with seed " + seed);
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.dfsek.terra.api.util.logging.Logger logger() {
|
||||
return logger;
|
||||
@@ -255,11 +237,14 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
config.load(this);
|
||||
LangUtil.load(config.getLanguage(), this); // Load language.
|
||||
boolean succeed = registry.loadAll(this);
|
||||
worldMap.forEach((seed, pair) -> {
|
||||
pair.getRight().getConfig().getSamplerCache().clear();
|
||||
String packID = pair.getRight().getConfig().getTemplate().getID();
|
||||
pair.setRight(new TerraWorld(pair.getRight().getWorld(), registry.get(packID), this));
|
||||
Map<Long, TerraWorld> newMap = new HashMap<>();
|
||||
worldMap.forEach((seed, tw) -> {
|
||||
tw.getConfig().getSamplerCache().clear();
|
||||
String packID = tw.getConfig().getTemplate().getID();
|
||||
newMap.put(seed, new TerraWorld(tw.getWorld(), registry.get(packID), this));
|
||||
});
|
||||
worldMap.clear();
|
||||
worldMap.putAll(newMap);
|
||||
return succeed;
|
||||
}
|
||||
|
||||
@@ -293,12 +278,7 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
genericLoaders.register(registry);
|
||||
registry
|
||||
.registerLoader(BlockData.class, (t, o, l) -> worldHandle.createBlockData((String) o))
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> biomeFixer.translate((String) o))
|
||||
.registerLoader(ResourceLocation.class, (t, o, l) -> {
|
||||
ResourceLocation identifier = ResourceLocation.tryParse((String) o);
|
||||
if(identifier == null) throw new LoadException("Invalid identifier: " + o);
|
||||
return identifier;
|
||||
});
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> biomeFixer.translate((String) o));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -306,11 +286,6 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
return eventManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<com.dfsek.terra.api.platform.modloader.Mod> getMods() {
|
||||
return net.minecraftforge.fml.ModList.get().getMods().stream().map(ForgeMod::new).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profiler getProfiler() {
|
||||
return profiler;
|
||||
@@ -320,16 +295,10 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
return manager;
|
||||
}
|
||||
|
||||
public Map<DimensionType, Pair<ServerWorld, TerraWorld>> getWorldMap() {
|
||||
return worldMap;
|
||||
}
|
||||
|
||||
@Addon("Terra-Forge")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public static final class ForgeAddon extends TerraAddon implements EventListener {
|
||||
|
||||
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
||||
private static final class ForgeAddon extends TerraAddon implements EventListener {
|
||||
|
||||
private final TerraPlugin main;
|
||||
|
||||
@@ -365,39 +334,6 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
injectTree(treeRegistry, "MEGA_SPRUCE", Features.MEGA_SPRUCE);
|
||||
injectTree(treeRegistry, "CRIMSON_FUNGUS", Features.CRIMSON_FUNGI);
|
||||
injectTree(treeRegistry, "WARPED_FUNGUS", Features.WARPED_FUNGI);
|
||||
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(template.doRegistryInjection()) {
|
||||
WorldGenRegistries.CONFIGURED_FEATURE.entrySet().forEach(entry -> {
|
||||
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getRegistryName())) {
|
||||
try {
|
||||
event.getPack().getTreeRegistry().add(entry.getKey().getRegistryName().toString(), (Tree) entry.getValue());
|
||||
main.getDebugLogger().info("Injected ConfiguredFeature " + entry.getKey().getRegistryName() + " as Tree: " + entry.getValue());
|
||||
} catch(DuplicateEntryException ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
templates.put(event.getPack(), Pair.of(template, null));
|
||||
}
|
||||
|
||||
@Priority(Priority.HIGHEST)
|
||||
@Global
|
||||
public void createInjectionOptions(ConfigPackPostLoadEvent event) {
|
||||
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
|
||||
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
templates.get(event.getPack()).setRight(template);
|
||||
}
|
||||
|
||||
|
||||
@@ -407,9 +343,5 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
} catch(DuplicateEntryException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-16
@@ -17,22 +17,14 @@ public class ForgeDirectional extends ForgeBlockData implements Directional {
|
||||
|
||||
@Override
|
||||
public BlockFace getFacing() {
|
||||
switch(delegate.getValue(property)) {
|
||||
case SOUTH:
|
||||
return BlockFace.SOUTH;
|
||||
case DOWN:
|
||||
return BlockFace.DOWN;
|
||||
case UP:
|
||||
return BlockFace.UP;
|
||||
case EAST:
|
||||
return BlockFace.EAST;
|
||||
case WEST:
|
||||
return BlockFace.WEST;
|
||||
case NORTH:
|
||||
return BlockFace.NORTH;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(delegate.getValue(property)) {
|
||||
case SOUTH -> BlockFace.SOUTH;
|
||||
case DOWN -> BlockFace.DOWN;
|
||||
case UP -> BlockFace.UP;
|
||||
case EAST -> BlockFace.EAST;
|
||||
case WEST -> BlockFace.WEST;
|
||||
case NORTH -> BlockFace.NORTH;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+58
-116
@@ -12,148 +12,90 @@ import net.minecraft.util.Direction;
|
||||
|
||||
public final class ForgeEnumAdapter {
|
||||
public static Stairs.Shape adapt(StairsShape shape) {
|
||||
switch(shape) {
|
||||
case OUTER_RIGHT:
|
||||
return Stairs.Shape.OUTER_RIGHT;
|
||||
case INNER_RIGHT:
|
||||
return Stairs.Shape.INNER_RIGHT;
|
||||
case OUTER_LEFT:
|
||||
return Stairs.Shape.OUTER_LEFT;
|
||||
case INNER_LEFT:
|
||||
return Stairs.Shape.INNER_LEFT;
|
||||
case STRAIGHT:
|
||||
return Stairs.Shape.STRAIGHT;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(shape) {
|
||||
case OUTER_RIGHT -> Stairs.Shape.OUTER_RIGHT;
|
||||
case INNER_RIGHT -> Stairs.Shape.INNER_RIGHT;
|
||||
case OUTER_LEFT -> Stairs.Shape.OUTER_LEFT;
|
||||
case INNER_LEFT -> Stairs.Shape.INNER_LEFT;
|
||||
case STRAIGHT -> Stairs.Shape.STRAIGHT;
|
||||
};
|
||||
}
|
||||
|
||||
public static Bisected.Half adapt(Half half) {
|
||||
switch(half) {
|
||||
case BOTTOM:
|
||||
return Bisected.Half.BOTTOM;
|
||||
case TOP:
|
||||
return Bisected.Half.TOP;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(half) {
|
||||
case BOTTOM -> Bisected.Half.BOTTOM;
|
||||
case TOP -> Bisected.Half.TOP;
|
||||
};
|
||||
}
|
||||
|
||||
public static BlockFace adapt(Direction direction) {
|
||||
switch(direction) {
|
||||
case DOWN:
|
||||
return BlockFace.DOWN;
|
||||
case UP:
|
||||
return BlockFace.UP;
|
||||
case WEST:
|
||||
return BlockFace.WEST;
|
||||
case EAST:
|
||||
return BlockFace.EAST;
|
||||
case NORTH:
|
||||
return BlockFace.NORTH;
|
||||
case SOUTH:
|
||||
return BlockFace.SOUTH;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(direction) {
|
||||
case DOWN -> BlockFace.DOWN;
|
||||
case UP -> BlockFace.UP;
|
||||
case WEST -> BlockFace.WEST;
|
||||
case EAST -> BlockFace.EAST;
|
||||
case NORTH -> BlockFace.NORTH;
|
||||
case SOUTH -> BlockFace.SOUTH;
|
||||
};
|
||||
}
|
||||
|
||||
public static Slab.Type adapt(SlabType type) {
|
||||
switch(type) {
|
||||
case BOTTOM:
|
||||
return Slab.Type.BOTTOM;
|
||||
case TOP:
|
||||
return Slab.Type.TOP;
|
||||
case DOUBLE:
|
||||
return Slab.Type.DOUBLE;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(type) {
|
||||
case BOTTOM -> Slab.Type.BOTTOM;
|
||||
case TOP -> Slab.Type.TOP;
|
||||
case DOUBLE -> Slab.Type.DOUBLE;
|
||||
};
|
||||
}
|
||||
|
||||
public static StairsShape adapt(Stairs.Shape shape) {
|
||||
switch(shape) {
|
||||
case STRAIGHT:
|
||||
return StairsShape.STRAIGHT;
|
||||
case INNER_LEFT:
|
||||
return StairsShape.INNER_LEFT;
|
||||
case OUTER_LEFT:
|
||||
return StairsShape.OUTER_LEFT;
|
||||
case INNER_RIGHT:
|
||||
return StairsShape.INNER_RIGHT;
|
||||
case OUTER_RIGHT:
|
||||
return StairsShape.OUTER_RIGHT;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(shape) {
|
||||
case STRAIGHT -> StairsShape.STRAIGHT;
|
||||
case INNER_LEFT -> StairsShape.INNER_LEFT;
|
||||
case OUTER_LEFT -> StairsShape.OUTER_LEFT;
|
||||
case INNER_RIGHT -> StairsShape.INNER_RIGHT;
|
||||
case OUTER_RIGHT -> StairsShape.OUTER_RIGHT;
|
||||
};
|
||||
}
|
||||
|
||||
public static Half adapt(Bisected.Half half) {
|
||||
switch(half) {
|
||||
case TOP:
|
||||
return Half.TOP;
|
||||
case BOTTOM:
|
||||
return Half.BOTTOM;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(half) {
|
||||
case TOP -> Half.TOP;
|
||||
case BOTTOM -> Half.BOTTOM;
|
||||
};
|
||||
}
|
||||
|
||||
public static Direction adapt(BlockFace face) {
|
||||
switch(face) {
|
||||
case SOUTH:
|
||||
return Direction.SOUTH;
|
||||
case NORTH:
|
||||
return Direction.NORTH;
|
||||
case EAST:
|
||||
return Direction.EAST;
|
||||
case WEST:
|
||||
return Direction.WEST;
|
||||
case UP:
|
||||
return Direction.UP;
|
||||
case DOWN:
|
||||
return Direction.DOWN;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return switch(face) {
|
||||
case SOUTH -> Direction.SOUTH;
|
||||
case NORTH -> Direction.NORTH;
|
||||
case EAST -> Direction.EAST;
|
||||
case WEST -> Direction.WEST;
|
||||
case UP -> Direction.UP;
|
||||
case DOWN -> Direction.DOWN;
|
||||
};
|
||||
}
|
||||
|
||||
public static SlabType adapt(Slab.Type type) {
|
||||
switch(type) {
|
||||
case DOUBLE:
|
||||
return SlabType.DOUBLE;
|
||||
case TOP:
|
||||
return SlabType.TOP;
|
||||
case BOTTOM:
|
||||
return SlabType.BOTTOM;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(type) {
|
||||
case DOUBLE -> SlabType.DOUBLE;
|
||||
case TOP -> SlabType.TOP;
|
||||
case BOTTOM -> SlabType.BOTTOM;
|
||||
};
|
||||
}
|
||||
|
||||
public static Axis adapt(Direction.Axis axis) {
|
||||
switch(axis) {
|
||||
case X:
|
||||
return Axis.X;
|
||||
case Y:
|
||||
return Axis.Y;
|
||||
case Z:
|
||||
return Axis.Z;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(axis) {
|
||||
case X -> Axis.X;
|
||||
case Y -> Axis.Y;
|
||||
case Z -> Axis.Z;
|
||||
};
|
||||
}
|
||||
|
||||
public static Direction.Axis adapt(Axis axis) {
|
||||
switch(axis) {
|
||||
case Z:
|
||||
return Direction.Axis.Z;
|
||||
case Y:
|
||||
return Direction.Axis.Y;
|
||||
case X:
|
||||
return Direction.Axis.X;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(axis) {
|
||||
case Z -> Direction.Axis.Z;
|
||||
case Y -> Direction.Axis.Y;
|
||||
case X -> Direction.Axis.X;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+6
-18
@@ -29,24 +29,12 @@ public class ForgeMultipleFacing extends ForgeBlockData implements MultipleFacin
|
||||
@Override
|
||||
public void setFace(BlockFace face, boolean facing) {
|
||||
switch(face) {
|
||||
case NORTH:
|
||||
delegate = delegate.setValue(BlockStateProperties.NORTH, facing);
|
||||
break;
|
||||
case SOUTH:
|
||||
delegate = delegate.setValue(BlockStateProperties.SOUTH, facing);
|
||||
break;
|
||||
case EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.EAST, facing);
|
||||
break;
|
||||
case WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.WEST, facing);
|
||||
break;
|
||||
case UP:
|
||||
delegate = delegate.setValue(BlockStateProperties.UP, facing);
|
||||
break;
|
||||
case DOWN:
|
||||
delegate = delegate.setValue(BlockStateProperties.DOWN, facing);
|
||||
break;
|
||||
case NORTH -> delegate = delegate.setValue(BlockStateProperties.NORTH, facing);
|
||||
case SOUTH -> delegate = delegate.setValue(BlockStateProperties.SOUTH, facing);
|
||||
case EAST -> delegate = delegate.setValue(BlockStateProperties.EAST, facing);
|
||||
case WEST -> delegate = delegate.setValue(BlockStateProperties.WEST, facing);
|
||||
case UP -> delegate = delegate.setValue(BlockStateProperties.UP, facing);
|
||||
case DOWN -> delegate = delegate.setValue(BlockStateProperties.DOWN, facing);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+36
-87
@@ -14,98 +14,47 @@ public class ForgeRotatable extends ForgeBlockData implements Rotatable {
|
||||
@Override
|
||||
public BlockFace getRotation() {
|
||||
int r = delegate.getValue(BlockStateProperties.ROTATION_16);
|
||||
switch(r) {
|
||||
case 0:
|
||||
return BlockFace.SOUTH;
|
||||
case 1:
|
||||
return BlockFace.SOUTH_SOUTH_WEST;
|
||||
case 2:
|
||||
return BlockFace.SOUTH_WEST;
|
||||
case 3:
|
||||
return BlockFace.WEST_SOUTH_WEST;
|
||||
case 4:
|
||||
return BlockFace.WEST;
|
||||
case 5:
|
||||
return BlockFace.WEST_NORTH_WEST;
|
||||
case 6:
|
||||
return BlockFace.NORTH_WEST;
|
||||
case 7:
|
||||
return BlockFace.NORTH_NORTH_WEST;
|
||||
case 8:
|
||||
return BlockFace.NORTH;
|
||||
case 9:
|
||||
return BlockFace.NORTH_NORTH_EAST;
|
||||
case 10:
|
||||
return BlockFace.NORTH_EAST;
|
||||
case 11:
|
||||
return BlockFace.EAST_NORTH_EAST;
|
||||
case 12:
|
||||
return BlockFace.EAST;
|
||||
case 13:
|
||||
return BlockFace.EAST_SOUTH_EAST;
|
||||
case 14:
|
||||
return BlockFace.SOUTH_EAST;
|
||||
case 15:
|
||||
return BlockFace.SOUTH_SOUTH_EAST;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown rotation " + r);
|
||||
}
|
||||
return switch(r) {
|
||||
case 0 -> BlockFace.SOUTH;
|
||||
case 1 -> BlockFace.SOUTH_SOUTH_WEST;
|
||||
case 2 -> BlockFace.SOUTH_WEST;
|
||||
case 3 -> BlockFace.WEST_SOUTH_WEST;
|
||||
case 4 -> BlockFace.WEST;
|
||||
case 5 -> BlockFace.WEST_NORTH_WEST;
|
||||
case 6 -> BlockFace.NORTH_WEST;
|
||||
case 7 -> BlockFace.NORTH_NORTH_WEST;
|
||||
case 8 -> BlockFace.NORTH;
|
||||
case 9 -> BlockFace.NORTH_NORTH_EAST;
|
||||
case 10 -> BlockFace.NORTH_EAST;
|
||||
case 11 -> BlockFace.EAST_NORTH_EAST;
|
||||
case 12 -> BlockFace.EAST;
|
||||
case 13 -> BlockFace.EAST_SOUTH_EAST;
|
||||
case 14 -> BlockFace.SOUTH_EAST;
|
||||
case 15 -> BlockFace.SOUTH_SOUTH_EAST;
|
||||
default -> throw new IllegalArgumentException("Unknown rotation " + r);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(BlockFace face) {
|
||||
switch(face) {
|
||||
case UP:
|
||||
case DOWN:
|
||||
throw new IllegalArgumentException("Illegal rotation " + face);
|
||||
case SOUTH:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 0);
|
||||
return;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 1);
|
||||
return;
|
||||
case SOUTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 2);
|
||||
return;
|
||||
case WEST_SOUTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 3);
|
||||
return;
|
||||
case WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 4);
|
||||
return;
|
||||
case WEST_NORTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 5);
|
||||
return;
|
||||
case NORTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 6);
|
||||
return;
|
||||
case NORTH_NORTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 7);
|
||||
return;
|
||||
case NORTH:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 8);
|
||||
return;
|
||||
case NORTH_NORTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 9);
|
||||
return;
|
||||
case NORTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 10);
|
||||
return;
|
||||
case EAST_NORTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 11);
|
||||
return;
|
||||
case EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 12);
|
||||
return;
|
||||
case EAST_SOUTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 13);
|
||||
return;
|
||||
case SOUTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 14);
|
||||
return;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 15);
|
||||
return;
|
||||
case UP, DOWN -> throw new IllegalArgumentException("Illegal rotation " + face);
|
||||
case SOUTH -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 0);
|
||||
case SOUTH_SOUTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 1);
|
||||
case SOUTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 2);
|
||||
case WEST_SOUTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 3);
|
||||
case WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 4);
|
||||
case WEST_NORTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 5);
|
||||
case NORTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 6);
|
||||
case NORTH_NORTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 7);
|
||||
case NORTH -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 8);
|
||||
case NORTH_NORTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 9);
|
||||
case NORTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 10);
|
||||
case EAST_NORTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 11);
|
||||
case EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 12);
|
||||
case EAST_SOUTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 13);
|
||||
case SOUTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 14);
|
||||
case SOUTH_SOUTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.dfsek.terra.forge.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PostLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("structures.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<ResourceLocation>> excludedPerBiomeStructures = new HashMap<>();
|
||||
|
||||
@Value("features.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<ResourceLocation>> excludedPerBiomeFeatures = new HashMap<>();
|
||||
|
||||
public Map<BiomeBuilder, Set<ResourceLocation>> getExcludedPerBiomeFeatures() {
|
||||
return excludedPerBiomeFeatures;
|
||||
}
|
||||
|
||||
public Map<BiomeBuilder, Set<ResourceLocation>> getExcludedPerBiomeStructures() {
|
||||
return excludedPerBiomeStructures;
|
||||
}
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
package com.dfsek.terra.forge.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PreLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("features.inject-registry.enable")
|
||||
@Default
|
||||
private boolean doRegistryInjection = false;
|
||||
|
||||
@Value("features.inject-biome.enable")
|
||||
@Default
|
||||
private boolean doBiomeInjection = false;
|
||||
|
||||
@Value("features.inject-registry.excluded-features")
|
||||
@Default
|
||||
private Set<ResourceLocation> excludedRegistryFeatures = new HashSet<>();
|
||||
|
||||
@Value("features.inject-biome.excluded-features")
|
||||
@Default
|
||||
private Set<ResourceLocation> excludedBiomeFeatures = new HashSet<>();
|
||||
|
||||
@Value("structures.inject-biome.excluded-features")
|
||||
@Default
|
||||
private Set<ResourceLocation> excludedBiomeStructures = new HashSet<>();
|
||||
|
||||
public boolean doBiomeInjection() {
|
||||
return doBiomeInjection;
|
||||
}
|
||||
|
||||
public boolean doRegistryInjection() {
|
||||
return doRegistryInjection;
|
||||
}
|
||||
|
||||
public Set<ResourceLocation> getExcludedBiomeFeatures() {
|
||||
return excludedBiomeFeatures;
|
||||
}
|
||||
|
||||
public Set<ResourceLocation> getExcludedRegistryFeatures() {
|
||||
return excludedRegistryFeatures;
|
||||
}
|
||||
|
||||
public Set<ResourceLocation> getExcludedBiomeStructures() {
|
||||
return excludedBiomeStructures;
|
||||
}
|
||||
}
|
||||
+13
-77
@@ -4,53 +4,32 @@ import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkData;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.forge.ForgeAdapter;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.block.ForgeBlockData;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
|
||||
import com.dfsek.terra.world.generation.math.samplers.Sampler;
|
||||
import com.dfsek.terra.world.population.items.TerraStructure;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.jafama.FastMath;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.EntityClassification;
|
||||
import net.minecraft.util.SharedSeedRandom;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.registry.DynamicRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.Blockreader;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeManager;
|
||||
import net.minecraft.world.biome.MobSpawnInfo;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.GenerationStage;
|
||||
import net.minecraft.world.gen.Heightmap;
|
||||
import net.minecraft.world.gen.WorldGenRegion;
|
||||
import net.minecraft.world.gen.feature.structure.Structure;
|
||||
import net.minecraft.world.gen.feature.structure.StructureManager;
|
||||
import net.minecraft.world.gen.feature.template.TemplateManager;
|
||||
import net.minecraft.world.gen.settings.DimensionStructuresSettings;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.world.spawner.WorldEntitySpawner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class ForgeChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper {
|
||||
private final long seed;
|
||||
@@ -70,10 +49,8 @@ public class ForgeChunkGeneratorWrapper extends ChunkGenerator implements Genera
|
||||
return pack;
|
||||
}
|
||||
|
||||
private DimensionType dimensionType;
|
||||
|
||||
public ForgeChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) {
|
||||
super(biomeSource, new DimensionStructuresSettings(configPack.getTemplate().vanillaStructures()));
|
||||
super(biomeSource, new DimensionStructuresSettings(false));
|
||||
this.pack = configPack;
|
||||
|
||||
this.delegate = new DefaultChunkGenerator3D(pack, TerraForgePlugin.getInstance());
|
||||
@@ -98,32 +75,8 @@ public class ForgeChunkGeneratorWrapper extends ChunkGenerator implements Genera
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockPos findNearestMapFeature(@NotNull ServerWorld world, @NotNull Structure<?> feature, @NotNull BlockPos center, int radius, boolean skipExistingChunks) {
|
||||
if(!pack.getTemplate().disableStructures()) {
|
||||
String name = Objects.requireNonNull(Registry.STRUCTURE_FEATURE.getKey(feature)).toString();
|
||||
TerraWorld terraWorld = TerraForgePlugin.getInstance().getWorld((World) world);
|
||||
TerraStructure located = pack.getStructure(pack.getTemplate().getLocatable().get(name));
|
||||
if(located != null) {
|
||||
CompletableFuture<BlockPos> result = new CompletableFuture<>();
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, ForgeAdapter.adapt(center).toLocation((World) world), 0, 500, location -> {
|
||||
result.complete(ForgeAdapter.adapt(location));
|
||||
}, TerraForgePlugin.getInstance());
|
||||
finder.run(); // Do this synchronously.
|
||||
try {
|
||||
return result.get();
|
||||
} catch(InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.findNearestMapFeature(world, feature, center, radius, skipExistingChunks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStronghold(@NotNull ChunkPos p_235952_1_) {
|
||||
if(pack.getTemplate().vanillaStructures()) return super.hasStronghold(p_235952_1_);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -143,23 +96,28 @@ public class ForgeChunkGeneratorWrapper extends ChunkGenerator implements Genera
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBaseHeight(int x, int z, Heightmap.@NotNull Type type) {
|
||||
TerraWorld world = TerraForgePlugin.getInstance().getWorld(dimensionType);
|
||||
public int getBaseHeight(int x, int z, Heightmap.@NotNull Type p_222529_3_) {
|
||||
TerraWorld world = TerraForgePlugin.getInstance().getWorld(seed);
|
||||
Sampler sampler = world.getConfig().getSamplerCache().getChunk(FastMath.floorDiv(x, 16), FastMath.floorDiv(z, 16));
|
||||
int cx = FastMath.floorMod(x, 16);
|
||||
int cz = FastMath.floorMod(z, 16);
|
||||
|
||||
int height = world.getWorld().getMaxHeight();
|
||||
while(height >= 0 && !type.isOpaque().test(((ForgeBlockData) world.getUngeneratedBlock(x, height - 1, z)).getHandle())) {
|
||||
|
||||
while (height >= 0 && sampler.sample(cx, height - 1, cz) < 0) {
|
||||
height--;
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull IBlockReader getBaseColumn(int x, int z) {
|
||||
TerraWorld world = TerraForgePlugin.getInstance().getWorld(dimensionType);
|
||||
int height = getBaseHeight(x, z, Heightmap.Type.WORLD_SURFACE);
|
||||
public @NotNull IBlockReader getBaseColumn(int p_230348_1_, int p_230348_2_) {
|
||||
int height = 64; // TODO: implementation
|
||||
BlockState[] array = new BlockState[256];
|
||||
for(int y = 255; y >= 0; y--) {
|
||||
if(y > height) {
|
||||
if(y > ((UserDefinedBiome) world.getBiomeProvider().getBiome(x, z)).getConfig().getSeaLevel()) {
|
||||
if(y > getSeaLevel()) {
|
||||
array[y] = Blocks.AIR.defaultBlockState();
|
||||
} else {
|
||||
array[y] = Blocks.WATER.defaultBlockState();
|
||||
@@ -172,31 +130,9 @@ public class ForgeChunkGeneratorWrapper extends ChunkGenerator implements Genera
|
||||
return new Blockreader(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnOriginalMobs(WorldGenRegion region) {
|
||||
if(pack.getTemplate().vanillaMobs()) {
|
||||
int cx = region.getCenterX();
|
||||
int cy = region.getCenterZ();
|
||||
Biome biome = region.getBiome((new ChunkPos(cx, cy)).getWorldPosition());
|
||||
SharedSeedRandom chunkRandom = new SharedSeedRandom();
|
||||
chunkRandom.setDecorationSeed(region.getSeed(), cx << 4, cy << 4);
|
||||
WorldEntitySpawner.spawnMobsForChunkGeneration(region, biome, cx, cy, chunkRandom);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobSpawnInfo.Spawners> getMobsAt(Biome p_230353_1_, StructureManager p_230353_2_, EntityClassification p_230353_3_, BlockPos p_230353_4_) {
|
||||
List<MobSpawnInfo.Spawners> spawns = net.minecraftforge.common.world.StructureSpawnManager.getStructureSpawns(p_230353_2_, p_230353_3_, p_230353_4_);
|
||||
if(spawns != null) return spawns;
|
||||
return super.getMobsAt(p_230353_1_, p_230353_2_, p_230353_3_, p_230353_4_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraChunkGenerator getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public void setDimensionType(DimensionType dimensionType) {
|
||||
this.dimensionType = dimensionType;
|
||||
}
|
||||
}
|
||||
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.dfsek.terra.forge.generation;
|
||||
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.DimensionSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TerraGeneratorType extends BiomeGeneratorTypeScreens {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public TerraGeneratorType(ConfigPack pack) {
|
||||
super(new StringTextComponent("Terra:" + pack.getTemplate().getID()));
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull ChunkGenerator generator(@NotNull Registry<Biome> biomeRegistry, @NotNull Registry<DimensionSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new ForgeChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.dfsek.terra.forge.generation;
|
||||
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.DimensionSettings;
|
||||
import net.minecraftforge.common.world.ForgeWorldType;
|
||||
|
||||
public class TerraLevelType implements ForgeWorldType.IChunkGeneratorFactory {
|
||||
public static final TerraLevelType TERRA_LEVEL_TYPE = new TerraLevelType();
|
||||
public static final ForgeWorldType FORGE_WORLD_TYPE = new ForgeWorldType(TERRA_LEVEL_TYPE).setRegistryName("terra", "world");
|
||||
@Override
|
||||
public ChunkGenerator createChunkGenerator(Registry<Biome> biomeRegistry, Registry<DimensionSettings> dimensionSettingsRegistry, long seed, String generatorSettings) {
|
||||
System.out.println(generatorSettings);
|
||||
dimensionSettingsRegistry.forEach(System.out::println);
|
||||
ConfigPack pack = TerraForgePlugin.getInstance().getConfigRegistry().get("DEFAULT");
|
||||
TerraForgePlugin.getInstance().logger().info("Creating generator for config pack " + pack.getTemplate().getID());
|
||||
return new ForgeChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.dfsek.terra.forge.listener;
|
||||
|
||||
import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.generation.TerraLevelType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.ForgeWorldTypeScreens;
|
||||
import net.minecraftforge.common.world.ForgeWorldType;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class ClientListener {
|
||||
private static final TerraForgePlugin INSTANCE = TerraForgePlugin.getInstance();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(FMLClientSetupEvent event) {
|
||||
INSTANCE.logger().info("Client setup...");
|
||||
|
||||
ForgeWorldType world = TerraLevelType.FORGE_WORLD_TYPE;
|
||||
ForgeWorldTypeScreens.registerFactory(world, (returnTo, dimensionGeneratorSettings) -> new Screen(world.getDisplayName()) {
|
||||
private final MutableInteger num = new MutableInteger(0);
|
||||
private final List<ConfigPack> packs = new ArrayList<>();
|
||||
private final Button toggle = new Button(0, 25, 120, 20, new StringTextComponent(""), button -> {
|
||||
num.increment();
|
||||
if(num.get() >= packs.size()) num.set(0);
|
||||
button.setMessage(new StringTextComponent("Pack: " + packs.get(num.get()).getTemplate().getID()));
|
||||
});
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
packs.clear();
|
||||
INSTANCE.getConfigRegistry().forEach((Consumer<ConfigPack>) packs::add);
|
||||
addButton(new Button(0, 0, 120, 20, new StringTextComponent("Close"), btn -> Minecraft.getInstance().setScreen(returnTo)));
|
||||
toggle.setMessage(new StringTextComponent("Pack: " + packs.get(num.get()).getTemplate().getID()));
|
||||
addButton(toggle);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,31 @@
|
||||
package com.dfsek.terra.forge.listener;
|
||||
|
||||
import com.dfsek.terra.forge.ForgeUtil;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.generation.TerraLevelType;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraftforge.common.world.ForgeWorldType;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class RegistryListener {
|
||||
private static final TerraForgePlugin INSTANCE = TerraForgePlugin.getInstance();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerLevels(RegistryEvent.Register<ForgeWorldType> event) {
|
||||
INSTANCE.logger().info("Registering level types...");
|
||||
event.getRegistry().register(TerraLevelType.FORGE_WORLD_TYPE);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegistryEvent.Register<Biome> event) {
|
||||
INSTANCE.setup(); // Setup now because we need the biomes, and this event happens after blocks n stuff
|
||||
INSTANCE.getConfigRegistry().forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> event.getRegistry().register(ForgeUtil.createBiome(biome)))); // Register all Terra biomes.
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerPop(RegistryEvent.Register<Feature<?>> event) {
|
||||
event.getRegistry().register(TerraForgePlugin.POPULATOR_FEATURE);
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerChunkProvider;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
public abstract class ServerWorldMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private ServerChunkProvider chunkSource;
|
||||
|
||||
@Shadow
|
||||
protected abstract void initCapabilities();
|
||||
|
||||
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;initCapabilities()V"))
|
||||
public void injectConstructor(ServerWorld serverWorld) {
|
||||
if(chunkSource.getGenerator() instanceof ForgeChunkGeneratorWrapper) {
|
||||
ForgeChunkGeneratorWrapper chunkGeneratorWrapper = (ForgeChunkGeneratorWrapper) chunkSource.getGenerator();
|
||||
DimensionType dimensionType = ((World) (Object) this).dimensionType();
|
||||
TerraForgePlugin.getInstance().getWorldMap().put(dimensionType, Pair.of((ServerWorld) (Object) this, new TerraWorld((com.dfsek.terra.api.platform.world.World) this, chunkGeneratorWrapper.getPack(), TerraForgePlugin.getInstance())));
|
||||
chunkGeneratorWrapper.setDimensionType(dimensionType);
|
||||
TerraForgePlugin.getInstance().logger().info("Registered world " + this + " to dimension type " + dimensionType);
|
||||
}
|
||||
initCapabilities();
|
||||
}
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.access;
|
||||
|
||||
import net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(BiomeGeneratorTypeScreens.class)
|
||||
public interface BiomeGeneratorTypeScreensAccessor {
|
||||
@Accessor("PRESETS")
|
||||
static List<BiomeGeneratorTypeScreens> getPresets() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Mutable
|
||||
@Accessor
|
||||
void setDescription(ITextComponent description);
|
||||
}
|
||||
+9
-26
@@ -88,32 +88,15 @@ public abstract class MobSpawnerTileEntityMixin extends TileEntityMixin {
|
||||
public void terra$applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
switch(k) {
|
||||
case "type":
|
||||
terra$setSpawnedType(TerraForgePlugin.getInstance().getWorldHandle().getEntity(v));
|
||||
return;
|
||||
case "delay":
|
||||
terra$setDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "min_delay":
|
||||
terra$setMinSpawnDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "max_delay":
|
||||
terra$setMaxSpawnDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "spawn_count":
|
||||
terra$setSpawnCount(Integer.parseInt(v));
|
||||
return;
|
||||
case "spawn_range":
|
||||
terra$setSpawnRange(Integer.parseInt(v));
|
||||
return;
|
||||
case "max_nearby":
|
||||
terra$setMaxNearbyEntities(Integer.parseInt(v));
|
||||
return;
|
||||
case "required_player_range":
|
||||
terra$setRequiredPlayerRange(Integer.parseInt(v));
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid property: " + k);
|
||||
case "type" -> terra$setSpawnedType(TerraForgePlugin.getInstance().getWorldHandle().getEntity(v));
|
||||
case "delay" -> terra$setDelay(Integer.parseInt(v));
|
||||
case "min_delay" -> terra$setMinSpawnDelay(Integer.parseInt(v));
|
||||
case "max_delay" -> terra$setMaxSpawnDelay(Integer.parseInt(v));
|
||||
case "spawn_count" -> terra$setSpawnCount(Integer.parseInt(v));
|
||||
case "spawn_range" -> terra$setSpawnRange(Integer.parseInt(v));
|
||||
case "max_nearby" -> terra$setMaxNearbyEntities(Integer.parseInt(v));
|
||||
case "required_player_range" -> terra$setRequiredPlayerRange(Integer.parseInt(v));
|
||||
default -> throw new IllegalArgumentException("Invalid property: " + k);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.init;
|
||||
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.generation.TerraGeneratorType;
|
||||
import com.dfsek.terra.forge.mixin.access.BiomeGeneratorTypeScreensAccessor;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens;
|
||||
import net.minecraft.resources.ResourcePackList;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public abstract class MinecraftClientMixin {
|
||||
@Redirect(method = "<init>", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/resources/ResourcePackList;reload()V" // sorta arbitrary position, after mod init, before window opens
|
||||
))
|
||||
public void injectConstructor(ResourcePackList resourcePackList) {
|
||||
TerraForgePlugin.getInstance().init(); // Load during MinecraftClient construction, after other mods have registered blocks and stuff
|
||||
TerraForgePlugin.getInstance().getConfigRegistry().forEach(pack -> {
|
||||
final BiomeGeneratorTypeScreens generatorType = new TerraGeneratorType(pack);
|
||||
//noinspection ConstantConditions
|
||||
((BiomeGeneratorTypeScreensAccessor) generatorType).setDescription(new StringTextComponent("Terra:" + pack.getTemplate().getID()));
|
||||
BiomeGeneratorTypeScreensAccessor.getPresets().add(1, generatorType);
|
||||
});
|
||||
resourcePackList.reload();
|
||||
}
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.init;
|
||||
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import net.minecraft.server.Main;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Main.class)
|
||||
public class MinecraftServerMixin {
|
||||
@Inject(method = "main([Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/DynamicRegistries;builtin()Lnet/minecraft/util/registry/DynamicRegistries$Impl;"))
|
||||
private static void injectConstructor(String[] args, CallbackInfo ci) {
|
||||
TerraForgePlugin.getInstance().init(); // Load during MinecraftServer construction, after other mods have registered blocks and stuff
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,7 @@
|
||||
"refmap": "terra-refmap.json",
|
||||
"mixins": [
|
||||
"DimensionGeneratorSettingsMixin",
|
||||
"ServerWorldMixin",
|
||||
"access.AbstractSpawnerAccessor",
|
||||
"access.BiomeGeneratorTypeScreensAccessor",
|
||||
"implementations.BiomeMixin",
|
||||
"implementations.ChunkGeneratorMixin",
|
||||
"implementations.ConfiguredFeatureMixin",
|
||||
@@ -33,10 +31,6 @@
|
||||
"implementations.world.WorldGenRegionMixin"
|
||||
],
|
||||
"client": [
|
||||
"init.MinecraftClientMixin"
|
||||
],
|
||||
"server": [
|
||||
"init.MinecraftServerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
Reference in New Issue
Block a user