Don't create own random provider if Better Random is present

This commit is contained in:
DBotThePony 2025-03-10 20:33:28 +07:00
parent 08ae897c6f
commit 6c0265582a
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 10 additions and 2 deletions

View File

@ -9,10 +9,13 @@ import ru.dbotthepony.mc.otm.core.util.GJRAND64RandomSource;
@Mixin(Level.class) @Mixin(Level.class)
public abstract class LevelMixin implements IMatteryLevel { public abstract class LevelMixin implements IMatteryLevel {
public final RandomSource otm_random = new GJRAND64RandomSource(); private RandomSource otm_random;
@Override @Override
public @NotNull RandomSource getOtmRandom() { public @NotNull RandomSource getOtmRandom() {
if (otm_random == null)
otm_random = new GJRAND64RandomSource();
return otm_random; return otm_random;
} }
} }

View File

@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.core
import net.minecraft.util.RandomSource import net.minecraft.util.RandomSource
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
import net.neoforged.fml.ModList
interface IMatteryLevel { interface IMatteryLevel {
/** /**
@ -13,4 +14,8 @@ interface IMatteryLevel {
val otmRandom: RandomSource val otmRandom: RandomSource
} }
val Level.otmRandom: RandomSource get() = (this as IMatteryLevel).otmRandom private val isBetterRandomLoaded by lazy {
ModList.get().isLoaded("better_random")
}
val Level.otmRandom: RandomSource get() = if (isBetterRandomLoaded) random else (this as IMatteryLevel).otmRandom