From 9836fa00886daffe740b50e94cdf30d8a11fa6d2 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 12 Mar 2025 18:20:13 +0700 Subject: [PATCH] AEUGH --- gradle.properties | 2 +- .../dbotthepony/mc/prng/mixin/LevelMixin.java | 38 +++++++++++++++++++ .../resources/META-INF/accesstransformer.cfg | 4 ++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 82eb001..3ebbe27 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.3.1 +mod_version=1.3.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/LevelMixin.java b/src/main/java/ru/dbotthepony/mc/prng/mixin/LevelMixin.java index 8a9fbf4..9d3374e 100644 --- a/src/main/java/ru/dbotthepony/mc/prng/mixin/LevelMixin.java +++ b/src/main/java/ru/dbotthepony/mc/prng/mixin/LevelMixin.java @@ -1,15 +1,26 @@ package ru.dbotthepony.mc.prng.mixin; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.core.RegistryAccess; +import net.minecraft.resources.ResourceKey; import net.minecraft.util.RandomSource; +import net.minecraft.util.profiling.ProfilerFiller; import net.minecraft.world.level.Level; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.storage.WritableLevelData; import org.spongepowered.asm.mixin.Final; 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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import ru.dbotthepony.mc.prng.BetterRandom; +import ru.dbotthepony.mc.prng.GJRAND64RandomSource; + +import java.util.function.Supplier; @Mixin(value = Level.class, priority = 10000) // ensure this mixin is applied over other "regular" mixins public abstract class LevelMixin { @@ -17,6 +28,8 @@ public abstract class LevelMixin { @Final private Thread thread; + // does not work with C2ME, Mixin crashes + /* @Redirect( method = "", at = @At( @@ -27,6 +40,31 @@ public abstract class LevelMixin { public RandomSource ensureBetterRandom() { return BetterRandom.createWorldRandom(() -> thread); } + */ + + @Shadow + public RandomSource random; + + @Inject( + method = "(Lnet/minecraft/world/level/storage/WritableLevelData;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/core/RegistryAccess;Lnet/minecraft/core/Holder;Ljava/util/function/Supplier;ZZJI)V", + at = @At("TAIL") + ) + public void constructorMix( + WritableLevelData levelData, + ResourceKey dimension, + RegistryAccess registryAccess, + Holder dimensionTypeRegistration, + Supplier profiler, + boolean isClientSide, + boolean isDebug, + long biomeZoomSeed, + int maxChainedNeighborUpdates, + CallbackInfo info + ) { + if (!(this.random instanceof GJRAND64RandomSource)) + this.random = BetterRandom.createWorldRandom(() -> thread); + } + @Overwrite public BlockPos getBlockRandomPos(int x, int y, int z, int yMask) { diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 4013a51..bb25d1f 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -11,3 +11,7 @@ public net.minecraft.world.level.levelgen.LegacyRandomSource seed public net.minecraft.world.level.levelgen.XoroshiroRandomSource randomNumberGenerator public net.minecraft.world.level.levelgen.Xoroshiro128PlusPlus seedLo public net.minecraft.world.level.levelgen.Xoroshiro128PlusPlus seedHi + +# This will cause minor slowdown when ZGC or ShenandoahGC is used, but at least it won't crash +# with C2ME installed +public-f net.minecraft.world.level.Level random