Skip to content

Temporary fix to handle loop that won't inline its condition#100

Merged
LexManos merged 1 commit intoMinecraftForge:masterfrom
zml2008:fix-nextGaussian
Jun 2, 2021
Merged

Temporary fix to handle loop that won't inline its condition#100
LexManos merged 1 commit intoMinecraftForge:masterfrom
zml2008:fix-nextGaussian

Conversation

@zml2008
Copy link
Collaborator

@zml2008 zml2008 commented May 27, 2021

Fixes #89, using the fix provided by Geolykt as a temporary solution.

Eventually someone should figure out why these loop conditions are not being properly inlined, but this helps get MC compiling.

diff

1.16.5: no change
21w19a:

diff -r -u3 -N a/net/minecraft/world/level/levelgen/SimpleRandomSource.java b/net/minecraft/world/level/levelgen/SimpleRandomSource.java
--- a/net/minecraft/world/level/levelgen/SimpleRandomSource.java	2021-05-12 08:32:54.000000000 -0700
+++ b/net/minecraft/world/level/levelgen/SimpleRandomSource.java	2021-05-26 22:24:06.000000000 -0700
@@ -3,6 +3,7 @@
 import com.mojang.datafixers.util.Pair;
 import java.util.concurrent.atomic.AtomicLong;
 import net.minecraft.util.DebugBuffer;
+import net.minecraft.util.Mth;
 import net.minecraft.util.ThreadingDetector;
 
 public class SimpleRandomSource implements RandomSource {
@@ -80,6 +81,23 @@
     }
 
     public double nextGaussian() {
-        // $FF: Couldn't be decompiled
+        if (this.haveNextNextGaussian) {
+            this.haveNextNextGaussian = false;
+            return this.nextNextGaussian;
+        } else {
+            while(true) {
+                double var0 = 2.0D * this.nextDouble() - 1.0D;
+                double var1 = 2.0D * this.nextDouble() - 1.0D;
+                double var2 = Mth.square(var0) + Mth.square(var1);
+                if (!(var2 >= 1.0D)) {
+                    if (var2 != 0.0D) {
+                        double var3 = Math.sqrt(-2.0D * Math.log(var2) / var2);
+                        this.nextNextGaussian = var1 * var3;
+                        this.haveNextNextGaussian = true;
+                        return var0 * var3;
+                    }
+                }
+            }
+        }
     }
 }

@LexManos LexManos merged commit 727ea00 into MinecraftForge:master Jun 2, 2021
@LexManos
Copy link
Member

LexManos commented Jun 2, 2021

The deeper I go into dissecting IfHelper, the more I have the urge to re-write it all. That system could be a lot more sane.
For now i've pulled this in so that it we can have a functional build. However it is a case where we need to re-address when time allows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(21w13a) net.minecraft.world.level.levelgen.SimpleRandomSource.nextGaussian fails to decompile

2 participants