From 11b09cbfb3f41886de0c7c90ef52d872588f1bbc Mon Sep 17 00:00:00 2001 From: JFronny <33260128+JFronny@users.noreply.github.com> Date: Fri, 7 Aug 2020 00:31:31 +0200 Subject: [PATCH] Simplex noise corruption, idk where it is used --- .../mixin/MixinSimplexNoiseSampler.java | 84 +++++++++++++++++++ .../io.gitlab.jfronny.quickmeth.mixins.json | 3 +- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinSimplexNoiseSampler.java diff --git a/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinSimplexNoiseSampler.java b/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinSimplexNoiseSampler.java new file mode 100644 index 0000000..3e0c265 --- /dev/null +++ b/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinSimplexNoiseSampler.java @@ -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); + } +} diff --git a/src/main/resources/io.gitlab.jfronny.quickmeth.mixins.json b/src/main/resources/io.gitlab.jfronny.quickmeth.mixins.json index 7a6e3cb..a924ebe 100644 --- a/src/main/resources/io.gitlab.jfronny.quickmeth.mixins.json +++ b/src/main/resources/io.gitlab.jfronny.quickmeth.mixins.json @@ -6,7 +6,8 @@ "mixins": [ "MathHelperMixin", "MixinOctavePerlinNoiseSampler", - "MixinPerlinNoiseSampler" + "MixinPerlinNoiseSampler", + "MixinSimplexNoiseSampler" ], "client": [ ],