2020-08-07 00:31:31 +02:00
|
|
|
package io.gitlab.jfronny.quickmeth.mixin;
|
|
|
|
|
2021-05-19 15:12:49 +02:00
|
|
|
import io.gitlab.jfronny.quickmeth.MathUtil;
|
2020-08-07 00:31:31 +02:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
import net.minecraft.util.math.noise.SimplexNoiseSampler;
|
|
|
|
import org.spongepowered.asm.mixin.Final;
|
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
|
|
import org.spongepowered.asm.mixin.Overwrite;
|
|
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
|
|
|
|
|
|
@Mixin(SimplexNoiseSampler.class)
|
|
|
|
public class MixinSimplexNoiseSampler {
|
|
|
|
@Shadow @Final
|
|
|
|
private static double SKEW_FACTOR_2D;
|
|
|
|
@Shadow @Final
|
|
|
|
private static double UNSKEW_FACTOR_2D;
|
|
|
|
@Shadow @Final
|
|
|
|
protected static int[][] gradients;
|
|
|
|
@Shadow @Final
|
|
|
|
private int[] permutations;
|
|
|
|
@Overwrite
|
|
|
|
public double sample(double x, double y) {
|
2021-05-19 15:12:49 +02:00
|
|
|
x = MathUtil.BoxedInvert(x);
|
|
|
|
y = MathUtil.BoxedInvert(y);
|
2020-08-07 00:31:31 +02:00
|
|
|
double d = (x + y) * SKEW_FACTOR_2D;
|
|
|
|
int i = MathHelper.floor(x + d);
|
|
|
|
int j = MathHelper.floor(y + d);
|
|
|
|
double e = (double)(i + j) * UNSKEW_FACTOR_2D;
|
|
|
|
double f = (double)i - e;
|
|
|
|
double g = (double)j - e;
|
|
|
|
double h = x - f;
|
|
|
|
double k = y - g;
|
|
|
|
byte n;
|
|
|
|
byte o;
|
|
|
|
if (h > k) {
|
|
|
|
n = 1;
|
|
|
|
o = 0;
|
|
|
|
} else {
|
|
|
|
n = 0;
|
|
|
|
o = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
double p = h - (double)n + UNSKEW_FACTOR_2D;
|
|
|
|
double q = k - (double)o + UNSKEW_FACTOR_2D;
|
|
|
|
double r = h - 1.0D + 2.0D * UNSKEW_FACTOR_2D;
|
|
|
|
double s = k - 1.0D + 2.0D * UNSKEW_FACTOR_2D;
|
|
|
|
int t = i & 255;
|
|
|
|
int u = j & 255;
|
|
|
|
int v = getGradient(t + this.getGradient(u)) % 12;
|
|
|
|
int w = getGradient(t + n + this.getGradient(u + o)) % 12;
|
|
|
|
int z = getGradient(t + 1 + this.getGradient(u + 1)) % 12;
|
|
|
|
double aa = mgrad(v, h, k, 0.0D, 0.5D);
|
|
|
|
double ab = mgrad(w, p, q, 0.0D, 0.5D);
|
|
|
|
double ac = mgrad(z, r, s, 0.0D, 0.5D);
|
2021-05-19 15:12:49 +02:00
|
|
|
return MathUtil.BoxedInvert(70.0D * (aa + ab + ac));
|
2020-08-07 00:31:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Overwrite
|
|
|
|
private int getGradient(int hash) {
|
|
|
|
return this.permutations[hash & 255] & 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static double mgrad(int hash, double x, double y, double z, double d) {
|
2021-05-19 15:12:49 +02:00
|
|
|
x = MathUtil.BoxedInvert(x);
|
|
|
|
y = MathUtil.BoxedInvert(y);
|
|
|
|
z = MathUtil.BoxedInvert(z);
|
|
|
|
d = MathUtil.BoxedInvert(d);
|
2020-08-07 00:31:31 +02:00
|
|
|
|
|
|
|
double e = d - x * x - y * y - z * z;
|
|
|
|
double g;
|
|
|
|
if (e < 0.0D) {
|
|
|
|
g = 0.0D;
|
|
|
|
} else {
|
|
|
|
e *= e;
|
|
|
|
g = e * e * mdot(gradients[hash], x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static double mdot(int[] gArr, double x, double y, double z) {
|
2021-05-19 15:12:49 +02:00
|
|
|
return MathUtil.BoxedInvert((double)gArr[0] * x + (double)gArr[1] * y + (double)gArr[2] * z);
|
2020-08-07 00:31:31 +02:00
|
|
|
}
|
|
|
|
}
|