Merge remote-tracking branch 'upstream/ver/6.0.0' into architecture/slf4j-logging

# Conflicts:
#	common/api/util/src/main/java/com/dfsek/terra/api/util/Logger.java
#	common/implementation/src/main/java/com/dfsek/terra/AbstractTerraPlugin.java
#	common/implementation/src/main/java/com/dfsek/terra/config/PluginConfigImpl.java
#	common/implementation/src/main/java/com/dfsek/terra/config/lang/LangUtil.java
#	common/implementation/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java
#	common/implementation/src/main/java/com/dfsek/terra/util/logging/DebugLogger.java
#	common/implementation/src/main/java/com/dfsek/terra/util/logging/JavaLogger.java
#	platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraPluginImpl.java
#	platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraPluginImpl.java
#	platforms/sponge/src/main/java/com/dfsek/terra/sponge/TerraPluginImpl.java
This commit is contained in:
solonovamax
2021-09-25 00:42:09 -04:00
141 changed files with 205 additions and 161 deletions

View File

@@ -1,5 +1,6 @@
dependencies {
"shadedApi"(project(":common:api:util"))
"shadedApi"(project(":common:api:noise"))
"shadedApi"("com.dfsek:Paralithic:0.5.0")

View File

@@ -1,5 +0,0 @@
package com.dfsek.terra.api;
public interface StringIdentifiable {
String getID();
}

View File

@@ -13,6 +13,7 @@ import com.dfsek.terra.api.profiler.Profiler;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
import com.dfsek.terra.api.util.Logger;
/**

View File

@@ -2,7 +2,7 @@ package com.dfsek.terra.api.block.entity;
import com.dfsek.terra.api.Handle;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
public interface BlockEntity extends Handle {

View File

@@ -2,7 +2,7 @@ package com.dfsek.terra.api.config;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.terra.api.StringIdentifiable;
import com.dfsek.terra.api.util.StringIdentifiable;
public interface AbstractableTemplate extends ConfigTemplate, StringIdentifiable {

View File

@@ -5,7 +5,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import com.dfsek.terra.api.StringIdentifiable;
import com.dfsek.terra.api.util.StringIdentifiable;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.meta.RegistryFactory;

View File

@@ -2,7 +2,7 @@ package com.dfsek.terra.api.config;
import java.util.Map;
import com.dfsek.terra.api.StringIdentifiable;
import com.dfsek.terra.api.util.StringIdentifiable;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.api.entity;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.World;

View File

@@ -8,7 +8,7 @@ import com.dfsek.terra.api.event.events.AbstractCancellable;
import com.dfsek.terra.api.event.events.PackEvent;
import com.dfsek.terra.api.structure.LootTable;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
/**

View File

@@ -5,7 +5,7 @@ import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.util.generic.pair.Pair;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
/**

View File

@@ -1,40 +0,0 @@
package com.dfsek.terra.api.injection;
import com.dfsek.terra.api.injection.annotations.Inject;
import com.dfsek.terra.api.injection.exception.InjectionException;
/**
* Dynamic dependency injector.
* <p>
* Stores an object to inject, and injects it into objects passed to {@link #inject(Object)}.
*
* @param <T> Type of object to inject.
*/
public interface Injector<T> {
/**
* Add an explicit class as a target. Useful for applications where subclasses may cause issues with DI.
*
* @param target Target class type.
*/
void addExplicitTarget(Class<? extends T> target);
/**
* Inject the stored object into an object.
* <p>
* Injects the stored object into any non-static, non-final fields
* annotated with {@link Inject},
* with type matching the stored object or any explicit targets
* ({@link #addExplicitTarget(Class)}.
*
* @param object Object to inject into
*
* @throws InjectionException If:
* <ul>
* <li>Matching field annotated with {@link Inject} is final</li>
* <li>Matching field annotated with {@link Inject} is static</li>
* <li>A reflective access exception occurs</li>
* </ul>
*/
void inject(Object object) throws InjectionException;
}

View File

@@ -1,15 +0,0 @@
package com.dfsek.terra.api.injection.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Specifies that a field is a target for dependency injection.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Inject {
}

View File

@@ -1,19 +0,0 @@
package com.dfsek.terra.api.injection.exception;
import com.dfsek.terra.api.injection.Injector;
/**
* Thrown when dynamic dependency injection cannot be completed by an {@link Injector}.
*/
public class InjectionException extends Exception {
private static final long serialVersionUID = -6929631447064215387L;
public InjectionException(String message) {
super(message);
}
public InjectionException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.api.inventory;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
public interface BlockInventoryHolder extends InventoryHolder {

View File

@@ -1,34 +0,0 @@
package com.dfsek.terra.api.noise;
import com.dfsek.terra.api.vector.Vector2;
import com.dfsek.terra.api.vector.Vector3;
public interface NoiseSampler {
static NoiseSampler zero() {
return new NoiseSampler() {
@Override
public double getNoiseSeeded(long seed, double x, double y) {
return 0;
}
@Override
public double getNoiseSeeded(long seed, double x, double y, double z) {
return 0;
}
};
}
default double getNoiseSeeded(Vector3 vector3, long seed) {
return getNoiseSeeded(seed, vector3.getX(), vector3.getY(), vector3.getZ());
}
default double getNoiseSeeded(Vector2 vector2, long seed) {
return getNoiseSeeded(seed, vector2.getX(), vector2.getZ());
}
double getNoiseSeeded(long seed, double x, double y);
double getNoiseSeeded(long seed, double x, double y, double z);
}

View File

@@ -2,10 +2,10 @@ package com.dfsek.terra.api.structure;
import java.util.Random;
import com.dfsek.terra.api.StringIdentifiable;
import com.dfsek.terra.api.util.StringIdentifiable;
import com.dfsek.terra.api.structure.buffer.Buffer;
import com.dfsek.terra.api.structure.rotation.Rotation;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.api.structure;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
public interface StructureSpawn {

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.api.structure.buffer;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.api.structure.buffer;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.World;

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.api.structure.configured;
import com.dfsek.terra.api.StringIdentifiable;
import com.dfsek.terra.api.util.StringIdentifiable;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.structure.StructureSpawn;
import com.dfsek.terra.api.util.Range;

View File

@@ -1,184 +0,0 @@
package com.dfsek.terra.api.util;
import net.jafama.FastMath;
import java.util.List;
import com.dfsek.terra.api.world.generator.Sampler;
/**
* Utility class for mathematical functions.
*/
public final class MathUtil {
/**
* Epsilon for fuzzy floating point comparisons.
*/
public static final double EPSILON = 1.0E-5;
/**
* Derivative constant.
*/
private static final double DERIVATIVE_DIST = 0.55;
/**
* Gets the standard deviation of an array of doubles.
*
* @param numArray The array of numbers to calculate the standard deviation of.
*
* @return double - The standard deviation.
*/
public static double standardDeviation(List<Number> numArray) {
double sum = 0.0, standardDeviation = 0.0;
int length = numArray.size();
for(Number num : numArray) {
sum += num.doubleValue();
}
double mean = sum / length;
for(Number num : numArray) {
standardDeviation += FastMath.pow2(num.doubleValue() - mean);
}
return FastMath.sqrt(standardDeviation / length);
}
public static long hashToLong(String s) {
if(s == null) {
return 0;
}
long hash = 0;
for(char c : s.toCharArray()) {
hash = 31L * hash + c;
}
return hash;
}
/**
* Compare 2 floating-point values with epsilon to account for rounding errors
*
* @param a Value 1
* @param b Value 2
*
* @return Whether these values are equal
*/
public static boolean equals(double a, double b) {
return a == b || FastMath.abs(a - b) < EPSILON;
}
public static double derivative(Sampler sampler, double x, double y, double z) {
double baseSample = sampler.sample(x, y, z);
double xVal1 = (sampler.sample(x + DERIVATIVE_DIST, y, z) - baseSample) / DERIVATIVE_DIST;
double xVal2 = (sampler.sample(x - DERIVATIVE_DIST, y, z) - baseSample) / DERIVATIVE_DIST;
double zVal1 = (sampler.sample(x, y, z + DERIVATIVE_DIST) - baseSample) / DERIVATIVE_DIST;
double zVal2 = (sampler.sample(x, y, z - DERIVATIVE_DIST) - baseSample) / DERIVATIVE_DIST;
double yVal1 = (sampler.sample(x, y + DERIVATIVE_DIST, z) - baseSample) / DERIVATIVE_DIST;
double yVal2 = (sampler.sample(x, y - DERIVATIVE_DIST, z) - baseSample) / DERIVATIVE_DIST;
return Math.sqrt(((xVal2 - xVal1) * (xVal2 - xVal1)) + ((zVal2 - zVal1) * (zVal2 - zVal1)) + ((yVal2 - yVal1) * (yVal2 - yVal1)));
}
public static int normalizeIndex(double val, int size) {
return FastMath.max(FastMath.min(FastMath.floorToInt(((val + 1D) / 2D) * size), size - 1), 0);
}
public static long squash(int first, int last) {
return (((long) first) << 32) | (last & 0xffffffffL);
}
/**
* Clamp value to range of [-1, 1]
*
* @param in Value to clamp
*
* @return Clamped value
*/
public static double clamp(double in) {
return FastMath.min(FastMath.max(in, -1), 1);
}
/**
* Compute the value in a normally distributed data set that has probability p.
*
* @param p Probability of value
* @param mu Mean of data
* @param sigma Standard deviation of data
*
* @return Value corresponding to input probability
*/
public static double normalInverse(double p, double mu, double sigma) {
if(p < 0 || p > 1)
throw new IllegalArgumentException("Probability must be in range [0, 1]");
if(sigma < 0)
throw new IllegalArgumentException("Standard deviation must be positive.");
if(p == 0)
return Double.NEGATIVE_INFINITY;
if(p == 1)
return Double.POSITIVE_INFINITY;
if(sigma == 0)
return mu;
double q, r, val;
q = p - 0.5;
if(FastMath.abs(q) <= .425) {
r = .180625 - q * q;
val =
q * (((((((r * 2509.0809287301226727 +
33430.575583588128105) * r + 67265.770927008700853) * r +
45921.953931549871457) * r + 13731.693765509461125) * r +
1971.5909503065514427) * r + 133.14166789178437745) * r +
3.387132872796366608)
/ (((((((r * 5226.495278852854561 +
28729.085735721942674) * r + 39307.89580009271061) * r +
21213.794301586595867) * r + 5394.1960214247511077) * r +
687.1870074920579083) * r + 42.313330701600911252) * r + 1);
} else {
if(q > 0) {
r = 1 - p;
} else {
r = p;
}
r = FastMath.sqrt(-FastMath.log(r));
if(r <= 5) {
r += -1.6;
val = (((((((r * 7.7454501427834140764e-4 +
.0227238449892691845833) * r + .24178072517745061177) *
r + 1.27045825245236838258) * r +
3.64784832476320460504) * r + 5.7694972214606914055) *
r + 4.6303378461565452959) * r +
1.42343711074968357734)
/ (((((((r *
1.05075007164441684324e-9 + 5.475938084995344946e-4) *
r + .0151986665636164571966) * r +
.14810397642748007459) * r + .68976733498510000455) *
r + 1.6763848301838038494) * r +
2.05319162663775882187) * r + 1);
} else {
r += -5;
val = (((((((r * 2.01033439929228813265e-7 +
2.71155556874348757815e-5) * r +
.0012426609473880784386) * r + .026532189526576123093) *
r + .29656057182850489123) * r +
1.7848265399172913358) * r + 5.4637849111641143699) *
r + 6.6579046435011037772)
/ (((((((r *
2.04426310338993978564e-15 + 1.4215117583164458887e-7) *
r + 1.8463183175100546818e-5) * r +
7.868691311456132591e-4) * r + .0148753612908506148525)
* r + .13692988092273580531) * r +
.59983220655588793769) * r + 1);
}
if(q < 0.0) {
val = -val;
}
}
return mu + sigma * val;
}
}

View File

@@ -9,7 +9,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;
import com.dfsek.terra.api.structure.rotation.Rotation;
import com.dfsek.terra.api.vector.Vector2;
import com.dfsek.terra.api.util.vector.Vector2;
public final class RotationUtil {

View File

@@ -1,202 +0,0 @@
package com.dfsek.terra.api.vector;
import net.jafama.FastMath;
import com.dfsek.terra.api.util.MathUtil;
/**
* oh yeah
*/
public class Vector2 implements Cloneable {
private double x;
private double z;
/**
* Create a vector with a given X and Z component
*
* @param x X component
* @param z Z component
*/
public Vector2(double x, double z) {
this.x = x;
this.z = z;
}
/**
* Multiply X and Z components by a value.
*
* @param m Value to multiply
*
* @return Mutated vector, for chaining.
*/
public Vector2 multiply(double m) {
x *= m;
z *= m;
return this;
}
/**
* Add this vector to another.
*
* @param other Vector to add
*
* @return Mutated vector, for chaining.
*/
public Vector2 add(Vector2 other) {
x += other.getX();
z += other.getZ();
return this;
}
/**
* Subtract a vector from this vector,
*
* @param other Vector to subtract
*
* @return Mutated vector, for chaining.
*/
public Vector2 subtract(Vector2 other) {
x -= other.getX();
z -= other.getZ();
return this;
}
/**
* Normalize this vector to length 1
*
* @return Mutated vector, for chaining.
*/
public Vector2 normalize() {
divide(length());
return this;
}
/**
* Divide X and Z components by a value.
*
* @param d Divisor
*
* @return Mutated vector, for chaining.
*/
public Vector2 divide(double d) {
x /= d;
z /= d;
return this;
}
/**
* Get the length of this Vector
*
* @return length
*/
public double length() {
return FastMath.sqrt(lengthSquared());
}
/**
* Get the squared length of this Vector
*
* @return squared length
*/
public double lengthSquared() {
return x * x + z * z;
}
/**
* Get the distance from this vector to another.
*
* @param other Another vector
*
* @return Distance between vectors
*/
public double distance(Vector2 other) {
return FastMath.sqrt(distanceSquared(other));
}
/**
* Get the squared distance between 2 vectors.
*
* @param other Another vector
*
* @return Squared distance
*/
public double distanceSquared(Vector2 other) {
double dx = other.getX() - x;
double dz = other.getZ() - z;
return dx * dx + dz * dz;
}
public Vector3 extrude(double y) {
return new Vector3(this.x, y, this.z);
}
public Vector2 add(double x, double z) {
this.x += x;
this.z += z;
return this;
}
/**
* Get X component
*
* @return X component
*/
public double getX() {
return x;
}
public Vector2 setX(double x) {
this.x = x;
return this;
}
/**
* Get Z component
*
* @return Z component
*/
public double getZ() {
return z;
}
public Vector2 setZ(double z) {
this.z = z;
return this;
}
public int getBlockX() {
return FastMath.floorToInt(x);
}
public int getBlockZ() {
return FastMath.floorToInt(z);
}
@Override
public int hashCode() {
int hash = 17;
hash = 31 * hash + Double.hashCode(x);
hash = 31 * hash + Double.hashCode(z);
return hash;
}
public boolean equals(Object obj) {
if(!(obj instanceof Vector2)) return false;
Vector2 other = (Vector2) obj;
return MathUtil.equals(this.x, other.x) && MathUtil.equals(this.z, other.z);
}
public Vector2 clone() {
try {
return (Vector2) super.clone();
} catch(CloneNotSupportedException e) {
throw new Error(e);
}
}
@Override
public String toString() {
return "(" + x + ", " + z + ")";
}
}

View File

@@ -1,341 +0,0 @@
package com.dfsek.terra.api.vector;
import net.jafama.FastMath;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.util.MathUtil;
public class Vector3 implements Cloneable {
private double x;
private double y;
private double z;
public Vector3(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public Vector3 multiply(double m) {
x *= m;
y *= m;
z *= m;
return this;
}
public Vector3 add(double x, double y, double z) {
this.x += x;
this.y += y;
this.z += z;
return this;
}
public Vector3 add(Vector3 other) {
this.x += other.getX();
this.y += other.getY();
this.z += other.getZ();
return this;
}
public Vector3 add(Vector2 other) {
this.x += other.getX();
this.z += other.getZ();
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());
}
/**
* Rotates the vector around the x axis.
* <p>
* This piece of math is based on the standard rotation matrix for vectors
* in three dimensional space. This matrix can be found here:
* <a href="https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations">Rotation
* Matrix</a>.
*
* @param angle the angle to rotate the vector about. This angle is passed
* in radians
*
* @return the same vector
*/
@NotNull
public Vector3 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>
* This piece of math is based on the standard rotation matrix for vectors
* in three dimensional space. This matrix can be found here:
* <a href="https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations">Rotation
* Matrix</a>.
*
* @param angle the angle to rotate the vector about. This angle is passed
* in radians
*
* @return the same vector
*/
@NotNull
public Vector3 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>
* This piece of math is based on the standard rotation matrix for vectors
* in three dimensional space. This matrix can be found here:
* <a href="https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations">Rotation
* Matrix</a>.
*
* @param angle the angle to rotate the vector about. This angle is passed
* in radians
*
* @return the same vector
*/
@NotNull
public Vector3 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);
}
/**
* Get the distance between this vector and another. The value of this
* method is not cached and uses a costly square-root function, so do not
* repeatedly call this method to get the vector's magnitude. NaN will be
* returned if the inner result of the sqrt() function overflows, which
* will be caused if the distance is too long.
*
* @param o The other vector
*
* @return the distance
*/
public double distance(@NotNull Vector3 o) {
return FastMath.sqrt(FastMath.pow2(x - o.getX()) + FastMath.pow2(y - o.getY()) + FastMath.pow2(z - o.getZ()));
}
/**
* Get the squared distance between this vector and another.
*
* @param o The other vector
*
* @return the distance
*/
public double distanceSquared(@NotNull Vector3 o) {
return FastMath.pow2(x - o.getX()) + FastMath.pow2(y - o.getY()) + FastMath.pow2(z - o.getZ());
}
/**
* Rotates the vector around a given arbitrary axis in 3 dimensional space.
*
* <p>
* Rotation will follow the general Right-Hand-Rule, which means rotation
* will be counterclockwise when the axis is pointing towards the observer.
* <p>
* This method will always make sure the provided axis is a unit vector, to
* not modify the length of the vector when rotating.
*
* @param axis the axis to rotate the vector around. If the passed vector is
* not of length 1, it gets copied and normalized before using it for the
* rotation. Please use {@link Vector3#normalize()} on the instance before
* passing it to this method
* @param angle the angle to rotate the vector around the axis
*
* @return the same vector
*
* @throws IllegalArgumentException if the provided axis vector instance is
* null
*/
@NotNull
public Vector3 rotateAroundAxis(@NotNull Vector3 axis, double angle) throws IllegalArgumentException {
return rotateAroundNonUnitAxis(axis.isNormalized() ? axis : axis.clone().normalize(), angle);
}
/**
* Rotates the vector around a given arbitrary axis in 3 dimensional space.
*
* <p>
* Rotation will follow the general Right-Hand-Rule, which means rotation
* will be counterclockwise when the axis is pointing towards the observer.
* <p>
* Note that the vector length will change accordingly to the axis vector
* length. If the provided axis is not a unit vector, the rotated vector
* will not have its previous length. The scaled length of the resulting
* vector will be related to the axis vector.
*
* @param axis the axis to rotate the vector around.
* @param angle the angle to rotate the vector around the axis
*
* @return the same vector
*
* @throws IllegalArgumentException if the provided axis vector instance is
* null
*/
@NotNull
public Vector3 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;
double yPrime = y2 * dotProduct * (1d - cosTheta)
+ y * cosTheta
+ (z2 * x - x2 * z) * sinTheta;
double zPrime = z2 * dotProduct * (1d - cosTheta)
+ z * cosTheta
+ (-y2 * x + x2 * y) * sinTheta;
return setX(xPrime).setY(yPrime).setZ(zPrime);
}
/**
* 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.
*
* @param other The other vector
*
* @return dot product
*/
public double dot(@NotNull Vector3 other) {
return x * other.getX() + y * other.getY() + z * other.getZ();
}
public Vector3 normalize() {
return this.multiply(this.inverseLength());
}
public Vector3 subtract(int x, int y, int z) {
this.x -= x;
this.y -= y;
this.z -= z;
return this;
}
public Vector3 subtract(Vector3 end) {
x -= end.getX();
y -= end.getY();
z -= end.getZ();
return this;
}
public double getZ() {
return z;
}
public Vector3 setZ(double z) {
this.z = z;
return this;
}
public double getX() {
return x;
}
public Vector3 setX(double x) {
this.x = x;
return this;
}
public double getY() {
return y;
}
public Vector3 setY(double y) {
this.y = y;
return this;
}
public int getBlockX() {
return FastMath.floorToInt(x);
}
public int getBlockY() {
return FastMath.floorToInt(y);
}
public int getBlockZ() {
return FastMath.floorToInt(z);
}
/**
* Returns if a vector is normalized
*
* @return whether the vector is normalised
*/
public boolean isNormalized() {
return MathUtil.equals(this.lengthSquared(), 1);
}
/**
* Returns a hash code for this vector
*
* @return hash code
*/
@Override
public int hashCode() {
int hash = 7;
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;
}
/**
* Checks to see if two objects are equal.
* <p>
* Only two Vectors can ever return true. This method uses a fuzzy match
* to account for floating point errors. The epsilon can be retrieved
* with epsilon.
*/
@Override
public boolean equals(Object obj) {
if(!(obj instanceof Vector3)) return false;
Vector3 other = (Vector3) obj;
return MathUtil.equals(x, other.getX()) && MathUtil.equals(y, other.getY()) && MathUtil.equals(z, other.getZ());
}
public Vector3 clone() {
try {
return (Vector3) super.clone();
} catch(CloneNotSupportedException e) {
throw new Error(e);
}
}
@Override
public String toString() {
return "(" + getX() + ", " + getY() + ", " + getZ() + ")";
}
}

View File

@@ -3,7 +3,7 @@ package com.dfsek.terra.api.world;
import java.util.List;
import com.dfsek.terra.api.util.Range;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
public interface Flora {

View File

@@ -5,7 +5,7 @@ import java.util.Random;
import java.util.Set;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
public interface Tree {

View File

@@ -6,7 +6,7 @@ import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.config.WorldConfig;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.generator.ChunkGenerator;

View File

@@ -1,7 +1,7 @@
package com.dfsek.terra.api.world.biome.generation;
import com.dfsek.terra.api.vector.Vector2;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector2;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.biome.TerraBiome;

View File

@@ -1,5 +1,6 @@
package com.dfsek.terra.api.world.generator;
import com.dfsek.terra.api.util.math.Sampler;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -8,7 +9,7 @@ import java.util.Random;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.BiomeGrid;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;

View File

@@ -1,12 +0,0 @@
package com.dfsek.terra.api.world.generator;
@FunctionalInterface
public interface Sampler {
double sample(double x, double y, double z);
default double sample(int x, int y,
int z) { // Floating-point modulus operations are expensive. This allows implementations to optionally handle
// integers separately.
return sample((double) x, y, z);
}
}

View File

@@ -1,5 +1,7 @@
package com.dfsek.terra.api.world.generator;
import com.dfsek.terra.api.util.math.Sampler;
public interface SamplerCache {
Sampler get(int x, int z);