reformat all code

This commit is contained in:
dfsek
2022-03-30 14:43:50 -07:00
parent d79c37fc49
commit 4a3c22a8d6
201 changed files with 925 additions and 1040 deletions

View File

@@ -28,6 +28,7 @@ public interface BaseAddon extends StringIdentifiable, Namespaced {
/**
* Gets the dependencies of this addon.
*
* @return Map of dependency ID to {@link VersionRange} of dependency
*/
default Map<String, VersionRange> getDependencies() {
@@ -36,6 +37,7 @@ public interface BaseAddon extends StringIdentifiable, Namespaced {
/**
* Get the version of the addon
*
* @return Version of addon
*/
Version getVersion();

View File

@@ -14,12 +14,13 @@ import com.dfsek.terra.api.addon.BaseAddon;
/**
* Interface representing a bootstrap addon.
*
* <p>
* A bootstrap addon is the only type of addon Terra implements a loader for.
* It is a minimal base for addon loaders to be implemented on top of.
*
* <p>
* Unless you are writing your own addon loader, you will want to depend on the
* {@code manifest-addon-loader} addon, and implement its AddonInitializer.
*
* @param <T> Type of addon this bootstrap addon loads
*/
public interface BootstrapBaseAddon<T extends BaseAddon> extends BaseAddon {

View File

@@ -17,18 +17,21 @@ import com.dfsek.terra.api.block.state.BlockState;
public interface BlockType extends Handle {
/**
* Get the default {@link BlockState} of this block
*
* @return Default block state
*/
BlockState getDefaultState();
/**
* Get whether this block is solid.
*
* @return Whether this block is solid.
*/
boolean isSolid();
/**
* Get whether this block is water.
*
* @return Whether this block is water.
*/
boolean isWater();

View File

@@ -21,39 +21,49 @@ public interface BlockState extends Handle {
/**
* Whether this {@link BlockState} matches another.
*
* <p>
* "matches" is defined as this {@link BlockState} holding a matching {@link #getBlockType()}.
*
* @param other Other {@link BlockState}
*
* @return Whether this state matches the other
*/
boolean matches(BlockState other);
/**
* Check whether this {@link BlockState} has a {@link Property}.
*
* @param property Property to check for
*
* @return Whether this state has the property.
*/
<T extends Comparable<T>> boolean has(Property<T> property);
/**
* Get the value of a {@link Property} on this state.
*
* @param property Property to get
*
* @return Value of the property
*/
<T extends Comparable<T>> T get(Property<T> property);
/**
* Return a new {@link BlockState} with a {@link Property} set to a value.
*
* @param property Property to set
* @param value Value of property
* @param value Value of property
*
* @return New {@link BlockState} with property set.
*/
<T extends Comparable<T>> BlockState set(Property<T> property, T value);
/**
* Perform an action on this {@link BlockState} if it contains a {@link Property}
*
* @param property Property to check for
* @param action Action to perform if property is present
* @param action Action to perform if property is present
*
* @return This {@link BlockState}
*/
default <T extends Comparable<T>> BlockState ifProperty(Property<T> property, Consumer<BlockState> action) {
@@ -63,8 +73,10 @@ public interface BlockState extends Handle {
/**
* Set the value of a {@link Property} on this {@link BlockState} if it is present.
*
* @param property Property to check for/set.
* @param value Value to set if property is present.
* @param value Value to set if property is present.
*
* @return Thie {@link BlockState}
*/
default <T extends Comparable<T>> BlockState setIfPresent(Property<T> property, T value) {
@@ -74,12 +86,14 @@ public interface BlockState extends Handle {
/**
* Get the {@link BlockType} this state applies to.
*
* @return Block type.
*/
BlockType getBlockType();
/**
* Get this state and its properties as a String
*
* @return String representation of this state
*/
default String getAsString() {
@@ -88,13 +102,16 @@ public interface BlockState extends Handle {
/**
* Get this state and its properties as a String
*
* @param properties Whether to include properties
*
* @return String representation of this state
*/
String getAsString(boolean properties);
/**
* Get whether this BlockState is air
*
* @return Whether this state is air
*/
boolean isAir();

View File

@@ -7,10 +7,10 @@
package com.dfsek.terra.api.block.state.properties;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import java.util.Collection;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
/**
* Represents a property a state holds
@@ -18,12 +18,14 @@ import java.util.Collection;
public interface Property<T> extends StringIdentifiable {
/**
* Get all possible values of this property
*
* @return All values of this property
*/
Collection<T> values();
/**
* Get the type of this property.
*
* @return {@link Class} instance representing the type of this property
*/
Class<T> getType();

View File

@@ -14,6 +14,7 @@ import com.dfsek.terra.api.block.state.properties.enums.RailShape;
import com.dfsek.terra.api.block.state.properties.enums.RedstoneConnection;
import com.dfsek.terra.api.block.state.properties.enums.WallHeight;
@Deprecated
public final class Properties {
public static final EnumProperty<Direction> DIRECTION = EnumProperty.of("facing", Direction.class);

View File

@@ -7,12 +7,12 @@
package com.dfsek.terra.api.command;
import java.util.Optional;
import com.dfsek.terra.api.Handle;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.Player;
import java.util.Optional;
public interface CommandSender extends Handle {
void sendMessage(String message);

View File

@@ -5,16 +5,6 @@ import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.context.CommandContext;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.registry.exception.NoSuchEntryException;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.util.reflection.TypeKey;
import io.leangen.geantyref.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -26,6 +16,11 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.registry.exception.NoSuchEntryException;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.util.reflection.TypeKey;
public class RegistryArgument<T, R> extends CommandArgument<T, R> {
private RegistryArgument(
@@ -63,19 +58,23 @@ public class RegistryArgument<T, R> extends CommandArgument<T, R> {
}
@SuppressWarnings("unchecked")
public static <T, R> Builder<T, R> builder(String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeKey<R> registryType) {
public static <T, R> Builder<T, R> builder(String name, Function<CommandContext<T>, Registry<R>> registryFunction,
TypeKey<R> registryType) {
return new Builder<>(name, registryFunction, (TypeToken<R>) TypeToken.get(registryType.getType()));
}
public static <T, R> CommandArgument<T, R> of(String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeKey<R> registryType) {
public static <T, R> CommandArgument<T, R> of(String name, Function<CommandContext<T>, Registry<R>> registryFunction,
TypeKey<R> registryType) {
return RegistryArgument.<T, R>builder(name, registryFunction, registryType).build();
}
public static <T, R> CommandArgument<T, R> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeKey<R> registryType) {
public static <T, R> CommandArgument<T, R> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction,
TypeKey<R> registryType) {
return RegistryArgument.builder(name, registryFunction, registryType).asOptional().build();
}
public static <T, R> CommandArgument<T, R> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeKey<R> registryType, String defaultKey) {
public static <T, R> CommandArgument<T, R> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction,
TypeKey<R> registryType, String defaultKey) {
return RegistryArgument.builder(name, registryFunction, registryType).asOptionalWithDefault(defaultKey).build();
}
@@ -89,7 +88,7 @@ public class RegistryArgument<T, R> extends CommandArgument<T, R> {
this.registryFunction = commandContext -> registry;
this.typeToken = (TypeToken<R>) TypeToken.get(registry.getType().getType());
}
private Builder(@NonNull String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeToken<R> typeToken) {
super(typeToken, name);
this.typeToken = typeToken;

View File

@@ -15,11 +15,9 @@ import java.util.Map;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.properties.PropertyHolder;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.registry.meta.CheckedRegistryHolder;
import com.dfsek.terra.api.registry.meta.RegistryHolder;
import com.dfsek.terra.api.registry.meta.RegistryProvider;
import com.dfsek.terra.api.tectonic.ConfigLoadingDelegate;
import com.dfsek.terra.api.tectonic.LoaderRegistrar;

View File

@@ -7,10 +7,7 @@
package com.dfsek.terra.api.config;
import java.util.function.Supplier;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.registry.OpenRegistry;
import com.dfsek.terra.api.util.reflection.TypeKey;

View File

@@ -9,8 +9,8 @@ package com.dfsek.terra.api.noise;
import com.dfsek.terra.api.util.vector.Vector2;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector2Int;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3Int;

View File

@@ -7,12 +7,11 @@
package com.dfsek.terra.api.registry;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
public interface CheckedRegistry<T> extends Registry<T> {

View File

@@ -7,12 +7,11 @@
package com.dfsek.terra.api.registry;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
public interface OpenRegistry<T> extends Registry<T> {

View File

@@ -8,10 +8,6 @@
package com.dfsek.terra.api.registry;
import com.dfsek.tectonic.api.loader.type.TypeLoader;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.util.reflection.TypeKey;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@@ -23,6 +19,9 @@ import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.util.reflection.TypeKey;
public interface Registry<T> extends TypeLoader<T> {
/**

View File

@@ -15,7 +15,7 @@ public final class RegistryKey implements StringIdentifiable, Namespaced {
"Namespace must only contain alphanumeric characters, hyphens, and underscores. \"" + namespace +
"\" is not a valid namespace.");
}
if(!ID_PATTERN.matcher(id).matches()) {
throw new IllegalArgumentException(
"ID must only contain alphanumeric characters, hyphens, and underscores. \"" + id +

View File

@@ -1,10 +1,10 @@
package com.dfsek.terra.api.registry.meta;
import java.lang.reflect.Type;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.util.reflection.TypeKey;
import java.lang.reflect.Type;
public interface CheckedRegistryHolder extends RegistryHolder {
default <T> CheckedRegistry<T> getCheckedRegistry(Class<T> clazz) throws IllegalStateException {

View File

@@ -9,9 +9,7 @@ package com.dfsek.terra.api.structure;
import java.util.Random;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import com.dfsek.terra.api.util.vector.Vector3Int;
import com.dfsek.terra.api.world.WritableWorld;

View File

@@ -9,10 +9,10 @@ package com.dfsek.terra.api.structure.configured;
import org.jetbrains.annotations.ApiStatus.Experimental;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.structure.StructureSpawn;
import com.dfsek.terra.api.util.Range;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import com.dfsek.terra.api.util.collection.ProbabilityCollection;

View File

@@ -7,11 +7,8 @@
package com.dfsek.terra.api.structure.feature;
import java.util.ArrayList;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.function.IntConsumer;
import java.util.stream.IntStream;
import com.dfsek.terra.api.util.Range;
import com.dfsek.terra.api.util.function.IntToBooleanFunction;
@@ -22,16 +19,15 @@ import com.dfsek.terra.api.util.generic.Lazy;
* A column of binary data
*/
public class BinaryColumn {
private static final BinaryColumn NULL = new BinaryColumn(0, 1, y -> false);
private final IntToBooleanFunction data;
private final int minY;
private final int maxY;
private final Lazy<boolean[]> results;
private static final BinaryColumn NULL = new BinaryColumn(0, 1, y -> false);
/**
* Constructs a new {@link BinaryColumn} with all values initiated to {@code false}
*
* @param minY Minimum Y value
* @param maxY Maximum Y value
*/
@@ -57,17 +53,19 @@ public class BinaryColumn {
this.data = y -> data[y - minY];
}
public static BinaryColumn getNull() {
return NULL;
}
public BinaryColumn(Range y, IntToBooleanFunction data) {
this(y.getMin(), y.getMax(), data);
}
public static BinaryColumn getNull() {
return NULL;
}
/**
* Get the value at a height.
*
* @param y Height of entry to get.
*
* @return Whether height has been set.
*/
public boolean get(int y) {
@@ -81,6 +79,7 @@ public class BinaryColumn {
/**
* Perform an action for all heights which have been set.
*
* @param consumer Action to perform
*/
public void forEach(IntConsumer consumer) {
@@ -94,7 +93,9 @@ public class BinaryColumn {
/**
* Return a {@link BinaryColumn} of equal height with a boolean AND operation applied to each height.
*
* @param that Other binary column, must match this column's height.
*
* @return Merged column.
*
* @throws IllegalArgumentException if column heights do not match
@@ -105,7 +106,9 @@ public class BinaryColumn {
/**
* Return a {@link BinaryColumn} of equal height with a boolean OR operation applied to each height.
*
* @param that Other binary column, must match this column's height.
*
* @return Merged column.
*
* @throws IllegalArgumentException if column heights do not match
@@ -121,7 +124,7 @@ public class BinaryColumn {
private BinaryColumn bool(BinaryColumn that, BooleanBinaryOperator operator) {
int smallMinY = Math.min(this.minY, that.minY);
int bigMaxY = Math.max(this.maxY, that.maxY);
return new BinaryColumn(smallMinY, bigMaxY, y -> operator.apply(() -> this.get(y), () -> that.get(y)));
}

View File

@@ -7,8 +7,8 @@
package com.dfsek.terra.api.structure.feature;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.world.WritableWorld;

View File

@@ -1,9 +1,9 @@
package com.dfsek.terra.api.util;
import com.dfsek.terra.api.util.vector.Vector3Int;
import java.util.function.Consumer;
import com.dfsek.terra.api.util.vector.Vector3Int;
public final class GeometryUtil {
private GeometryUtil() {

View File

@@ -9,7 +9,6 @@ package com.dfsek.terra.api.util.collection;
import java.io.Serial;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.NoSuchElementException;

View File

@@ -7,9 +7,6 @@
package com.dfsek.terra.api.util.collection;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3Int;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@@ -25,6 +22,8 @@ import java.util.function.Function;
import com.dfsek.terra.api.noise.NoiseSampler;
import com.dfsek.terra.api.util.MathUtil;
import com.dfsek.terra.api.util.mutable.MutableInteger;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3Int;
public class ProbabilityCollection<E> implements Collection<E> {

View File

@@ -35,7 +35,6 @@ public class Vector2 {
}
/**
* Get the length of this Vector
*
@@ -127,34 +126,40 @@ public class Vector2 {
return new Mutable(x, z);
}
@Override
public String toString() {
return "(" + x + ", " + z + ")";
}
public static class Mutable extends Vector2 {
private Mutable(double x, double z) {
super(x, z);
}
public double getX() {
return x;
}
public double getZ() {
return z;
}
public Vector2 immutable() {
return Vector2.of(x, z);
}
public Mutable setX(double x) {
this.x = x;
return this;
}
public double getZ() {
return z;
}
public Mutable setZ(double z) {
this.z = z;
return this;
}
public Vector2 immutable() {
return Vector2.of(x, z);
}
/**
* Get the length of this Vector
*
@@ -163,7 +168,7 @@ public class Vector2 {
public double length() {
return FastMath.sqrt(lengthSquared());
}
/**
* Get the squared length of this Vector
*
@@ -172,13 +177,13 @@ public class Vector2 {
public double lengthSquared() {
return x * x + z * z;
}
public Mutable add(double x, double z) {
this.x += x;
this.z += z;
return this;
}
/**
* Multiply X and Z components by a value.
*
@@ -191,7 +196,7 @@ public class Vector2 {
z *= m;
return this;
}
/**
* Add this vector to another.
*
@@ -204,7 +209,7 @@ public class Vector2 {
z += other.getZ();
return this;
}
/**
* Subtract a vector from this vector,
*
@@ -217,7 +222,7 @@ public class Vector2 {
z -= other.getZ();
return this;
}
/**
* Normalize this vector to length 1
*
@@ -227,7 +232,7 @@ public class Vector2 {
divide(length());
return this;
}
/**
* Divide X and Z components by a value.
*
@@ -241,9 +246,4 @@ public class Vector2 {
return this;
}
}
@Override
public String toString() {
return "(" + x + ", " + z + ")";
}
}

View File

@@ -54,33 +54,6 @@ public class Vector2Int {
};
}
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);
}
}
@Override
public int hashCode() {
return (31 * x) + z;
@@ -93,4 +66,32 @@ 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

@@ -150,69 +150,75 @@ public class Vector3 {
return new Mutable(x, y, z);
}
@Override
public String toString() {
return "(" + getX() + ", " + getY() + ", " + getZ() + ")";
}
public static class Mutable extends Vector3 {
private Mutable(double x, double y, double z) {
super(x, y, z);
}
public static Mutable of(double x, double y, double z) {
return new Mutable(x, y, z);
}
public Vector3 immutable() {
return Vector3.of(x, y, z);
}
public double getZ() {
return z;
}
public Mutable setZ(double z) {
this.z = z;
return this;
}
public double getX() {
return x;
}
public Mutable setX(double x) {
this.x = x;
return this;
}
public double getY() {
return y;
}
public Mutable setY(double y) {
this.y = y;
return this;
}
public double lengthSquared() {
return x * x + y * y + z * z;
}
public double length() {
return FastMath.sqrt(lengthSquared());
}
public double inverseLength() {
return FastMath.invSqrtQuick(lengthSquared());
}
public Mutable normalize() {
return this.multiply(this.inverseLength());
}
public Mutable subtract(int x, int y, int z) {
this.x -= x;
this.y -= y;
this.z -= z;
return this;
}
/**
* 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.
@@ -224,48 +230,48 @@ public class Vector3 {
public double dot(@NotNull Vector3 other) {
return x * other.getX() + y * other.getY() + z * other.getZ();
}
public Mutable subtract(Vector3 end) {
x -= end.getX();
y -= end.getY();
z -= end.getZ();
return this;
}
public Mutable multiply(double m) {
x *= m;
y *= m;
z *= m;
return this;
}
public Mutable add(double x, double y, double z) {
this.x += x;
this.y += y;
this.z += z;
return this;
}
public Mutable add(Vector3 other) {
this.x += other.getX();
this.y += other.getY();
this.z += other.getZ();
return this;
}
public Mutable add(Vector3Int other) {
this.x += other.getX();
this.y += other.getY();
this.z += other.getZ();
return this;
}
public Mutable add(Vector2 other) {
this.x += other.getX();
this.z += other.getZ();
return this;
}
/**
* Rotates the vector around a given arbitrary axis in 3 dimensional space.
*
@@ -291,7 +297,7 @@ public class Vector3 {
public Mutable rotateAroundAxis(@NotNull Vector3 axis, double angle) throws IllegalArgumentException {
return rotateAroundNonUnitAxis(axis.isNormalized() ? axis : axis.mutable().normalize().immutable(), angle);
}
/**
* Rotates the vector around a given arbitrary axis in 3 dimensional space.
*
@@ -316,11 +322,11 @@ public class Vector3 {
public Mutable rotateAroundNonUnitAxis(@NotNull Vector3 axis, double angle) throws IllegalArgumentException {
double x = getX(), y = getY(), z = getZ();
double x2 = axis.getX(), y2 = axis.getY(), z2 = axis.getZ();
double cosTheta = Math.cos(angle);
double sinTheta = Math.sin(angle);
double dotProduct = this.dot(axis);
double xPrime = x2 * dotProduct * (1d - cosTheta)
+ x * cosTheta
+ (-z2 * y + y2 * z) * sinTheta;
@@ -330,10 +336,10 @@ public class Vector3 {
double zPrime = z2 * dotProduct * (1d - cosTheta)
+ z * cosTheta
+ (-y2 * x + x2 * y) * sinTheta;
return setX(xPrime).setY(yPrime).setZ(zPrime);
}
/**
* Rotates the vector around the x axis.
* <p>
@@ -351,12 +357,12 @@ public class Vector3 {
public Mutable rotateAroundX(double angle) {
double angleCos = Math.cos(angle);
double angleSin = Math.sin(angle);
double y = angleCos * getY() - angleSin * getZ();
double z = angleSin * getY() + angleCos * getZ();
return setY(y).setZ(z);
}
/**
* Rotates the vector around the y axis.
* <p>
@@ -374,12 +380,12 @@ public class Vector3 {
public Mutable rotateAroundY(double angle) {
double angleCos = Math.cos(angle);
double angleSin = Math.sin(angle);
double x = angleCos * getX() + angleSin * getZ();
double z = -angleSin * getX() + angleCos * getZ();
return setX(x).setZ(z);
}
/**
* Rotates the vector around the z axis
* <p>
@@ -397,37 +403,32 @@ public class Vector3 {
public Mutable rotateAroundZ(double angle) {
double angleCos = Math.cos(angle);
double angleSin = Math.sin(angle);
double x = angleCos * getX() - angleSin * getY();
double y = angleSin * getX() + angleCos * getY();
return setX(x).setY(y);
}
@Override
public int hashCode() {
int hash = 13;
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.z) ^ (Double.doubleToLongBits(this.z) >>> 32));
return hash;
}
public int getBlockX() {
return FastMath.floorToInt(x);
}
public int getBlockY() {
return FastMath.floorToInt(y);
}
public int getBlockZ() {
return FastMath.floorToInt(z);
}
}
@Override
public String toString() {
return "(" + getX() + ", " + getY() + ", " + getZ() + ")";
}
}

View File

@@ -91,7 +91,7 @@ public class Vector3Int {
this.z += z;
return this;
}
public Vector3 toVector3() {
return Vector3.of(x, y, z);
}

View File

@@ -37,6 +37,10 @@ public class BufferedWorld implements WritableWorld {
this.writeInterceptor = writeInterceptor;
}
protected static Builder builder(WritableWorld world) {
return new Builder(world);
}
@Override
public Object getHandle() {
return delegate.getHandle();
@@ -101,6 +105,7 @@ public class BufferedWorld implements WritableWorld {
return delegate;
}
public static final class Builder {
private final WritableWorld delegate;
private ReadInterceptor readInterceptor;
@@ -155,8 +160,4 @@ public class BufferedWorld implements WritableWorld {
Objects.requireNonNullElse(writeInterceptor, Interceptors.writeThrough()));
}
}
protected static Builder builder(WritableWorld world) {
return new Builder(world);
}
}

View File

@@ -12,16 +12,20 @@ import com.dfsek.terra.api.util.vector.Vector3Int;
public interface ReadableWorld extends World {
/**
* Get the {@link BlockState} at a location.
*
* @param x X coordinate
* @param y Y coordinate
* @param z Z coordinate
*
* @return {@link BlockState} at coordinates.
*/
BlockState getBlockState(int x, int y, int z);
/**
* Get the {@link BlockState} at a location.
*
* @param position Location to get block.
*
* @return {@link BlockState} at coordinates.
*/
default BlockState getBlockState(Vector3 position) {
@@ -30,7 +34,9 @@ public interface ReadableWorld extends World {
/**
* Get the {@link BlockState} at a location.
*
* @param position Location to get block.
*
* @return {@link BlockState} at coordinates.
*/
default BlockState getBlockState(Vector3Int position) {

View File

@@ -12,18 +12,21 @@ import com.dfsek.terra.api.world.info.WorldProperties;
public interface World extends WorldProperties {
/**
* Get the {@link ChunkGenerator} this world uses.
*
* @return Chunk generator.
*/
ChunkGenerator getGenerator();
/**
* Get the {@link BiomeProvider} this world uses.
*
* @return Biome provider.
*/
BiomeProvider getBiomeProvider();
/**
* Get the {@link ConfigPack} this world uses.
*
* @return Config pack.
*/
ConfigPack getPack();

View File

@@ -28,12 +28,14 @@ public interface Biome extends PropertyHolder, StringIdentifiable {
/**
* Get the color of this biome.
*
* @return ARGB color of this biome
*/
int getColor();
/**
* Get the tags this biome holds
*
* @return A {@link Set} of String tags this biome holds.
*/
Set<String> getTags();

View File

@@ -1,16 +1,16 @@
package com.dfsek.terra.api.world.biome.generation;
import java.util.HashMap;
import java.util.Map;
import com.dfsek.terra.api.Handle;
import com.dfsek.terra.api.util.MathUtil;
import com.dfsek.terra.api.world.biome.Biome;
import java.util.HashMap;
import java.util.Map;
/**
* A biome provider implementation that lazily evaluates biomes, and caches them.
*
* <p>
* This is for use in chunk generators, it makes the assumption that <b>the seed remains the same for the duration of its use!</b>
*/
public class CachingBiomeProvider implements BiomeProvider, Handle {

View File

@@ -7,15 +7,14 @@
package com.dfsek.terra.api.world.chunk.generation;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
import com.dfsek.terra.api.world.info.WorldProperties;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3Int;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
import com.dfsek.terra.api.world.info.WorldProperties;
public interface ChunkGenerator {

View File

@@ -67,27 +67,28 @@ public class Column<T extends WritableWorld> {
return new BinaryColumnBuilder(this);
}
@SuppressWarnings("unchecked")
public Column<T> adjacent(int offsetX, int offsetZ) {
return (Column<T>) world.column(x + offsetX, z + offsetZ);
}
public static class BinaryColumnBuilder {
private final boolean[] arr;
private final Column<?> column;
public BinaryColumnBuilder(Column<?> column) {
this.column = column;
arr = new boolean[column.getMaxY() - column.getMinY()];
}
public BinaryColumn build() {
return new BinaryColumn(column.getMinY(), column.getMaxY(), arr);
}
public BinaryColumnBuilder set(int y) {
arr[y - column.getMinY()] = true;
return this;
}
}
@SuppressWarnings("unchecked")
public Column<T> adjacent(int offsetX, int offsetZ) {
return (Column<T>) world.column(x + offsetX, z + offsetZ);
}
}

View File

@@ -8,8 +8,6 @@
package com.dfsek.terra.api.world.chunk.generation.util;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.noise.NoiseSampler;
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
public interface Palette {

View File

@@ -2,9 +2,11 @@ package com.dfsek.terra.api.world.util;
public final class Interceptors {
private static final ReadInterceptor READ_THROUGH = ((x, y, z, world) -> world.getBlockState(x, y, z));
private static final WriteInterceptor WRITE_THROUGH = ((x, y, z, block, world, physics) -> world.setBlockState(x, y, z, block, physics));
private static final WriteInterceptor WRITE_THROUGH = ((x, y, z, block, world, physics) -> world.setBlockState(x, y, z, block,
physics));
private Interceptors() {
}
public static ReadInterceptor readThrough() {