From 6c0265582acb4a5399d750dbc8ccf7bc3fd94a36 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 10 Mar 2025 20:33:28 +0700 Subject: [PATCH] Don't create own random provider if Better Random is present --- src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java | 5 ++++- .../kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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 ac4d4e141..7ef475bbd 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java +++ b/src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java @@ -9,10 +9,13 @@ import ru.dbotthepony.mc.otm.core.util.GJRAND64RandomSource; @Mixin(Level.class) public abstract class LevelMixin implements IMatteryLevel { - public final RandomSource otm_random = new GJRAND64RandomSource(); + private RandomSource otm_random; @Override public @NotNull RandomSource getOtmRandom() { + if (otm_random == null) + otm_random = new GJRAND64RandomSource(); + 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 dba505e23..cf0ad7e10 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt @@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.core import net.minecraft.util.RandomSource import net.minecraft.world.level.Level +import net.neoforged.fml.ModList interface IMatteryLevel { /** @@ -13,4 +14,8 @@ interface IMatteryLevel { 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