2020-09-26 21:44:40 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: JellySquid <jellysquid+atwork@protonmail.com>
|
|
|
|
Date: Sat, 26 Sep 2020 11:37:25 -0500
|
|
|
|
Subject: [PATCH] lithium PerlinNoiseSamplerMixin
|
|
|
|
|
2020-10-27 20:15:13 +01:00
|
|
|
This is a more optimized version of Lithium's PerlinNoiseSamplerMixin.
|
2020-09-26 21:44:40 +02:00
|
|
|
Original code by JellySquid, licensed under LGPLv3
|
|
|
|
you can find the original code on https://github.com/jellysquid3/lithium-fabric/ (Yarn mappings)
|
|
|
|
|
2020-10-27 20:15:13 +01:00
|
|
|
Co-authored-by: Bud Gidiere <sgidiere@gmail.com>
|
|
|
|
|
2020-09-26 21:44:40 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/NoiseGeneratorPerlin.java b/src/main/java/net/minecraft/server/NoiseGeneratorPerlin.java
|
2020-10-27 20:34:46 +01:00
|
|
|
index d7ca619b228e2a5a461085e0c5222e6a36a66fe0..ea157542df2617eec6b5a62331e1daa3c086ffae 100644
|
2020-09-26 21:44:40 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/NoiseGeneratorPerlin.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/NoiseGeneratorPerlin.java
|
2020-10-27 20:15:13 +01:00
|
|
|
@@ -1,6 +1,7 @@
|
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
+import org.apache.commons.math3.util.FastMath; // Yatopia
|
|
|
|
|
|
|
|
public final class NoiseGeneratorPerlin {
|
|
|
|
|
|
|
|
@@ -8,6 +9,12 @@ public final class NoiseGeneratorPerlin {
|
2020-09-26 21:44:40 +02:00
|
|
|
public final double a;
|
|
|
|
public final double b;
|
|
|
|
public final double c;
|
2020-10-01 18:51:56 +02:00
|
|
|
+ // Yatopia start - Faster Perlin
|
2020-09-26 21:44:40 +02:00
|
|
|
+ private static final int GRADIENT_STRIDE = 4;
|
|
|
|
+ private static final int GRADIENT_STRIDE_SH = 2;
|
|
|
|
+
|
|
|
|
+ private final byte[] gradientTable = new byte[256 * GRADIENT_STRIDE];
|
2020-10-01 18:51:56 +02:00
|
|
|
+ // Yatopia end
|
2020-09-26 21:44:40 +02:00
|
|
|
|
|
|
|
public NoiseGeneratorPerlin(Random random) {
|
|
|
|
this.a = random.nextDouble() * 256.0D;
|
2020-10-27 20:15:13 +01:00
|
|
|
@@ -29,8 +36,19 @@ public final class NoiseGeneratorPerlin {
|
2020-09-26 21:44:40 +02:00
|
|
|
this.d[i + j] = b0;
|
|
|
|
}
|
|
|
|
|
2020-10-01 18:51:56 +02:00
|
|
|
+ // Yatopia start
|
2020-09-26 21:44:40 +02:00
|
|
|
+ for (i = 0; i < 256; i++) {
|
|
|
|
+ int hash = this.d[i & 255] & 15;
|
|
|
|
+
|
|
|
|
+ for (int j = 0; j < 3; j++) {
|
|
|
|
+ this.gradientTable[(i * GRADIENT_STRIDE) + j] = (byte) NoiseGenerator3Handler.a[hash][j];
|
|
|
|
+ }
|
|
|
|
+ }
|
2020-10-01 18:51:56 +02:00
|
|
|
+ // Yatopia end
|
2020-09-26 21:44:40 +02:00
|
|
|
}
|
|
|
|
|
2020-10-27 20:15:13 +01:00
|
|
|
+ // Yatopia start - replaced logic
|
|
|
|
+ /*
|
2020-10-01 18:51:56 +02:00
|
|
|
public double a(double d0, double d1, double d2, double d3, double d4) {
|
|
|
|
double d5 = d0 + this.a;
|
|
|
|
double d6 = d1 + this.b;
|
2020-10-27 20:15:13 +01:00
|
|
|
@@ -55,6 +73,125 @@ public final class NoiseGeneratorPerlin {
|
2020-10-01 18:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.a(i, j, k, d8, d9 - d14, d10, d11, d12, d13);
|
|
|
|
+ */
|
2020-10-27 20:15:13 +01:00
|
|
|
+ public final double sample(double x, double y, double z, double d, double e) { return a(x, y, z, d, e); } // Yatopia - OBFHELPER
|
|
|
|
+ public final double a(double x, double y, double z, double d, double e) {
|
|
|
|
+ final double ox = x + this.a;
|
|
|
|
+ final double oy = y + this.b;
|
2020-10-27 20:34:46 +01:00
|
|
|
+ final double oz = z + this.c;
|
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double fox = FastMath.floor(ox);
|
2020-10-27 20:34:46 +01:00
|
|
|
+ final double foy = FastMath.floor(oy);
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double foz = FastMath.floor(oz);
|
|
|
|
+
|
|
|
|
+ final double oox = ox - fox;
|
2020-09-26 21:44:40 +02:00
|
|
|
+ double ooy = oy - foy;
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double ooz = oz - foz;
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double fx = oox * oox * oox * (oox * (oox * 6.0 - 15.0) + 10.0);
|
|
|
|
+ final double fy = ooy * ooy * ooy * (ooy * (ooy * 6.0 - 15.0) + 10.0);
|
|
|
|
+ final double fz = ooz * ooz * ooz * (ooz * (ooz * 6.0 - 15.0) + 10.0);
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ if (d != 0.0D) { ooy = ooy - (FastMath.floor(FastMath.min(e, ooy) / d) * d); }
|
|
|
|
+
|
|
|
|
+ final int sectionX = (int) fox;
|
|
|
|
+ final int sectionY = (int) foy;
|
|
|
|
+ final int sectionZ = (int) foz;
|
2020-09-27 16:14:14 +02:00
|
|
|
+
|
2020-09-26 21:44:40 +02:00
|
|
|
+ final byte[] perm = this.d;
|
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final int i = (perm[sectionX & 255] & 255) + sectionY;
|
|
|
|
+ final int l = (perm[(sectionX + 1) & 255] & 255) + sectionY;
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final int j = (perm[255 & i] & 255) + sectionZ;
|
|
|
|
+ final int m = (perm[l & 255] & 255) + sectionZ;
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final int k = (perm[(i + 1) & 255] & 255) + sectionZ;
|
|
|
|
+ final int n = (perm[(l + 1) & 255] & 255) + sectionZ;
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double localX2 = oox - 1.0D;
|
|
|
|
+ final double localY2 = ooy - 1.0D;
|
|
|
|
+ final double localZ2 = ooz - 1.0D;
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
|
|
|
+ final int d00 = (j & 255) << GRADIENT_STRIDE_SH;
|
|
|
|
+ final int d01 = (m & 255) << GRADIENT_STRIDE_SH;
|
|
|
|
+ final int d02 = (k & 255) << GRADIENT_STRIDE_SH;
|
|
|
|
+ final int d03 = (n & 255) << GRADIENT_STRIDE_SH;
|
|
|
|
+
|
|
|
|
+ final int d10 = ((j + 1) & 255) << GRADIENT_STRIDE_SH;
|
|
|
|
+ final int d11 = ((m + 1) & 255) << GRADIENT_STRIDE_SH;
|
|
|
|
+ final int d12 = ((k + 1) & 255) << GRADIENT_STRIDE_SH;
|
|
|
|
+ final int d13 = ((n + 1) & 255) << GRADIENT_STRIDE_SH;
|
|
|
|
+
|
|
|
|
+ final byte[] grad = this.gradientTable;
|
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double g00x = grad[d00] * oox;
|
|
|
|
+ final double g00y = grad[d00 + 1] * ooy;
|
|
|
|
+ final double g00z = grad[d00 + 2] * ooz;
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
2020-10-01 18:51:56 +02:00
|
|
|
+ final double g01x = grad[d01] * localX2;
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double g01y = grad[d01 + 1] * ooy;
|
|
|
|
+ final double g01z = grad[d01 + 2] * ooz;
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double g02x = grad[d02] * oox;
|
2020-09-26 21:44:40 +02:00
|
|
|
+ final double g02y = grad[d02 + 1] * localY2;
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double g02z = grad[d02 + 2] * ooz;
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
2020-10-01 18:51:56 +02:00
|
|
|
+ final double g03x = grad[d03] * localX2;
|
2020-09-26 21:44:40 +02:00
|
|
|
+ final double g03y = grad[d03 + 1] * localY2;
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double g03z = grad[d03 + 2] * ooz;
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double g10x = grad[d10] * oox;
|
|
|
|
+ final double g10y = grad[d10 + 1] * ooy;
|
2020-09-26 21:44:40 +02:00
|
|
|
+ final double g10z = grad[d10 + 2] * localZ2;
|
|
|
|
+
|
2020-10-01 18:51:56 +02:00
|
|
|
+ final double g11x = grad[d11] * localX2;
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double g11y = grad[d11 + 1] * ooy;
|
2020-09-26 21:44:40 +02:00
|
|
|
+ final double g11z = grad[d11 + 2] * localZ2;
|
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double g12x = grad[d12] * oox;
|
2020-09-26 21:44:40 +02:00
|
|
|
+ final double g12y = grad[d12 + 1] * localY2;
|
|
|
|
+ final double g12z = grad[d12 + 2] * localZ2;
|
|
|
|
+
|
2020-10-01 18:51:56 +02:00
|
|
|
+ final double g13x = grad[d13] * localX2;
|
2020-09-26 21:44:40 +02:00
|
|
|
+ final double g13y = grad[d13 + 1] * localY2;
|
|
|
|
+ final double g13z = grad[d13 + 2] * localZ2;
|
|
|
|
+
|
|
|
|
+ final double g00 = g00x + g00y + g00z;
|
|
|
|
+ final double g01 = g01x + g01y + g01z;
|
|
|
|
+ final double g02 = g02x + g02y + g02z;
|
|
|
|
+ final double g03 = g03x + g03y + g03z;
|
|
|
|
+ final double g10 = g10x + g10y + g10z;
|
|
|
|
+ final double g11 = g11x + g11y + g11z;
|
|
|
|
+ final double g12 = g12x + g12y + g12z;
|
|
|
|
+ final double g13 = g13x + g13y + g13z;
|
|
|
|
+
|
|
|
|
+ final double ba1 = g01 - g00;
|
|
|
|
+ final double ba2 = g11 - g10;
|
|
|
|
+ final double dc1 = g03 - g02;
|
|
|
|
+ final double dc2 = g13 - g12;
|
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double dba1 = fx * ba1;
|
|
|
|
+ final double dba2 = fx * ba2;
|
|
|
|
+ final double ddc1 = fx * dc1;
|
|
|
|
+ final double ddc2 = fx * dc2;
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
|
|
|
+ final double dd0 = g00 + dba1;
|
|
|
|
+ final double dd1 = g10 + dba2;
|
|
|
|
+ final double dd2 = g02 + ddc1;
|
|
|
|
+ final double dd3 = g12 + ddc2;
|
|
|
|
+
|
|
|
|
+ final double aa0 = dd2 - dd0;
|
|
|
|
+ final double aa1 = dd3 - dd1;
|
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ final double y20 = fy * aa0;
|
|
|
|
+ final double y31 = fy * aa1;
|
2020-09-26 21:44:40 +02:00
|
|
|
+
|
|
|
|
+ final double aa2 = dd0 + y20;
|
|
|
|
+ final double aa3 = dd1 + y31;
|
|
|
|
+
|
2020-10-27 20:15:13 +01:00
|
|
|
+ return dd0 + y20 + (fz * (aa3 - aa2));
|
2020-10-01 18:51:56 +02:00
|
|
|
+ // Yatopia end
|
|
|
|
}
|
2020-10-27 20:15:13 +01:00
|
|
|
|
|
|
|
private static double a(int i, double d0, double d1, double d2) {
|