From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Wed, 14 Aug 2024 17:52:47 -0700 Subject: [PATCH] Moonrise: Optimise BiomeManager#getFiddle Original license: GPLv3 Original project: https://github.com/Tuinity/Moonrise https://github.com/Tuinity/Moonrise/commit/a83025a52f3284b597aabecb945cf37d3e377317 The floorMod and subtraction by 0.5 can be done before converting to double, and the division by 1024 may be converted to a simple multiplication. At this point, the result is exactly the same. However, to remove the extra multiplication by 0.9, it can be moved into the multiplication by 1/1024. This may affect the result to one ULP, but I do not forsee that causing any problems. diff --git a/src/main/java/net/minecraft/world/level/biome/BiomeManager.java b/src/main/java/net/minecraft/world/level/biome/BiomeManager.java index b90a323c4fc9af141758a73a72e6918300caf470..db159843e16e29be897112d02e71e48377ab13ac 100644 --- a/src/main/java/net/minecraft/world/level/biome/BiomeManager.java +++ b/src/main/java/net/minecraft/world/level/biome/BiomeManager.java @@ -127,10 +127,15 @@ public class BiomeManager { return Mth.square(f + n) + Mth.square(e + h) + Mth.square(d + g); } - private static double getFiddle(long l) { - double d = (double)Math.floorMod(l >> 24, 1024) / 1024.0; - return (d - 0.5) * 0.9; + // Moonrise start - Optimise BiomeManager#getFiddle + /** + * @reason Replace floorMod and double division to optimise the function + * @author Spottedleaf + */ + private static double getFiddle(long seed) { + return (double) (((seed >> 24) & (1024 - 1)) - (1024 / 2)) * (0.9 / 1024.0); } + // Moonrise end - Optimise BiomeManager#getFiddle public interface NoiseBiomeSource { Holder getNoiseBiome(int biomeX, int biomeY, int biomeZ);