Fix DensityFunctions lvt

This commit is contained in:
Nassim Jahnke
2024-12-19 11:01:00 +01:00
parent 15ad7cc156
commit 8f5d9953f5
3 changed files with 21 additions and 18 deletions

View File

@@ -17,7 +17,7 @@
public EndIslandDensityFunction(long seed) {
RandomSource randomSource = new LegacyRandomSource(seed);
@@ -518,15 +_,29 @@
@@ -518,15 +_,31 @@
int i1 = z / 2;
int i2 = x % 2;
int i3 = z % 2;
@@ -28,22 +28,25 @@
+ NoiseCache cache = noiseCache.get().computeIfAbsent(noise, noiseKey -> new NoiseCache()); // Paper - Perf: Optimize end generation
for (int i4 = -12; i4 <= 12; i4++) {
for (int i5 = -12; i5 <= 12; i5++) {
long l = i + i4;
long l1 = i1 + i5;
- if (l * l + l1 * l1 > 4096L && noise.getValue(l, l1) < -0.9F) {
- float f1 = (Mth.abs((float)l) * 3439.0F + Mth.abs((float)l1) * 147.0F) % 13.0F + 9.0F;
- long l = i + i4;
- long l1 = i1 + i5;
+ long l = i + i4; final int chunkX = (int) l; // Paper - OBFHELPER
+ long l1 = i1 + i5; final int chunkZ = (int) l1; // Paper - OBFHELPER
+ // Paper start - Perf: Optimize end generation by using a noise cache
+ long key = net.minecraft.world.level.ChunkPos.asLong((int) l, (int) l);
+ int index = (int) it.unimi.dsi.fastutil.HashCommon.mix(key) & 8191;
+ float f1 = Float.MIN_VALUE;
+ if (cache.keys[index] == key) {
+ f1 = cache.values[index];
+ final long chunkKey = net.minecraft.world.level.ChunkPos.asLong(chunkX, chunkZ);
+ final int cacheIndex = (int) it.unimi.dsi.fastutil.HashCommon.mix(chunkKey) & 8191;
+ float f1 = Float.MIN_VALUE; // noise value
+ if (cache.keys[cacheIndex] == chunkKey) {
+ // Use cache
+ f1 = cache.values[cacheIndex];
+ } else {
+ if (l * l + l1 * l1 > 4096L && noise.getValue((double)l, (double)l1) < -0.9F) {
+ f1 = (Mth.abs((float)l) * 3439.0F + Mth.abs((float)l1) * 147.0F) % 13.0F + 9.0F;
+ }
+ cache.keys[index] = key;
+ cache.values[index] = f1;
+ // Vanilla function
if (l * l + l1 * l1 > 4096L && noise.getValue(l, l1) < -0.9F) {
- float f1 = (Mth.abs((float)l) * 3439.0F + Mth.abs((float)l1) * 147.0F) % 13.0F + 9.0F;
+ f1 = (Mth.abs((float)l) * 3439.0F + Mth.abs((float)l1) * 147.0F) % 13.0F + 9.0F;
+ }
+ cache.keys[cacheIndex] = chunkKey;
+ cache.values[cacheIndex] = f1;
+ }
+ if (f1 != Float.MIN_VALUE) {
+ // Paper end - Perf: Optimize end generation