Skip to content

Commit

Permalink
Optimise BiomeManager#getFiddle
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Spottedleaf committed Aug 15, 2024
1 parent 0391e7b commit a83025a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions src/main/resources/moonrise.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a83025a

Please sign in to comment.