Reformat code

This commit is contained in:
Zoë Gidiere
2023-11-02 18:47:36 -06:00
parent d696e4fd24
commit 81a96d6b76
224 changed files with 1156 additions and 1075 deletions

View File

@@ -7,11 +7,6 @@
package com.dfsek.terra.api;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.PluginConfig;
@@ -23,6 +18,11 @@ import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.io.File;
/**
* Represents a Terra mod/plugin instance.

View File

@@ -7,7 +7,7 @@ import com.dfsek.terra.api.util.vector.Vector3Int;
public final class GeometryUtil {
private GeometryUtil() {
}
public static void sphere(Vector3Int origin, int radius, Consumer<Vector3Int> action) {

View File

@@ -14,11 +14,14 @@ import java.util.List;
* Utility class for mathematical functions.
*/
public final class MathUtil {
/**
* Epsilon for fuzzy floating point comparisons.
*/
public static final double EPSILON = 1.0E-5;
private static final int SIN_BITS, SIN_MASK, SIN_COUNT;
private static final double radFull, radToIndex;
private static final double degFull, degToIndex;
private static final double[] sin, cos;
static {
SIN_BITS = 12;
SIN_MASK = ~(-1 << SIN_BITS);
@@ -32,23 +35,18 @@ public final class MathUtil {
sin = new double[SIN_COUNT];
cos = new double[SIN_COUNT];
for (int i = 0; i < SIN_COUNT; i++) {
for(int i = 0; i < SIN_COUNT; i++) {
sin[i] = Math.sin((i + 0.5f) / SIN_COUNT * radFull);
cos[i] = Math.cos((i + 0.5f) / SIN_COUNT * radFull);
}
// Four cardinal directions (credits: Nate)
for (int i = 0; i < 360; i += 90) {
for(int i = 0; i < 360; i += 90) {
sin[(int) (i * degToIndex) & SIN_MASK] = Math.sin(i * Math.PI / 180.0);
cos[(int) (i * degToIndex) & SIN_MASK] = Math.cos(i * Math.PI / 180.0);
}
}
/**
* Epsilon for fuzzy floating point comparisons.
*/
public static final double EPSILON = 1.0E-5;
public static double sin(double rad) {
return sin[(int) (rad * radToIndex) & SIN_MASK];
}
@@ -114,7 +112,7 @@ public final class MathUtil {
}
public static int normalizeIndex(double val, int size) {
return Math.max(Math.min((int)Math.floor(((val + 1D) / 2D) * size), size - 1), 0);
return Math.max(Math.min((int) Math.floor(((val + 1D) / 2D) * size), size - 1), 0);
}
public static long squash(int first, int last) {

View File

@@ -57,13 +57,15 @@ public class ProbabilityCollection<E> implements Collection<E> {
@SuppressWarnings("unchecked")
public E get(NoiseSampler n, Vector3Int vector3Int, long seed) {
if(array.length == 0) return null;
return (E) array[(int) MathUtil.normalizeIndex(n.noise(seed, vector3Int.getX(), vector3Int.getY(), vector3Int.getZ()), array.length)];
return (E) array[(int) MathUtil.normalizeIndex(n.noise(seed, vector3Int.getX(), vector3Int.getY(), vector3Int.getZ()),
array.length)];
}
@SuppressWarnings("unchecked")
public E get(NoiseSampler n, Vector3 vector3Int, long seed) {
if(array.length == 0) return null;
return (E) array[(int) MathUtil.normalizeIndex(n.noise(seed, vector3Int.getX(), vector3Int.getY(), vector3Int.getZ()), array.length)];
return (E) array[(int) MathUtil.normalizeIndex(n.noise(seed, vector3Int.getX(), vector3Int.getY(), vector3Int.getZ()),
array.length)];
}
@SuppressWarnings("unchecked")

View File

@@ -80,7 +80,7 @@ public final class Either<L, R> {
@Override
public boolean equals(Object obj) {
if(!(obj instanceof Either<?, ?> that)) return false;
return (this.leftPresent && that.leftPresent && Objects.equals(this.left, that.left))
|| (!this.leftPresent && !that.leftPresent && Objects.equals(this.right, that.right));
}

View File

@@ -106,52 +106,52 @@ public final class Pair<L, R> {
return String.format("{%s,%s}", left, right);
}
public static class Mutable<L, R> {
private L left;
private R right;
private Mutable(L left, R right) {
this.left = left;
this.right = right;
}
@NotNull
@Contract("_, _ -> new")
public static <L1, R1> Pair.Mutable<L1, R1> of(L1 left, R1 right) {
return new Mutable<>(left, right);
}
@Contract("-> new")
public Pair<L, R> immutable() {
return Pair.of(left, right);
}
public L getLeft() {
return left;
}
public void setLeft(L left) {
this.left = left;
}
public R getRight() {
return right;
}
public void setRight(R right) {
this.right = right;
}
@Override
public int hashCode() {
return Objects.hash(left, right);
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof Mutable<?, ?> that)) return false;
return Objects.equals(this.left, that.left) && Objects.equals(this.right, that.right);
}
}

View File

@@ -73,7 +73,7 @@ public final class ReflectionUtil {
public static String typeToString(Type type) {
return type instanceof Class ? ((Class<?>) type).getName() : type.toString();
}
public static boolean equals(Type a, Type b) {
if(a == b) {
return true;

View File

@@ -28,6 +28,7 @@ public class Vector2 {
this.x = x;
this.z = z;
}
public static Vector2 zero() {
return ZERO;
}

View File

@@ -66,29 +66,29 @@ public class Vector2Int {
return false;
}
public static class Mutable extends Vector2Int {
protected Mutable(int x, int z) {
super(x, z);
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public Vector2Int immutable() {
return new Vector2Int(x, z);
}

View File

@@ -22,6 +22,7 @@ public class Vector3 {
this.y = y;
this.z = z;
}
public static Vector3 zero() {
return ZERO;
}

View File

@@ -30,12 +30,12 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
.initialCapacity(98304)
.maximumSize(98304) // 1 full chunk (high res)
.build(vec -> delegate.getBiome(vec.x * res, vec.y * res, vec.z * res, vec.seed));
this.baseCache = Caffeine
.newBuilder()
.maximumSize(256) // 1 full chunk (high res)
.build(vec -> delegate.getBaseBiome(vec.x * res, vec.z * res, vec.seed));
}
@Override
@@ -80,8 +80,8 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
return 31 * code + ((int) (seed ^ (seed >>> 32)));
}
}
private record SeededVector2(int x, int z, long seed) {
@Override
public boolean equals(Object obj) {

View File

@@ -86,17 +86,17 @@ public class ColumnTest {
public int getMaxY() {
return max;
}
@Override
public int getX() {
return 0;
}
@Override
public int getZ() {
return 0;
}
@Override
public T get(int y) {
return p.apply(y);