Reuse Mojang's floor function in noise samplers
This commit is contained in:
1 parent
68a447daf9
commit
773e8722ca
2 files changed
+14
-18
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
@@ -59,9 +60,9 @@ public class PerlinNoiseSampler
|
||||
double f = x + this.originX;
|
||||
double g = y + this.originY;
|
||||
double h = z + this.originZ;
|
||||
int i = floor(f);
|
||||
int j = floor(g);
|
||||
int k = floor(h);
|
||||
int i = Mth.floor(f);
|
||||
int j = Mth.floor(g);
|
||||
int k = Mth.floor(h);
|
||||
double l = f - (double) i;
|
||||
double m = g - (double) j;
|
||||
double n = h - (double) k;
|
||||
@@ -72,7 +73,7 @@ public class PerlinNoiseSampler
|
||||
/*
|
||||
if (d != 0.0D) {
|
||||
double r = Math.min(e, m);
|
||||
t = (double)floor(r / d) * d;
|
||||
t = (double)Mth.floor(r / d) * d;
|
||||
} else {
|
||||
t = 0.0D;
|
||||
}*/
|
||||
@@ -120,8 +121,8 @@ public class PerlinNoiseSampler
|
||||
{
|
||||
double f = x + this.originX;
|
||||
double g = y + this.originY;
|
||||
int i = floor(f);
|
||||
int j = floor(g);
|
||||
int i = Mth.floor(f);
|
||||
int j = Mth.floor(g);
|
||||
double l = f - (double) i;
|
||||
double m = g - (double) j;
|
||||
double o = perlinFade(l);
|
||||
@@ -161,7 +162,7 @@ public class PerlinNoiseSampler
|
||||
public double sample1d(double x)
|
||||
{
|
||||
double f = x + this.originX;
|
||||
int i = floor(f);
|
||||
int i = Mth.floor(f);
|
||||
double l = f - i;
|
||||
double o = perlinFade(l);
|
||||
return this.sample1d(i, l, o) + 0.5;
|
||||
@@ -194,10 +195,4 @@ public class PerlinNoiseSampler
|
||||
{
|
||||
return d * d * d * (d * (d * 6.0D - 15.0D) + 10.0D);
|
||||
}
|
||||
|
||||
public static int floor(double d)
|
||||
{
|
||||
int i = (int) d;
|
||||
return d < i ? i - 1 : i;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
@@ -52,8 +53,8 @@ public class SimplexNoiseSampler extends PerlinNoiseSampler
|
||||
x = x / 2;
|
||||
y = y / 2;
|
||||
double d = (x + y) * SKEW_FACTOR_2D;
|
||||
int i = PerlinNoiseSampler.floor(x + d);
|
||||
int j = PerlinNoiseSampler.floor(y + d);
|
||||
int i = Mth.floor(x + d);
|
||||
int j = Mth.floor(y + d);
|
||||
double e = (i + j) * UNSKEW_FACTOR_2D;
|
||||
double f = i - e;
|
||||
double g = j - e;
|
||||
@@ -96,9 +97,9 @@ public class SimplexNoiseSampler extends PerlinNoiseSampler
|
||||
f = f / 2;
|
||||
//final double g = 0.3333333333333333D;
|
||||
double h = (d + e + f) * 0.3333333333333333D;
|
||||
int i = floor(d + h);
|
||||
int j = floor(e + h);
|
||||
int k = floor(f + h);
|
||||
int i = Mth.floor(d + h);
|
||||
int j = Mth.floor(e + h);
|
||||
int k = Mth.floor(f + h);
|
||||
//final double l = 0.16666666666666666D;
|
||||
double m = (i + j + k) * 0.16666666666666666D;
|
||||
double n = i - m;
|
||||
|
||||
Reference in new issue
Block a user