Faster otmRandom
This commit is contained in:
parent
6c0265582a
commit
0159931930
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user