From 161df68b38ae8f6ea3045afb1137e02a34a52332 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 11 Mar 2025 09:02:36 +0700 Subject: [PATCH] Revert slime chunk spawn behavior to pre-changes --- README.md | 12 +++++++++- gradle.properties | 2 +- .../mc/prng/mixin/WorldgenRandomMixin.java | 22 +++++++++++++++++++ src/main/resources/better_random.mixins.json | 3 ++- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/main/java/ru/dbotthepony/mc/prng/mixin/WorldgenRandomMixin.java diff --git a/README.md b/README.md index 6f38fc5..b474164 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,14 @@ Better Random ======= -Or Better PRNG, is a mod which replace Minecraft's default +##### Disclaimer +This mod changes RNG, and as such, affects worldgen greatly, so with this mod alone installed vanilla world seeds will no longer +be reproducible. If you care about preserving vanilla worldgen parity in your modpack, **refrain** from installing this mod. + +You were warned. + +### About the mod +Better Random, or Better PRNG if you prefer, is a mod which replace Minecraft's default [Linear congruential generator](https://en.wikipedia.org/wiki/Linear_congruential_generator) (LCG for short, used for generating most of random game events, as well as generator used when generating world features) and Xoshiro128PlusPlus (used to generate "sequences" aka random generator used for `LootPool`s) @@ -13,6 +20,9 @@ with a better random number generator, [gjrand](https://gjrand.sourceforge.net). * Replaces `RandomSequence` and `RandomSequences` with versions which use gjrand; * Replaces `Level#getBlockRandomPos` to use `Level#random`. Previously, `getBlockRandomPos` utilized LCG with even worse properties than one of `Level#random`. +### Caveats: + * Slime chunk function was patched to be hardwired to LegacyRandomSource so they don't change with this mod installed. + ### Compatibility: Should be compatible with everything that doesn't go around public interfaces vanilla code provide. diff --git a/gradle.properties b/gradle.properties index a378496..543c6c6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -34,7 +34,7 @@ mod_name=Better Random # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=BSD 2 Clause # The mod version. See https://semver.org/ -mod_version=1.0.0 +mod_version=1.1.0 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/ru/dbotthepony/mc/prng/mixin/WorldgenRandomMixin.java b/src/main/java/ru/dbotthepony/mc/prng/mixin/WorldgenRandomMixin.java new file mode 100644 index 0000000..6a07fbe --- /dev/null +++ b/src/main/java/ru/dbotthepony/mc/prng/mixin/WorldgenRandomMixin.java @@ -0,0 +1,22 @@ +package ru.dbotthepony.mc.prng.mixin; + +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.levelgen.LegacyRandomSource; +import net.minecraft.world.level.levelgen.WorldgenRandom; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +@Mixin(WorldgenRandom.class) +public abstract class WorldgenRandomMixin { + @Overwrite + public static RandomSource seedSlimeChunk(int chunkX, int chunkZ, long levelSeed, long salt) { + return new LegacyRandomSource( + levelSeed + + (long)(chunkX * chunkX * 4987142) + + (long)(chunkX * 5947611) + + (long)(chunkZ * chunkZ) * 4392871L + + (long)(chunkZ * 389711) + ^ salt + ); + } +} diff --git a/src/main/resources/better_random.mixins.json b/src/main/resources/better_random.mixins.json index fc76402..674f986 100644 --- a/src/main/resources/better_random.mixins.json +++ b/src/main/resources/better_random.mixins.json @@ -7,7 +7,8 @@ "mixins": [ "RandomSourceMixin", "LevelMixin", - "ServerLevelMixin" + "ServerLevelMixin", + "WorldgenRandomMixin" ], "client": [] }