MinecraftForge / ForgeFlower

Forge's modifications to FernFlower. Fixing various bugs/inconsistencies. Main Repo: https://github.com/MinecraftForge/FernFlower
Apache License 2.0
80 stars 44 forks source link

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

Closed zml2008 closed 3 years ago

zml2008 commented 3 years ago

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 commented 3 years ago

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.