diff --git a/src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java b/src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java index 7ef475bbd..9930b5a28 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java +++ b/src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java @@ -2,20 +2,18 @@ package ru.dbotthepony.mc.otm.mixin; import net.minecraft.util.RandomSource; import net.minecraft.world.level.Level; -import org.jetbrains.annotations.NotNull; +import net.neoforged.fml.ModList; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import ru.dbotthepony.mc.otm.core.IMatteryLevel; import ru.dbotthepony.mc.otm.core.util.GJRAND64RandomSource; @Mixin(Level.class) public abstract class LevelMixin implements IMatteryLevel { - private RandomSource otm_random; + private final RandomSource otm_random = ModList.get().isLoaded("better_random") ? null : new GJRAND64RandomSource(); @Override - public @NotNull RandomSource getOtmRandom() { - if (otm_random == null) - otm_random = new GJRAND64RandomSource(); - + public @Nullable RandomSource getOtmRandom() { return otm_random; } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt index cf0ad7e10..583febb3c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt @@ -11,11 +11,7 @@ interface IMatteryLevel { * Original Minecraft use LCG, which may show bad behavior when repeatedly sampled *a lot*, * which is what [Level]'s random is used for. OTM provided PRNG should behave better in this scenario. */ - val otmRandom: RandomSource + val otmRandom: RandomSource? } -private val isBetterRandomLoaded by lazy { - ModList.get().isLoaded("better_random") -} - -val Level.otmRandom: RandomSource get() = if (isBetterRandomLoaded) random else (this as IMatteryLevel).otmRandom +val Level.otmRandom: RandomSource get() = (this as IMatteryLevel).otmRandom ?: random