From a83025a52f3284b597aabecb945cf37d3e377317 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Wed, 14 Aug 2024 17:52:47 -0700 Subject: [PATCH] Optimise BiomeManager#getFiddle 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. --- .../random_ticking/BiomeManagerMixin.java | 18 ++++++++++++++++++ src/main/resources/moonrise.mixins.json | 1 + 2 files changed, 19 insertions(+) create mode 100644 src/main/java/ca/spottedleaf/moonrise/mixin/random_ticking/BiomeManagerMixin.java diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/random_ticking/BiomeManagerMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/random_ticking/BiomeManagerMixin.java new file mode 100644 index 00000000..8975e6e8 --- /dev/null +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/random_ticking/BiomeManagerMixin.java @@ -0,0 +1,18 @@ +package ca.spottedleaf.moonrise.mixin.random_ticking; + +import net.minecraft.world.level.biome.BiomeManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +@Mixin(BiomeManager.class) +abstract class BiomeManagerMixin { + + /** + * @reason Replace floorMod and double division to optimise the function + * @author Spottedleaf + */ + @Overwrite + public static double getFiddle(final long seed) { + return (double)(((seed >> 24) & (1024 - 1)) - (1024/2)) * (0.9 / 1024.0); + } +} diff --git a/src/main/resources/moonrise.mixins.json b/src/main/resources/moonrise.mixins.json index 42e62267..67ee622c 100644 --- a/src/main/resources/moonrise.mixins.json +++ b/src/main/resources/moonrise.mixins.json @@ -91,6 +91,7 @@ "poi_lookup.AcquirePoiMixin", "poi_lookup.PoiManagerMixin", "poi_lookup.PortalForcerMixin", + "random_ticking.BiomeManagerMixin", "random_ticking.BiomeMixin", "random_ticking.LevelMixin", "random_ticking.ServerLevelMixin",