Simplex noise corruption, idk where it is used

This commit is contained in:
JFronny 2020-08-07 00:31:31 +02:00
parent 049ef096ae
commit 11b09cbfb3
2 changed files with 86 additions and 1 deletions

View File

@ -0,0 +1,84 @@
package io.gitlab.jfronny.quickmeth.mixin;
import io.gitlab.jfronny.quickmeth.quickmeth;
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) {
x = quickmeth.BoxedInvert(x);
y = quickmeth.BoxedInvert(y);
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);
return quickmeth.BoxedInvert(70.0D * (aa + ab + ac));
}
@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) {
x = quickmeth.BoxedInvert(x);
y = quickmeth.BoxedInvert(y);
z = quickmeth.BoxedInvert(z);
d = quickmeth.BoxedInvert(d);
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) {
return quickmeth.BoxedInvert((double)gArr[0] * x + (double)gArr[1] * y + (double)gArr[2] * z);
}
}

View File

@ -6,7 +6,8 @@
"mixins": [
"MathHelperMixin",
"MixinOctavePerlinNoiseSampler",
"MixinPerlinNoiseSampler"
"MixinPerlinNoiseSampler",
"MixinSimplexNoiseSampler"
],
"client": [
],