reformat code

This commit is contained in:
dfsek
2022-05-26 19:40:41 -07:00
parent 49857f6b91
commit ee373bbe4b
63 changed files with 214 additions and 242 deletions
@@ -10,7 +10,7 @@ final class SelfDelegate implements BiomeDelegate {
public static final SelfDelegate INSTANCE = new SelfDelegate(); public static final SelfDelegate INSTANCE = new SelfDelegate();
private SelfDelegate() { private SelfDelegate() {
} }
@Override @Override
@@ -28,7 +28,7 @@ public class BiomePipelineTemplate extends BiomeProviderTemplate {
@Description(""" @Description("""
The initial size of biome chunks. This value must be at least 2. The initial size of biome chunks. This value must be at least 2.
<b>This is not the final size of biome chunks. Final chunks will be much larger</b>. <b>This is not the final size of biome chunks. Final chunks will be much larger</b>.
It is recommended to keep biome chunks' final size in the range of [50, 300] It is recommended to keep biome chunks' final size in the range of [50, 300]
to prevent performance issues. To calculate the size of biome chunks, simply to prevent performance issues. To calculate the size of biome chunks, simply
take initial-size and for each expand stage, multiply the running value by 2 take initial-size and for each expand stage, multiply the running value by 2
@@ -22,7 +22,7 @@ public class SlantHolder {
} }
public static SlantHolder of(TreeMap<Double, PaletteHolder> layers, double minSlope) { public static SlantHolder of(TreeMap<Double, PaletteHolder> layers, double minSlope) {
if(layers.size() == 1){ if(layers.size() == 1) {
Entry<Double, PaletteHolder> firstEntry = layers.firstEntry(); Entry<Double, PaletteHolder> firstEntry = layers.firstEntry();
return new Single(firstEntry.getValue(), minSlope); return new Single(firstEntry.getValue(), minSlope);
} }
@@ -42,9 +42,9 @@ public class SlantHolder {
} }
private static final class Single extends SlantHolder { private static final class Single extends SlantHolder {
private final PaletteHolder layers; private final PaletteHolder layers;
public Single(PaletteHolder layers, double minSlope) { public Single(PaletteHolder layers, double minSlope) {
super(of(minSlope, layers), minSlope); super(of(minSlope, layers), minSlope);
this.layers = layers; this.layers = layers;
@@ -55,7 +55,7 @@ public class SlantHolder {
map.put(v, layer); map.put(v, layer);
return map; return map;
} }
@Override @Override
public PaletteHolder getPalette(double slope) { public PaletteHolder getPalette(double slope) {
return layers; return layers;
@@ -34,12 +34,12 @@ public class PaddedGridDistributor implements Distributor {
public boolean matches(int x, int z, long seed) { public boolean matches(int x, int z, long seed) {
int cellX = FastMath.floorDiv(x, cellWidth); int cellX = FastMath.floorDiv(x, cellWidth);
int cellZ = FastMath.floorDiv(z, cellWidth); int cellZ = FastMath.floorDiv(z, cellWidth);
Random random = new Random((murmur64(MathUtil.squash(cellX, cellZ)) ^ seed) + salt); Random random = new Random((murmur64(MathUtil.squash(cellX, cellZ)) ^ seed) + salt);
int pointX = random.nextInt(width) + cellX * cellWidth; int pointX = random.nextInt(width) + cellX * cellWidth;
int pointZ = random.nextInt(width) + cellZ * cellWidth; int pointZ = random.nextInt(width) + cellZ * cellWidth;
return x == pointX && z == pointZ; return x == pointX && z == pointZ;
} }
} }
@@ -7,9 +7,10 @@
package com.dfsek.terra.addons.noise.normalizer; package com.dfsek.terra.addons.noise.normalizer;
import net.jafama.FastMath;
import com.dfsek.terra.api.noise.NoiseSampler; import com.dfsek.terra.api.noise.NoiseSampler;
import net.jafama.FastMath;
public class PosterizationNormalizer extends Normalizer { public class PosterizationNormalizer extends Normalizer {
private final double stepSize; private final double stepSize;
@@ -22,6 +22,7 @@ public class GaborNoiseSampler extends NoiseFunction {
private double impulseDensity = (impulsesPerKernel / (Math.PI * kernelRadius * kernelRadius)); private double impulseDensity = (impulsesPerKernel / (Math.PI * kernelRadius * kernelRadius));
private double impulsesPerCell = impulseDensity * kernelRadius * kernelRadius; private double impulsesPerCell = impulseDensity * kernelRadius * kernelRadius;
private double g = FastMath.exp(-impulsesPerCell); private double g = FastMath.exp(-impulsesPerCell);
private double omega0 = Math.PI * 0.25; private double omega0 = Math.PI * 0.25;
private boolean isotropic = true; private boolean isotropic = true;
@@ -13,9 +13,6 @@ import ca.solostudios.strata.version.VersionRange;
import com.dfsek.tectonic.api.exception.LoadException; import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.tectonic.api.loader.ConfigLoader; import com.dfsek.tectonic.api.loader.ConfigLoader;
import com.dfsek.tectonic.yaml.YamlConfiguration; import com.dfsek.tectonic.yaml.YamlConfiguration;
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -23,7 +20,6 @@ import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.FileVisitOption; import java.nio.file.FileVisitOption;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@@ -41,6 +37,7 @@ import com.dfsek.terra.addons.manifest.impl.config.loaders.VersionRangeLoader;
import com.dfsek.terra.addons.manifest.impl.exception.AddonException; import com.dfsek.terra.addons.manifest.impl.exception.AddonException;
import com.dfsek.terra.addons.manifest.impl.exception.ManifestException; import com.dfsek.terra.addons.manifest.impl.exception.ManifestException;
import com.dfsek.terra.addons.manifest.impl.exception.ManifestNotPresentException; import com.dfsek.terra.addons.manifest.impl.exception.ManifestNotPresentException;
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon; import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
@@ -12,7 +12,7 @@ public class Scope {
public Variable<?> get(String id) { public Variable<?> get(String id) {
throw new IllegalStateException("Cannot get variable from null scope: " + id); throw new IllegalStateException("Cannot get variable from null scope: " + id);
} }
@Override @Override
public void put(String id, Variable<?> variable) { public void put(String id, Variable<?> variable) {
throw new IllegalStateException("Cannot set variable in null scope: " + id); throw new IllegalStateException("Cannot set variable in null scope: " + id);
@@ -38,7 +38,7 @@ public class Scope {
public void put(String id, Variable<?> variable) { public void put(String id, Variable<?> variable) {
variableMap.put(id, variable); variableMap.put(id, variable);
} }
public Scope sub() { public Scope sub() {
return new Scope(this); return new Scope(this);
@@ -7,13 +7,13 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations; package com.dfsek.terra.addons.terrascript.parser.lang.operations;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments; import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope; import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public abstract class BinaryOperation<I, O> implements Returnable<O> { public abstract class BinaryOperation<I, O> implements Returnable<O> {
private final Returnable<I> left; private final Returnable<I> left;
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations; package com.dfsek.terra.addons.terrascript.parser.lang.operations;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class BooleanAndOperation extends BinaryOperation<Boolean, Boolean> { public class BooleanAndOperation extends BinaryOperation<Boolean, Boolean> {
public BooleanAndOperation(Returnable<Boolean> left, Returnable<Boolean> right, Position start) { public BooleanAndOperation(Returnable<Boolean> left, Returnable<Boolean> right, Position start) {
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations; package com.dfsek.terra.addons.terrascript.parser.lang.operations;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class BooleanOrOperation extends BinaryOperation<Boolean, Boolean> { public class BooleanOrOperation extends BinaryOperation<Boolean, Boolean> {
public BooleanOrOperation(Returnable<Boolean> left, Returnable<Boolean> right, Position start) { public BooleanOrOperation(Returnable<Boolean> left, Returnable<Boolean> right, Position start) {
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations; package com.dfsek.terra.addons.terrascript.parser.lang.operations;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class ConcatenationOperation extends BinaryOperation<Object, Object> { public class ConcatenationOperation extends BinaryOperation<Object, Object> {
public ConcatenationOperation(Returnable<Object> left, Returnable<Object> right, Position position) { public ConcatenationOperation(Returnable<Object> left, Returnable<Object> right, Position position) {
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations; package com.dfsek.terra.addons.terrascript.parser.lang.operations;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class DivisionOperation extends BinaryOperation<Number, Number> { public class DivisionOperation extends BinaryOperation<Number, Number> {
public DivisionOperation(Returnable<Number> left, Returnable<Number> right, Position position) { public DivisionOperation(Returnable<Number> left, Returnable<Number> right, Position position) {
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations; package com.dfsek.terra.addons.terrascript.parser.lang.operations;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class ModuloOperation extends BinaryOperation<Number, Number> { public class ModuloOperation extends BinaryOperation<Number, Number> {
public ModuloOperation(Returnable<Number> left, Returnable<Number> right, Position start) { public ModuloOperation(Returnable<Number> left, Returnable<Number> right, Position start) {
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations; package com.dfsek.terra.addons.terrascript.parser.lang.operations;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class MultiplicationOperation extends BinaryOperation<Number, Number> { public class MultiplicationOperation extends BinaryOperation<Number, Number> {
public MultiplicationOperation(Returnable<Number> left, Returnable<Number> right, Position position) { public MultiplicationOperation(Returnable<Number> left, Returnable<Number> right, Position position) {
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations; package com.dfsek.terra.addons.terrascript.parser.lang.operations;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class NumberAdditionOperation extends BinaryOperation<Number, Number> { public class NumberAdditionOperation extends BinaryOperation<Number, Number> {
public NumberAdditionOperation(Returnable<Number> left, Returnable<Number> right, Position position) { public NumberAdditionOperation(Returnable<Number> left, Returnable<Number> right, Position position) {
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations; package com.dfsek.terra.addons.terrascript.parser.lang.operations;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class SubtractionOperation extends BinaryOperation<Number, Number> { public class SubtractionOperation extends BinaryOperation<Number, Number> {
public SubtractionOperation(Returnable<Number> left, Returnable<Number> right, Position position) { public SubtractionOperation(Returnable<Number> left, Returnable<Number> right, Position position) {
@@ -9,12 +9,12 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
import net.jafama.FastMath; import net.jafama.FastMath;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation; import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
import static com.dfsek.terra.api.util.MathUtil.EPSILON; import static com.dfsek.terra.api.util.MathUtil.EPSILON;
@@ -7,12 +7,12 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements; package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation; import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class GreaterOrEqualsThanStatement extends BinaryOperation<Number, Boolean> { public class GreaterOrEqualsThanStatement extends BinaryOperation<Number, Boolean> {
public GreaterOrEqualsThanStatement(Returnable<Number> left, Returnable<Number> right, Position position) { public GreaterOrEqualsThanStatement(Returnable<Number> left, Returnable<Number> right, Position position) {
@@ -7,12 +7,12 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements; package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation; import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class GreaterThanStatement extends BinaryOperation<Number, Boolean> { public class GreaterThanStatement extends BinaryOperation<Number, Boolean> {
public GreaterThanStatement(Returnable<Number> left, Returnable<Number> right, Position position) { public GreaterThanStatement(Returnable<Number> left, Returnable<Number> right, Position position) {
@@ -7,12 +7,12 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements; package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation; import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class LessThanOrEqualsStatement extends BinaryOperation<Number, Boolean> { public class LessThanOrEqualsStatement extends BinaryOperation<Number, Boolean> {
public LessThanOrEqualsStatement(Returnable<Number> left, Returnable<Number> right, Position position) { public LessThanOrEqualsStatement(Returnable<Number> left, Returnable<Number> right, Position position) {
@@ -7,12 +7,12 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements; package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation; import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import java.util.function.Supplier;
public class LessThanStatement extends BinaryOperation<Number, Boolean> { public class LessThanStatement extends BinaryOperation<Number, Boolean> {
public LessThanStatement(Returnable<Number> left, Returnable<Number> right, Position position) { public LessThanStatement(Returnable<Number> left, Returnable<Number> right, Position position) {
@@ -7,14 +7,14 @@
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements; package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import net.jafama.FastMath; import net.jafama.FastMath;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import static com.dfsek.terra.api.util.MathUtil.EPSILON; import static com.dfsek.terra.api.util.MathUtil.EPSILON;
@@ -30,7 +30,7 @@ public class NotEqualsStatement extends BinaryOperation<Object, Boolean> {
if(leftUnwrapped instanceof Number l && rightUnwrapped instanceof Number r) { if(leftUnwrapped instanceof Number l && rightUnwrapped instanceof Number r) {
return FastMath.abs(l.doubleValue() - r.doubleValue()) > EPSILON; return FastMath.abs(l.doubleValue() - r.doubleValue()) > EPSILON;
} }
return !leftUnwrapped.equals(rightUnwrapped); return !leftUnwrapped.equals(rightUnwrapped);
} }
@@ -47,7 +47,7 @@ public class EntityFunction implements Function<Void> {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments; TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(), Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation()); z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
Entity entity = arguments.getWorld().spawnEntity(Vector3.of(xz.getX(), y.apply(implementationArguments, scope).doubleValue(), Entity entity = arguments.getWorld().spawnEntity(Vector3.of(xz.getX(), y.apply(implementationArguments, scope).doubleValue(),
xz.getZ()) xz.getZ())
.mutable() .mutable()
@@ -36,9 +36,9 @@ public class GetMarkFunction implements Function<String> {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments; TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(), Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation()); z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
String mark = arguments.getMark(Vector3.of(FastMath.floorToInt(xz.getX()), FastMath.floorToInt( String mark = arguments.getMark(Vector3.of(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(
y.apply(implementationArguments, scope).doubleValue()), y.apply(implementationArguments, scope).doubleValue()),
FastMath.floorToInt(xz.getZ())) FastMath.floorToInt(xz.getZ()))
.mutable() .mutable()
.add(arguments.getOrigin()) .add(arguments.getOrigin())
@@ -38,8 +38,8 @@ public class SetMarkFunction implements Function<Void> {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments; TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(), Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation()); z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
arguments.setMark(Vector3.of(FastMath.floorToInt(xz.getX()), arguments.setMark(Vector3.of(FastMath.floorToInt(xz.getX()),
FastMath.floorToInt( FastMath.floorToInt(
y.apply(implementationArguments, scope).doubleValue()), y.apply(implementationArguments, scope).doubleValue()),
@@ -43,8 +43,8 @@ public class StateFunction implements Function<Void> {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments; TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(), Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation()); z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
Vector3 origin = Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, scope).intValue(), Vector3 origin = Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, scope).intValue(),
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable(); FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
try { try {
@@ -60,11 +60,11 @@ public class StructureFunction implements Function<Boolean> {
if(arguments.getRecursions() > platform.getTerraConfig().getMaxRecursion()) if(arguments.getRecursions() > platform.getTerraConfig().getMaxRecursion())
throw new RuntimeException("Structure recursion too deep: " + arguments.getRecursions()); throw new RuntimeException("Structure recursion too deep: " + arguments.getRecursions());
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(), Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation()); z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
String app = id.apply(implementationArguments, scope); String app = id.apply(implementationArguments, scope);
return registry.getByID(app).map(script -> { return registry.getByID(app).map(script -> {
Rotation rotation1; Rotation rotation1;
@@ -4,8 +4,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import com.dfsek.terra.addons.noise.config.DimensionApplicableNoiseSampler; import com.dfsek.terra.addons.noise.config.DimensionApplicableNoiseSampler;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable; import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
@@ -14,7 +12,6 @@ import com.dfsek.terra.addons.terrascript.parser.lang.constants.NumericConstant;
import com.dfsek.terra.addons.terrascript.parser.lang.constants.StringConstant; import com.dfsek.terra.addons.terrascript.parser.lang.constants.StringConstant;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder; import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import com.dfsek.terra.api.noise.NoiseSampler;
public class SamplerFunctionBuilder implements FunctionBuilder<com.dfsek.terra.addons.terrascript.parser.lang.functions.Function<Number>> { public class SamplerFunctionBuilder implements FunctionBuilder<com.dfsek.terra.addons.terrascript.parser.lang.functions.Function<Number>> {
@@ -36,30 +33,36 @@ public class SamplerFunctionBuilder implements FunctionBuilder<com.dfsek.terra.a
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public com.dfsek.terra.addons.terrascript.parser.lang.functions.Function<Number> build(List<Returnable<?>> argumentList, Position position) { public com.dfsek.terra.addons.terrascript.parser.lang.functions.Function<Number> build(List<Returnable<?>> argumentList,
Position position) {
Returnable<String> arg = (Returnable<String>) argumentList.get(0); Returnable<String> arg = (Returnable<String>) argumentList.get(0);
if(argumentList.size() == 3) { // 2D if(argumentList.size() == 3) { // 2D
if(arg instanceof StringConstant constant) { if(arg instanceof StringConstant constant) {
return new ConstantSamplerFunction(Objects.requireNonNull(samplers2d.get(constant.getConstant()), "No such 2D noise function " + constant.getConstant()).getSampler(), return new ConstantSamplerFunction(Objects.requireNonNull(samplers2d.get(constant.getConstant()),
(Returnable<Number>) argumentList.get(1), "No such 2D noise function " + constant.getConstant())
new NumericConstant(0, position), .getSampler(),
(Returnable<Number>) argumentList.get(2), (Returnable<Number>) argumentList.get(1),
true, new NumericConstant(0, position),
position); (Returnable<Number>) argumentList.get(2),
true,
position);
} else { } else {
return new SamplerFunction((Returnable<String>) argumentList.get(0), return new SamplerFunction((Returnable<String>) argumentList.get(0),
(Returnable<Number>) argumentList.get(1), (Returnable<Number>) argumentList.get(1),
new NumericConstant(0, position), new NumericConstant(0, position),
(Returnable<Number>) argumentList.get(2), (Returnable<Number>) argumentList.get(2),
s -> Objects.requireNonNull(samplers2d.get(s.get()), "No such 2D noise function " + s.get()).getSampler(), s -> Objects.requireNonNull(samplers2d.get(s.get()), "No such 2D noise function " + s.get())
.getSampler(),
true, true,
position); position);
} }
} else { // 3D } else { // 3D
if(arg instanceof StringConstant constant) { if(arg instanceof StringConstant constant) {
return new ConstantSamplerFunction(Objects.requireNonNull(samplers3d.get(constant.getConstant()), "No such 2D noise function " + constant.getConstant()).getSampler(), return new ConstantSamplerFunction(Objects.requireNonNull(samplers3d.get(constant.getConstant()),
"No such 2D noise function " + constant.getConstant())
.getSampler(),
(Returnable<Number>) argumentList.get(1), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (Returnable<Number>) argumentList.get(2),
(Returnable<Number>) argumentList.get(3), (Returnable<Number>) argumentList.get(3),
@@ -70,7 +73,8 @@ public class SamplerFunctionBuilder implements FunctionBuilder<com.dfsek.terra.a
(Returnable<Number>) argumentList.get(1), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (Returnable<Number>) argumentList.get(2),
(Returnable<Number>) argumentList.get(3), (Returnable<Number>) argumentList.get(3),
s -> Objects.requireNonNull(samplers2d.get(s.get()), "No such 2D noise function " + s.get()).getSampler(), s -> Objects.requireNonNull(samplers2d.get(s.get()), "No such 2D noise function " + s.get())
.getSampler(),
true, true,
position); position);
} }
@@ -105,7 +105,7 @@ public class BinaryColumn {
int smallMaxY = Math.min(this.maxY, that.maxY); int smallMaxY = Math.min(this.maxY, that.maxY);
if(bigMinY >= smallMaxY) return getNull(); if(bigMinY >= smallMaxY) return getNull();
return new BinaryColumn(bigMinY, smallMaxY, y -> this.get(y) && that.get(y)); return new BinaryColumn(bigMinY, smallMaxY, y -> this.get(y) && that.get(y));
} }
@@ -131,35 +131,35 @@ public class Vector2 {
return "(" + x + ", " + z + ")"; return "(" + x + ", " + z + ")";
} }
public static class Mutable extends Vector2 { public static class Mutable extends Vector2 {
private Mutable(double x, double z) { private Mutable(double x, double z) {
super(x, z); super(x, z);
} }
public double getX() { public double getX() {
return x; return x;
} }
public Mutable setX(double x) { public Mutable setX(double x) {
this.x = x; this.x = x;
return this; return this;
} }
public double getZ() { public double getZ() {
return z; return z;
} }
public Mutable setZ(double z) { public Mutable setZ(double z) {
this.z = z; this.z = z;
return this; return this;
} }
public Vector2 immutable() { public Vector2 immutable() {
return Vector2.of(x, z); return Vector2.of(x, z);
} }
/** /**
* Get the length of this Vector * Get the length of this Vector
* *
@@ -168,7 +168,7 @@ public class Vector2 {
public double length() { public double length() {
return FastMath.sqrt(lengthSquared()); return FastMath.sqrt(lengthSquared());
} }
/** /**
* Get the squared length of this Vector * Get the squared length of this Vector
* *
@@ -177,13 +177,13 @@ public class Vector2 {
public double lengthSquared() { public double lengthSquared() {
return x * x + z * z; return x * x + z * z;
} }
public Mutable add(double x, double z) { public Mutable add(double x, double z) {
this.x += x; this.x += x;
this.z += z; this.z += z;
return this; return this;
} }
/** /**
* Multiply X and Z components by a value. * Multiply X and Z components by a value.
* *
@@ -196,7 +196,7 @@ public class Vector2 {
z *= m; z *= m;
return this; return this;
} }
/** /**
* Add this vector to another. * Add this vector to another.
* *
@@ -209,7 +209,7 @@ public class Vector2 {
z += other.getZ(); z += other.getZ();
return this; return this;
} }
/** /**
* Subtract a vector from this vector, * Subtract a vector from this vector,
* *
@@ -222,7 +222,7 @@ public class Vector2 {
z -= other.getZ(); z -= other.getZ();
return this; return this;
} }
/** /**
* Normalize this vector to length 1 * Normalize this vector to length 1
* *
@@ -232,7 +232,7 @@ public class Vector2 {
divide(length()); divide(length());
return this; return this;
} }
/** /**
* Divide X and Z components by a value. * Divide X and Z components by a value.
* *
@@ -91,7 +91,7 @@ public class Vector3 {
public double getY() { public double getY() {
return y; return y;
} }
public int getBlockX() { public int getBlockX() {
return FastMath.floorToInt(x); return FastMath.floorToInt(x);
@@ -155,70 +155,70 @@ public class Vector3 {
return "(" + getX() + ", " + getY() + ", " + getZ() + ")"; return "(" + getX() + ", " + getY() + ", " + getZ() + ")";
} }
public static class Mutable extends Vector3 { public static class Mutable extends Vector3 {
private Mutable(double x, double y, double z) { private Mutable(double x, double y, double z) {
super(x, y, z); super(x, y, z);
} }
public static Mutable of(double x, double y, double z) { public static Mutable of(double x, double y, double z) {
return new Mutable(x, y, z); return new Mutable(x, y, z);
} }
public Vector3 immutable() { public Vector3 immutable() {
return Vector3.of(x, y, z); return Vector3.of(x, y, z);
} }
public double getZ() { public double getZ() {
return z; return z;
} }
public Mutable setZ(double z) { public Mutable setZ(double z) {
this.z = z; this.z = z;
return this; return this;
} }
public double getX() { public double getX() {
return x; return x;
} }
public Mutable setX(double x) { public Mutable setX(double x) {
this.x = x; this.x = x;
return this; return this;
} }
public double getY() { public double getY() {
return y; return y;
} }
public Mutable setY(double y) { public Mutable setY(double y) {
this.y = y; this.y = y;
return this; return this;
} }
public double lengthSquared() { public double lengthSquared() {
return x * x + y * y + z * z; return x * x + y * y + z * z;
} }
public double length() { public double length() {
return FastMath.sqrt(lengthSquared()); return FastMath.sqrt(lengthSquared());
} }
public double inverseLength() { public double inverseLength() {
return FastMath.invSqrtQuick(lengthSquared()); return FastMath.invSqrtQuick(lengthSquared());
} }
public Mutable normalize() { public Mutable normalize() {
return this.multiply(this.inverseLength()); return this.multiply(this.inverseLength());
} }
public Mutable subtract(int x, int y, int z) { public Mutable subtract(int x, int y, int z) {
this.x -= x; this.x -= x;
this.y -= y; this.y -= y;
this.z -= z; this.z -= z;
return this; return this;
} }
/** /**
* Calculates the dot product of this vector with another. The dot product * Calculates the dot product of this vector with another. The dot product
* is defined as x1*x2+y1*y2+z1*z2. The returned value is a scalar. * is defined as x1*x2+y1*y2+z1*z2. The returned value is a scalar.
@@ -230,48 +230,48 @@ public class Vector3 {
public double dot(@NotNull Vector3 other) { public double dot(@NotNull Vector3 other) {
return x * other.getX() + y * other.getY() + z * other.getZ(); return x * other.getX() + y * other.getY() + z * other.getZ();
} }
public Mutable subtract(Vector3 end) { public Mutable subtract(Vector3 end) {
x -= end.getX(); x -= end.getX();
y -= end.getY(); y -= end.getY();
z -= end.getZ(); z -= end.getZ();
return this; return this;
} }
public Mutable multiply(double m) { public Mutable multiply(double m) {
x *= m; x *= m;
y *= m; y *= m;
z *= m; z *= m;
return this; return this;
} }
public Mutable add(double x, double y, double z) { public Mutable add(double x, double y, double z) {
this.x += x; this.x += x;
this.y += y; this.y += y;
this.z += z; this.z += z;
return this; return this;
} }
public Mutable add(Vector3 other) { public Mutable add(Vector3 other) {
this.x += other.getX(); this.x += other.getX();
this.y += other.getY(); this.y += other.getY();
this.z += other.getZ(); this.z += other.getZ();
return this; return this;
} }
public Mutable add(Vector3Int other) { public Mutable add(Vector3Int other) {
this.x += other.getX(); this.x += other.getX();
this.y += other.getY(); this.y += other.getY();
this.z += other.getZ(); this.z += other.getZ();
return this; return this;
} }
public Mutable add(Vector2 other) { public Mutable add(Vector2 other) {
this.x += other.getX(); this.x += other.getX();
this.z += other.getZ(); this.z += other.getZ();
return this; return this;
} }
/** /**
* Rotates the vector around a given arbitrary axis in 3 dimensional space. * Rotates the vector around a given arbitrary axis in 3 dimensional space.
* *
@@ -297,7 +297,7 @@ public class Vector3 {
public Mutable rotateAroundAxis(@NotNull Vector3 axis, double angle) throws IllegalArgumentException { public Mutable rotateAroundAxis(@NotNull Vector3 axis, double angle) throws IllegalArgumentException {
return rotateAroundNonUnitAxis(axis.isNormalized() ? axis : axis.mutable().normalize().immutable(), angle); return rotateAroundNonUnitAxis(axis.isNormalized() ? axis : axis.mutable().normalize().immutable(), angle);
} }
/** /**
* Rotates the vector around a given arbitrary axis in 3 dimensional space. * Rotates the vector around a given arbitrary axis in 3 dimensional space.
* *
@@ -322,11 +322,11 @@ public class Vector3 {
public Mutable rotateAroundNonUnitAxis(@NotNull Vector3 axis, double angle) throws IllegalArgumentException { public Mutable rotateAroundNonUnitAxis(@NotNull Vector3 axis, double angle) throws IllegalArgumentException {
double x = getX(), y = getY(), z = getZ(); double x = getX(), y = getY(), z = getZ();
double x2 = axis.getX(), y2 = axis.getY(), z2 = axis.getZ(); double x2 = axis.getX(), y2 = axis.getY(), z2 = axis.getZ();
double cosTheta = Math.cos(angle); double cosTheta = Math.cos(angle);
double sinTheta = Math.sin(angle); double sinTheta = Math.sin(angle);
double dotProduct = this.dot(axis); double dotProduct = this.dot(axis);
double xPrime = x2 * dotProduct * (1d - cosTheta) double xPrime = x2 * dotProduct * (1d - cosTheta)
+ x * cosTheta + x * cosTheta
+ (-z2 * y + y2 * z) * sinTheta; + (-z2 * y + y2 * z) * sinTheta;
@@ -336,10 +336,10 @@ public class Vector3 {
double zPrime = z2 * dotProduct * (1d - cosTheta) double zPrime = z2 * dotProduct * (1d - cosTheta)
+ z * cosTheta + z * cosTheta
+ (-y2 * x + x2 * y) * sinTheta; + (-y2 * x + x2 * y) * sinTheta;
return setX(xPrime).setY(yPrime).setZ(zPrime); return setX(xPrime).setY(yPrime).setZ(zPrime);
} }
/** /**
* Rotates the vector around the x axis. * Rotates the vector around the x axis.
* <p> * <p>
@@ -357,12 +357,12 @@ public class Vector3 {
public Mutable rotateAroundX(double angle) { public Mutable rotateAroundX(double angle) {
double angleCos = Math.cos(angle); double angleCos = Math.cos(angle);
double angleSin = Math.sin(angle); double angleSin = Math.sin(angle);
double y = angleCos * getY() - angleSin * getZ(); double y = angleCos * getY() - angleSin * getZ();
double z = angleSin * getY() + angleCos * getZ(); double z = angleSin * getY() + angleCos * getZ();
return setY(y).setZ(z); return setY(y).setZ(z);
} }
/** /**
* Rotates the vector around the y axis. * Rotates the vector around the y axis.
* <p> * <p>
@@ -380,12 +380,12 @@ public class Vector3 {
public Mutable rotateAroundY(double angle) { public Mutable rotateAroundY(double angle) {
double angleCos = Math.cos(angle); double angleCos = Math.cos(angle);
double angleSin = Math.sin(angle); double angleSin = Math.sin(angle);
double x = angleCos * getX() + angleSin * getZ(); double x = angleCos * getX() + angleSin * getZ();
double z = -angleSin * getX() + angleCos * getZ(); double z = -angleSin * getX() + angleCos * getZ();
return setX(x).setZ(z); return setX(x).setZ(z);
} }
/** /**
* Rotates the vector around the z axis * Rotates the vector around the z axis
* <p> * <p>
@@ -403,30 +403,30 @@ public class Vector3 {
public Mutable rotateAroundZ(double angle) { public Mutable rotateAroundZ(double angle) {
double angleCos = Math.cos(angle); double angleCos = Math.cos(angle);
double angleSin = Math.sin(angle); double angleSin = Math.sin(angle);
double x = angleCos * getX() - angleSin * getY(); double x = angleCos * getX() - angleSin * getY();
double y = angleSin * getX() + angleCos * getY(); double y = angleSin * getX() + angleCos * getY();
return setX(x).setY(y); return setX(x).setY(y);
} }
@Override @Override
public int hashCode() { public int hashCode() {
int hash = 13; int hash = 13;
hash = 79 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32)); hash = 79 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32));
hash = 79 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32)); hash = 79 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
hash = 79 * hash + (int) (Double.doubleToLongBits(this.z) ^ (Double.doubleToLongBits(this.z) >>> 32)); hash = 79 * hash + (int) (Double.doubleToLongBits(this.z) ^ (Double.doubleToLongBits(this.z) >>> 32));
return hash; return hash;
} }
public int getBlockX() { public int getBlockX() {
return FastMath.floorToInt(x); return FastMath.floorToInt(x);
} }
public int getBlockY() { public int getBlockY() {
return FastMath.floorToInt(y); return FastMath.floorToInt(y);
} }
public int getBlockZ() { public int getBlockZ() {
return FastMath.floorToInt(z); return FastMath.floorToInt(z);
} }
@@ -91,7 +91,7 @@ public class Vector3Int {
this.z += z; this.z += z;
return this; return this;
} }
public Vector3 toVector3() { public Vector3 toVector3() {
return Vector3.of(x, y, z); return Vector3.of(x, y, z);
} }
@@ -105,7 +105,7 @@ public class BufferedWorld implements WritableWorld {
return delegate; return delegate;
} }
public static final class Builder { public static final class Builder {
private final WritableWorld delegate; private final WritableWorld delegate;
private ReadInterceptor readInterceptor; private ReadInterceptor readInterceptor;
@@ -72,20 +72,20 @@ public class Column<T extends WritableWorld> {
return (Column<T>) world.column(x + offsetX, z + offsetZ); return (Column<T>) world.column(x + offsetX, z + offsetZ);
} }
public static class BinaryColumnBuilder { public static class BinaryColumnBuilder {
private final boolean[] arr; private final boolean[] arr;
private final Column<?> column; private final Column<?> column;
public BinaryColumnBuilder(Column<?> column) { public BinaryColumnBuilder(Column<?> column) {
this.column = column; this.column = column;
arr = new boolean[column.getMaxY() - column.getMinY()]; arr = new boolean[column.getMaxY() - column.getMinY()];
} }
public BinaryColumn build() { public BinaryColumn build() {
return new BinaryColumn(column.getMinY(), column.getMaxY(), arr); return new BinaryColumn(column.getMinY(), column.getMaxY(), arr);
} }
public BinaryColumnBuilder set(int y) { public BinaryColumnBuilder set(int y) {
arr[y - column.getMinY()] = true; arr[y - column.getMinY()] = true;
return this; return this;
@@ -18,9 +18,6 @@
package com.dfsek.terra; package com.dfsek.terra;
import com.dfsek.tectonic.api.TypeRegistry; import com.dfsek.tectonic.api.TypeRegistry;
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -49,6 +46,7 @@ import com.dfsek.terra.addon.EphemeralAddon;
import com.dfsek.terra.addon.InternalAddon; import com.dfsek.terra.addon.InternalAddon;
import com.dfsek.terra.api.Platform; import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.BaseAddon; import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.PluginConfig; import com.dfsek.terra.api.config.PluginConfig;
import com.dfsek.terra.api.event.EventManager; import com.dfsek.terra.api.event.EventManager;
@@ -153,26 +151,26 @@ public abstract class AbstractPlatform implements Platform {
protected InternalAddon loadAddons() { protected InternalAddon loadAddons() {
List<BaseAddon> addonList = new ArrayList<>(); List<BaseAddon> addonList = new ArrayList<>();
InternalAddon internalAddon = new InternalAddon(); InternalAddon internalAddon = new InternalAddon();
addonList.add(internalAddon); addonList.add(internalAddon);
platformAddon().forEach(addonList::add); platformAddon().forEach(addonList::add);
BootstrapAddonLoader bootstrapAddonLoader = new BootstrapAddonLoader(); BootstrapAddonLoader bootstrapAddonLoader = new BootstrapAddonLoader();
Path addonsFolder = getDataFolder().toPath().resolve("addons"); Path addonsFolder = getDataFolder().toPath().resolve("addons");
Injector<Platform> platformInjector = new InjectorImpl<>(this); Injector<Platform> platformInjector = new InjectorImpl<>(this);
platformInjector.addExplicitTarget(Platform.class); platformInjector.addExplicitTarget(Platform.class);
BootstrapAddonClassLoader bootstrapAddonClassLoader = new BootstrapAddonClassLoader(new URL[] {}, getClass().getClassLoader()); BootstrapAddonClassLoader bootstrapAddonClassLoader = new BootstrapAddonClassLoader(new URL[]{ }, getClass().getClassLoader());
bootstrapAddonLoader.loadAddons(addonsFolder, bootstrapAddonClassLoader) bootstrapAddonLoader.loadAddons(addonsFolder, bootstrapAddonClassLoader)
.forEach(bootstrapAddon -> { .forEach(bootstrapAddon -> {
platformInjector.inject(bootstrapAddon); platformInjector.inject(bootstrapAddon);
bootstrapAddon.loadAddons(addonsFolder, bootstrapAddonClassLoader) bootstrapAddon.loadAddons(addonsFolder, bootstrapAddonClassLoader)
.forEach(addonList::add); .forEach(addonList::add);
}); });
@@ -183,7 +181,7 @@ public abstract class AbstractPlatform implements Platform {
builder.append("Loading ") builder.append("Loading ")
.append(addonList.size()) .append(addonList.size())
.append(" Terra addons:"); .append(" Terra addons:");
for(BaseAddon addon : addonList) { for(BaseAddon addon : addonList) {
builder.append("\n ") builder.append("\n ")
.append("- ") .append("- ")
@@ -191,10 +189,10 @@ public abstract class AbstractPlatform implements Platform {
.append("@") .append("@")
.append(addon.getVersion().getFormatted()); .append(addon.getVersion().getFormatted());
} }
logger.info(builder.toString()); logger.info(builder.toString());
} }
DependencySorter sorter = new DependencySorter(); DependencySorter sorter = new DependencySorter();
addonList.forEach(sorter::add); addonList.forEach(sorter::add);
sorter.sort().forEach(addon -> { sorter.sort().forEach(addon -> {
@@ -27,7 +27,7 @@ public class InternalAddon implements BaseAddon {
private static final Version VERSION = Versions.getVersion(1, 0, 0); private static final Version VERSION = Versions.getVersion(1, 0, 0);
public InternalAddon() { public InternalAddon() {
} }
@Override @Override
@@ -62,7 +62,7 @@ public class MetaListLikePreprocessor extends MetaPreprocessor<Meta> {
if(!s.startsWith("<< ")) continue; if(!s.startsWith("<< ")) continue;
String meta = s.substring(3); String meta = s.substring(3);
Pair<Configuration, Object> pair = getMetaValue(meta, depthTracker); Pair<Configuration, Object> pair = getMetaValue(meta, depthTracker);
Object metaValue = pair.getRight(); Object metaValue = pair.getRight();
@@ -67,7 +67,7 @@ public class MetaMapPreprocessor extends MetaPreprocessor<Meta> {
depthTracker); depthTracker);
} }
newMap.putAll((Map<?, ?>) meta); newMap.putAll((Map<?, ?>) meta);
String configName; String configName;
if(pair.getLeft().getName() == null) { if(pair.getLeft().getName() == null) {
configName = "Anonymous Configuration"; configName = "Anonymous Configuration";
@@ -44,7 +44,7 @@ public class MetaValuePreprocessor extends MetaPreprocessor<Meta> {
if(value.startsWith("$") // it's a meta value. if(value.startsWith("$") // it's a meta value.
&& !value.startsWith("${")) { // it's not a meta string template. && !value.startsWith("${")) { // it's not a meta string template.
Pair<Configuration, Object> pair = getMetaValue(value.substring(1), depthTracker); Pair<Configuration, Object> pair = getMetaValue(value.substring(1), depthTracker);
String configName; String configName;
if(pair.getLeft().getName() == null) { if(pair.getLeft().getName() == null) {
configName = "Anonymous Configuration"; configName = "Anonymous Configuration";
@@ -68,21 +68,21 @@ public class ProfilerImpl implements Profiler {
if(SAFE.get()) { if(SAFE.get()) {
long time = System.nanoTime(); long time = System.nanoTime();
Stack<Frame> stack = THREAD_STACK.get(); Stack<Frame> stack = THREAD_STACK.get();
Map<String, List<Long>> timingsMap = TIMINGS.get(); Map<String, List<Long>> timingsMap = TIMINGS.get();
if(timingsMap.isEmpty()) { if(timingsMap.isEmpty()) {
synchronized(accessibleThreadMaps) { synchronized(accessibleThreadMaps) {
accessibleThreadMaps.add(timingsMap); accessibleThreadMaps.add(timingsMap);
} }
} }
Frame top = stack.pop(); Frame top = stack.pop();
if(!stack.isEmpty() ? !top.getId().endsWith("." + frame) : !top.getId().equals(frame)) if(!stack.isEmpty() ? !top.getId().endsWith("." + frame) : !top.getId().equals(frame))
throw new MalformedStackException("Expected " + frame + ", found " + top); throw new MalformedStackException("Expected " + frame + ", found " + top);
List<Long> timings = timingsMap.computeIfAbsent(top.getId(), id -> new ArrayList<>()); List<Long> timings = timingsMap.computeIfAbsent(top.getId(), id -> new ArrayList<>());
timings.add(time - top.getStart()); timings.add(time - top.getStart());
} }
if(size.get() == 0) SAFE.set(true); if(size.get() == 0) SAFE.set(true);
@@ -38,11 +38,11 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
*/ */
public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> { public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
private static final Logger logger = LoggerFactory.getLogger(ConfigRegistry.class); private static final Logger logger = LoggerFactory.getLogger(ConfigRegistry.class);
public ConfigRegistry() { public ConfigRegistry() {
super(TypeKey.of(ConfigPack.class)); super(TypeKey.of(ConfigPack.class));
} }
public void load(File folder, Platform platform) throws ConfigException { public void load(File folder, Platform platform) throws ConfigException {
ConfigPack pack = new ConfigPackImpl(folder, platform); ConfigPack pack = new ConfigPackImpl(folder, platform);
register(pack.getRegistryKey(), pack); register(pack.getRegistryKey(), pack);
@@ -60,11 +60,11 @@ public class ProfilerTest {
for(int i = 0; i < 100; i++) { for(int i = 0; i < 100; i++) {
doThing(); doThing();
} }
for(int i = 0; i < 100; i++) { for(int i = 0; i < 100; i++) {
doThirdOtherThing(); doThirdOtherThing();
} }
for(int i = 0; i < 100; i++) { for(int i = 0; i < 100; i++) {
doOtherThing(); doOtherThing();
} }
@@ -76,7 +76,7 @@ public class ProfilerTest {
PROFILER.pop("thing"); PROFILER.pop("thing");
PROFILER.push("thing4"); PROFILER.push("thing4");
PROFILER.pop("thing4"); PROFILER.pop("thing4");
PROFILER.getTimings().forEach((id, timings) -> System.out.println(id + ": " + timings.toString())); PROFILER.getTimings().forEach((id, timings) -> System.out.println(id + ": " + timings.toString()));
} }
} }
@@ -50,7 +50,7 @@ public class RegistryTest {
test.registerChecked(RegistryKey.parse("test:test"), "bazinga2"); test.registerChecked(RegistryKey.parse("test:test"), "bazinga2");
fail("Shouldn't be able to re-register with #registerChecked!"); fail("Shouldn't be able to re-register with #registerChecked!");
} catch(DuplicateEntryException ignore) { } catch(DuplicateEntryException ignore) {
} }
} }
@@ -66,7 +66,7 @@ public class RegistryTest {
test.register(RegistryKey.parse("test:test"), "bazinga2"); test.register(RegistryKey.parse("test:test"), "bazinga2");
fail("Shouldn't be able to re-register in CheckedRegistry!"); fail("Shouldn't be able to re-register in CheckedRegistry!");
} catch(DuplicateEntryException ignore) { } catch(DuplicateEntryException ignore) {
} }
} }
@@ -90,7 +90,7 @@ public class RegistryTest {
test.getByID("test"); test.getByID("test");
fail("Shouldn't be able to get with ambiguous ID!"); fail("Shouldn't be able to get with ambiguous ID!");
} catch(IllegalArgumentException ignore) { } catch(IllegalArgumentException ignore) {
} }
} }
} }
@@ -19,14 +19,12 @@ package com.dfsek.terra.addon;
import ca.solostudios.strata.Versions; import ca.solostudios.strata.Versions;
import ca.solostudios.strata.version.Version; import ca.solostudios.strata.version.Version;
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.nio.file.FileVisitOption; import java.nio.file.FileVisitOption;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@@ -35,6 +33,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.dfsek.terra.addon.exception.AddonLoadException; import com.dfsek.terra.addon.exception.AddonLoadException;
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon; import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
@@ -198,7 +198,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
logger.warn(""" logger.warn("""
You are using Mohist, so we will not give you any support for issues that may arise. You are using Mohist, so we will not give you any support for issues that may arise.
Since you enabled the "IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways" flag, we won't disable Terra. But be warned. Since you enabled the "IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways" flag, we won't disable Terra. But be warned.
> I felt a great disturbance in the JVM, as if millions of plugins suddenly cried out in stack traces and were suddenly silenced. > I felt a great disturbance in the JVM, as if millions of plugins suddenly cried out in stack traces and were suddenly silenced.
> I fear something terrible has happened. > I fear something terrible has happened.
> - Astrash > - Astrash
@@ -18,8 +18,6 @@
package com.dfsek.terra.bukkit.world; package com.dfsek.terra.bukkit.world;
import com.dfsek.terra.api.world.info.WorldProperties;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.TreeType; import org.bukkit.TreeType;
@@ -40,6 +38,7 @@ import com.dfsek.terra.api.inventory.item.Enchantment;
import com.dfsek.terra.api.util.vector.Vector3; import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.ServerWorld; import com.dfsek.terra.api.world.ServerWorld;
import com.dfsek.terra.api.world.chunk.Chunk; import com.dfsek.terra.api.world.chunk.Chunk;
import com.dfsek.terra.api.world.info.WorldProperties;
import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.BukkitEntity; import com.dfsek.terra.bukkit.BukkitEntity;
import com.dfsek.terra.bukkit.BukkitPlayer; import com.dfsek.terra.bukkit.BukkitPlayer;
@@ -17,12 +17,12 @@
package com.dfsek.terra.bukkit.world; package com.dfsek.terra.bukkit.world;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.ServerWorld; import com.dfsek.terra.api.world.ServerWorld;
import com.dfsek.terra.api.world.chunk.Chunk; import com.dfsek.terra.api.world.chunk.Chunk;
import org.jetbrains.annotations.NotNull;
public class BukkitChunk implements Chunk { public class BukkitChunk implements Chunk {
private final org.bukkit.Chunk delegate; private final org.bukkit.Chunk delegate;
@@ -27,11 +27,10 @@ import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
public class BukkitProtoWorld implements ProtoWorld { public class BukkitProtoWorld implements ProtoWorld {
private static final Logger LOGGER = LoggerFactory.getLogger(BukkitProtoWorld.class); private static final Logger LOGGER = LoggerFactory.getLogger(BukkitProtoWorld.class);
private static final AtomicBoolean warn = new AtomicBoolean(true);
private final LimitedRegion delegate; private final LimitedRegion delegate;
private final BlockState air; private final BlockState air;
private static final AtomicBoolean warn = new AtomicBoolean(true);
public BukkitProtoWorld(LimitedRegion delegate, BlockState air) { public BukkitProtoWorld(LimitedRegion delegate, BlockState air) {
this.delegate = delegate; this.delegate = delegate;
this.air = air; this.air = air;
@@ -122,7 +121,7 @@ public class BukkitProtoWorld implements ProtoWorld {
delegate.getCenterChunkX(), delegate.getCenterChunkZ()); delegate.getCenterChunkX(), delegate.getCenterChunkZ());
} else { } else {
LOGGER.debug("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z, LOGGER.debug("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z,
delegate.getCenterChunkX(), delegate.getCenterChunkZ()); delegate.getCenterChunkX(), delegate.getCenterChunkZ());
} }
return Optional.empty(); return Optional.empty();
} }
@@ -49,16 +49,16 @@ public class FabricEntryPoint implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
logger.info("Initializing Terra Fabric mod..."); logger.info("Initializing Terra Fabric mod...");
FabricServerCommandManager<CommandSender> manager = new FabricServerCommandManager<>( FabricServerCommandManager<CommandSender> manager = new FabricServerCommandManager<>(
CommandExecutionCoordinator.simpleCoordinator(), CommandExecutionCoordinator.simpleCoordinator(),
serverCommandSource -> (CommandSender) serverCommandSource, serverCommandSource -> (CommandSender) serverCommandSource,
commandSender -> (ServerCommandSource) commandSender commandSender -> (ServerCommandSource) commandSender
); );
manager.brigadierManager().setNativeNumberSuggestions(false); manager.brigadierManager().setNativeNumberSuggestions(false);
TERRA_PLUGIN.getEventManager().callEvent(new CommandRegistrationEvent(manager)); TERRA_PLUGIN.getEventManager().callEvent(new CommandRegistrationEvent(manager));
} }
} }
@@ -23,15 +23,11 @@ import ca.solostudios.strata.version.Version;
import com.dfsek.tectonic.api.TypeRegistry; import com.dfsek.tectonic.api.TypeRegistry;
import com.dfsek.tectonic.api.depth.DepthTracker; import com.dfsek.tectonic.api.depth.DepthTracker;
import com.dfsek.tectonic.api.exception.LoadException; import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.terra.fabric.util.FabricUtil;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.MinecraftVersion; import net.minecraft.MinecraftVersion;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries; import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome.Category; import net.minecraft.world.biome.Biome.Category;
import net.minecraft.world.biome.Biome.Precipitation; import net.minecraft.world.biome.Biome.Precipitation;
import net.minecraft.world.biome.BiomeEffects.GrassColorModifier; import net.minecraft.world.biome.BiomeEffects.GrassColorModifier;
@@ -53,6 +49,7 @@ import com.dfsek.terra.api.world.biome.PlatformBiome;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper; import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.handle.FabricItemHandle; import com.dfsek.terra.fabric.handle.FabricItemHandle;
import com.dfsek.terra.fabric.handle.FabricWorldHandle; import com.dfsek.terra.fabric.handle.FabricWorldHandle;
import com.dfsek.terra.fabric.util.FabricUtil;
import com.dfsek.terra.fabric.util.ProtoPlatformBiome; import com.dfsek.terra.fabric.util.ProtoPlatformBiome;
@@ -76,7 +73,7 @@ public class PlatformImpl extends AbstractPlatform {
getTerraConfig().load(this); getTerraConfig().load(this);
getRawConfigRegistry().clear(); getRawConfigRegistry().clear();
boolean succeed = getRawConfigRegistry().loadAll(this); boolean succeed = getRawConfigRegistry().loadAll(this);
if(server != null) { if(server != null) {
server.reloadResources(server.getDataPackManager().getNames()).exceptionally(throwable -> { server.reloadResources(server.getDataPackManager().getNames()).exceptionally(throwable -> {
@@ -7,7 +7,6 @@ import net.minecraft.structure.StructureSet;
import net.minecraft.util.dynamic.RegistryOps; import net.minecraft.util.dynamic.RegistryOps;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryCodecs; import net.minecraft.util.registry.RegistryCodecs;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.config.ConfigPack;
@@ -20,11 +20,11 @@ package com.dfsek.terra.fabric.generation;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry; import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource; import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler; import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.config.ConfigPack;
@@ -32,18 +32,14 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.fabric.data.Codecs; import com.dfsek.terra.fabric.data.Codecs;
import com.dfsek.terra.fabric.util.ProtoPlatformBiome; import com.dfsek.terra.fabric.util.ProtoPlatformBiome;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TerraBiomeSource extends BiomeSource { public class TerraBiomeSource extends BiomeSource {
private static final Logger LOGGER = LoggerFactory.getLogger(TerraBiomeSource.class);
private final Registry<net.minecraft.world.biome.Biome> biomeRegistry; private final Registry<net.minecraft.world.biome.Biome> biomeRegistry;
private final long seed; private final long seed;
private ConfigPack pack; private ConfigPack pack;
private static final Logger LOGGER = LoggerFactory.getLogger(TerraBiomeSource.class);
public TerraBiomeSource(Registry<net.minecraft.world.biome.Biome> biomes, long seed, ConfigPack pack) { public TerraBiomeSource(Registry<net.minecraft.world.biome.Biome> biomes, long seed, ConfigPack pack) {
super(StreamSupport super(StreamSupport
.stream(pack.getBiomeProvider() .stream(pack.getBiomeProvider()
@@ -73,7 +69,7 @@ public class TerraBiomeSource extends BiomeSource {
.getBiomeProvider() .getBiomeProvider()
.getBiome(biomeX << 2, biomeZ << 2, seed) .getBiome(biomeX << 2, biomeZ << 2, seed)
.getPlatformBiome()) .getPlatformBiome())
.getDelegate()); .getDelegate());
} }
public BiomeProvider getProvider() { public BiomeProvider getProvider() {
@@ -62,7 +62,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
} }
public void terra$setDelay(int delay) { public void terra$setDelay(int delay) {
} }
public int terra$getMinSpawnDelay() { public int terra$getMinSpawnDelay() {
@@ -70,7 +70,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
} }
public void terra$setMinSpawnDelay(int delay) { public void terra$setMinSpawnDelay(int delay) {
} }
public int terra$getMaxSpawnDelay() { public int terra$getMaxSpawnDelay() {
@@ -78,7 +78,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
} }
public void terra$setMaxSpawnDelay(int delay) { public void terra$setMaxSpawnDelay(int delay) {
} }
public int terra$getSpawnCount() { public int terra$getSpawnCount() {
@@ -86,7 +86,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
} }
public void terra$setSpawnCount(int spawnCount) { public void terra$setSpawnCount(int spawnCount) {
} }
public int terra$getMaxNearbyEntities() { public int terra$getMaxNearbyEntities() {
@@ -94,7 +94,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
} }
public void terra$setMaxNearbyEntities(int maxNearbyEntities) { public void terra$setMaxNearbyEntities(int maxNearbyEntities) {
} }
public int terra$getRequiredPlayerRange() { public int terra$getRequiredPlayerRange() {
@@ -102,7 +102,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
} }
public void terra$setRequiredPlayerRange(int requiredPlayerRange) { public void terra$setRequiredPlayerRange(int requiredPlayerRange) {
} }
public int terra$getSpawnRange() { public int terra$getSpawnRange() {
@@ -110,7 +110,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
} }
public void terra$setSpawnRange(int spawnRange) { public void terra$setSpawnRange(int spawnRange) {
} }
public void terra$applyState(String state) { public void terra$applyState(String state) {
@@ -26,7 +26,6 @@ import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkStatus; import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.tick.MultiTickScheduler; import net.minecraft.world.tick.MultiTickScheduler;
import net.minecraft.world.tick.OrderedTick; import net.minecraft.world.tick.OrderedTick;
import net.minecraft.world.tick.QueryableTickScheduler;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface;
@@ -69,7 +68,7 @@ public abstract class ChunkRegionMixin {
@Shadow @Shadow
@Final @Final
private Chunk centerPos; private Chunk centerPos;
@Shadow @Shadow
@Final @Final
private MultiTickScheduler<Fluid> fluidTickScheduler; private MultiTickScheduler<Fluid> fluidTickScheduler;
@@ -17,15 +17,12 @@
package com.dfsek.terra.fabric.mixin.implementations.world; package com.dfsek.terra.fabric.mixin.implementations.world;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldAccess; import net.minecraft.world.WorldAccess;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic; import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import com.dfsek.terra.api.block.entity.BlockEntity; import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.block.state.BlockState;
@@ -85,7 +82,8 @@ public abstract class ServerWorldMixin {
} }
public ChunkGenerator terra$getGenerator() { public ChunkGenerator terra$getGenerator() {
return ((FabricChunkGeneratorWrapper) ((net.minecraft.server.world.ServerWorld) (Object) this).getChunkManager().getChunkGenerator()).getHandle(); return ((FabricChunkGeneratorWrapper) ((net.minecraft.server.world.ServerWorld) (Object) this).getChunkManager()
.getChunkGenerator()).getHandle();
} }
public BiomeProvider terra$getBiomeProvider() { public BiomeProvider terra$getBiomeProvider() {
@@ -95,7 +93,8 @@ public abstract class ServerWorldMixin {
} }
public ConfigPack terra$getPack() { public ConfigPack terra$getPack() {
net.minecraft.world.gen.chunk.ChunkGenerator generator = (((net.minecraft.server.world.ServerWorld) (Object) this).getChunkManager()).getChunkGenerator(); net.minecraft.world.gen.chunk.ChunkGenerator generator =
(((net.minecraft.server.world.ServerWorld) (Object) this).getChunkManager()).getChunkGenerator();
if(generator instanceof FabricChunkGeneratorWrapper fabricChunkGeneratorWrapper) { if(generator instanceof FabricChunkGeneratorWrapper fabricChunkGeneratorWrapper) {
return fabricChunkGeneratorWrapper.getPack(); return fabricChunkGeneratorWrapper.getPack();
} }
@@ -1,7 +1,6 @@
package com.dfsek.terra.fabric.mixin.lifecycle; package com.dfsek.terra.fabric.mixin.lifecycle;
import net.minecraft.server.DataPackContents; import net.minecraft.server.DataPackContents;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.DynamicRegistryManager; import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -2,7 +2,6 @@ package com.dfsek.terra.fabric.mixin.lifecycle;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@@ -17,28 +17,20 @@
package com.dfsek.terra.fabric.mixin.lifecycle.client; package com.dfsek.terra.fabric.mixin.lifecycle.client;
import com.dfsek.terra.fabric.util.FabricUtil;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs; import net.minecraft.client.RunArgs;
import net.minecraft.client.world.GeneratorType; import net.minecraft.client.world.GeneratorType;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.DynamicRegistryManager.Mutable;
import net.minecraft.util.registry.Registry;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; 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.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent; import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.fabric.FabricEntryPoint; import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.generation.TerraGeneratorType; import com.dfsek.terra.fabric.generation.TerraGeneratorType;
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor; import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
import com.dfsek.terra.fabric.util.FabricUtil;
@Mixin(MinecraftClient.class) @Mixin(MinecraftClient.class)
@@ -17,8 +17,6 @@
package com.dfsek.terra.fabric.mixin.lifecycle.server; package com.dfsek.terra.fabric.mixin.lifecycle.server;
import com.dfsek.terra.api.registry.CheckedRegistry;
import net.minecraft.server.dedicated.ServerPropertiesHandler; import net.minecraft.server.dedicated.ServerPropertiesHandler;
import net.minecraft.structure.StructureSet; import net.minecraft.structure.StructureSet;
import net.minecraft.util.registry.DynamicRegistryManager; import net.minecraft.util.registry.DynamicRegistryManager;
@@ -38,6 +36,7 @@ import java.util.Locale;
import java.util.Random; import java.util.Random;
import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.fabric.FabricEntryPoint; import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.PlatformImpl; import com.dfsek.terra.fabric.PlatformImpl;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper; import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
@@ -17,30 +17,24 @@
package com.dfsek.terra.fabric.mixin.lifecycle.server; package com.dfsek.terra.fabric.mixin.lifecycle.server;
import com.dfsek.terra.fabric.util.FabricUtil;
import net.minecraft.server.Main; import net.minecraft.server.Main;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.DynamicRegistryManager.Mutable;
import net.minecraft.util.registry.Registry;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; 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.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent; import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.fabric.FabricEntryPoint; import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.util.FabricUtil;
@Mixin(Main.class) @Mixin(Main.class)
public class ServerMainMixin { public class ServerMainMixin {
@Inject(method = "main([Ljava/lang/String;)V", @Inject(method = "main([Ljava/lang/String;)V",
at = @At(value = "INVOKE", at = @At(value = "INVOKE",
target = "Lnet/minecraft/resource/ResourcePackManager;<init>(Lnet/minecraft/resource/ResourceType;[Lnet/minecraft/resource/ResourcePackProvider;)V") // after registry manager creation target = "Lnet/minecraft/resource/ResourcePackManager;<init>(Lnet/minecraft/resource/ResourceType;" +
"[Lnet/minecraft/resource/ResourcePackProvider;)V")
// after registry manager creation
) )
private static void injectConstructor(String[] args, CallbackInfo ci) { private static void injectConstructor(String[] args, CallbackInfo ci) {
FabricEntryPoint.getPlatform().getEventManager().callEvent( FabricEntryPoint.getPlatform().getEventManager().callEvent(
@@ -42,7 +42,6 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream;
import com.dfsek.terra.api.block.entity.BlockEntity; import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.block.entity.Container; import com.dfsek.terra.api.block.entity.Container;
@@ -57,6 +56,8 @@ import com.dfsek.terra.fabric.config.VanillaBiomeProperties;
public final class FabricUtil { public final class FabricUtil {
private static final Logger logger = LoggerFactory.getLogger(FabricUtil.class); private static final Logger logger = LoggerFactory.getLogger(FabricUtil.class);
private static final Map<Identifier, List<Identifier>>
TERRA_BIOME_MAP = new HashMap<>();
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) { public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
return pack.getID() return pack.getID()
@@ -71,10 +72,6 @@ public final class FabricUtil {
}); });
} }
private static final Map<Identifier, List<Identifier>>
TERRA_BIOME_MAP = new HashMap<>();
/** /**
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate. * Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
* *
@@ -95,16 +92,21 @@ public final class FabricUtil {
Identifier identifier = new Identifier("terra", FabricUtil.createBiomeID(pack, id)); Identifier identifier = new Identifier("terra", FabricUtil.createBiomeID(pack, id));
if(registry.containsId(identifier)) { if(registry.containsId(identifier)) {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(FabricUtil.getEntry(registry, identifier).orElseThrow().getKey().orElseThrow()); ((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(FabricUtil.getEntry(registry, identifier)
.orElseThrow()
.getKey()
.orElseThrow());
} else { } else {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(BuiltinRegistries.add(registry, registerKey(identifier).getValue(), minecraftBiome).getKey().orElseThrow()); ((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(BuiltinRegistries.add(registry,
registerKey(identifier).getValue(),
minecraftBiome).getKey().orElseThrow());
} }
TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier); TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
} }
} }
private static RegistryKey<net.minecraft.world.biome.Biome> registerKey(Identifier identifier){ private static RegistryKey<net.minecraft.world.biome.Biome> registerKey(Identifier identifier) {
return RegistryKey.of(Registry.BIOME_KEY, identifier); return RegistryKey.of(Registry.BIOME_KEY, identifier);
} }
@@ -130,9 +132,9 @@ public final class FabricUtil {
tag -> collect tag -> collect
.computeIfAbsent(tag, t -> new ArrayList<>()) .computeIfAbsent(tag, t -> new ArrayList<>())
.add(getEntry(registry, .add(getEntry(registry,
terra.getKey() terra.getKey()
.orElseThrow() .orElseThrow()
.getValue()).orElseThrow())); .getValue()).orElseThrow()));
}, },
() -> logger.error("No such biome: {}", tb))), () -> logger.error("No such biome: {}", tb))),
@@ -19,7 +19,6 @@ package com.dfsek.terra.fabric.util;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.util.registry.RegistryKey; import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;