diff --git a/gradle.properties b/gradle.properties index 967ac6b..ba9609a 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.2.1 +mod_version=1.2.2 # 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 index 2726c9c..8610786 100644 --- a/src/main/java/ru/dbotthepony/mc/prng/mixin/WorldgenRandomMixin.java +++ b/src/main/java/ru/dbotthepony/mc/prng/mixin/WorldgenRandomMixin.java @@ -4,29 +4,39 @@ import net.minecraft.util.RandomSource; import net.minecraft.world.level.levelgen.LegacyRandomSource; import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.level.levelgen.XoroshiroRandomSource; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.Redirect; import ru.dbotthepony.mc.prng.GJRAND64RandomSource; @Mixin(WorldgenRandom.class) public abstract class WorldgenRandomMixin { @Shadow - protected RandomSource randomSource; + private RandomSource randomSource; - // quite lazy solution because if someone genuinely want to get lcg they wont be able to - @Inject( + // This is a mixed bag os a solution. + // On one hand, we cover all cases where WorldgenRandom getting called within vanilla code, + // on other hand it also detours and redirects calls done by mods, which *may* delibarately use LCG or Xoroshiro128++ + // But we also need to consider that mods will likely just copy/do what vanilla code does, and hence + // they expect code to follow same behavior as vanilla, so in such case us redirecting PRNG is completely desirable + @Redirect( method = "(Lnet/minecraft/util/RandomSource;)V", - at = @At("TAIL") + at = @At( + value = "FIELD", + target = "randomSource:Lnet/minecraft/util/RandomSource;", + opcode = Opcodes.PUTFIELD + ) ) - public void constructorMix(RandomSource randomSource, CallbackInfo info) { + public void constructorMix(WorldgenRandom self, RandomSource randomSource) { if (randomSource instanceof LegacyRandomSource rng) { this.randomSource = new GJRAND64RandomSource(rng.seed.get()); } else if (randomSource instanceof XoroshiroRandomSource rng) { this.randomSource = new GJRAND64RandomSource(rng.randomNumberGenerator.seedHi, rng.randomNumberGenerator.seedLo); + } else { + this.randomSource = randomSource; } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index b3f7f90..4013a51 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -6,7 +6,7 @@ protected net.minecraft.world.RandomSequences includeSequenceId public net.minecraft.world.RandomSequences$DirtyMarkingRandomSource public net.minecraft.world.RandomSequences$DirtyMarkingRandomSource (Lnet/minecraft/world/RandomSequences;Lnet/minecraft/util/RandomSource;)V -protected-f net.minecraft.world.level.levelgen.WorldgenRandom randomSource +private-f net.minecraft.world.level.levelgen.WorldgenRandom randomSource public net.minecraft.world.level.levelgen.LegacyRandomSource seed public net.minecraft.world.level.levelgen.XoroshiroRandomSource randomNumberGenerator public net.minecraft.world.level.levelgen.Xoroshiro128PlusPlus seedLo