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.util.RandomSource;
|
||||||
import net.minecraft.world.level.Level;
|
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 org.spongepowered.asm.mixin.Mixin;
|
||||||
import ru.dbotthepony.mc.otm.core.IMatteryLevel;
|
import ru.dbotthepony.mc.otm.core.IMatteryLevel;
|
||||||
import ru.dbotthepony.mc.otm.core.util.GJRAND64RandomSource;
|
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 {
|
||||||
private RandomSource otm_random;
|
private final RandomSource otm_random = ModList.get().isLoaded("better_random") ? null : new GJRAND64RandomSource();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull RandomSource getOtmRandom() {
|
public @Nullable RandomSource getOtmRandom() {
|
||||||
if (otm_random == null)
|
|
||||||
otm_random = new GJRAND64RandomSource();
|
|
||||||
|
|
||||||
return otm_random;
|
return otm_random;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,7 @@ interface IMatteryLevel {
|
|||||||
* Original Minecraft use LCG, which may show bad behavior when repeatedly sampled *a lot*,
|
* 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.
|
* 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 {
|
val Level.otmRandom: RandomSource get() = (this as IMatteryLevel).otmRandom ?: random
|
||||||
ModList.get().isLoaded("better_random")
|
|
||||||
}
|
|
||||||
|
|
||||||
val Level.otmRandom: RandomSource get() = if (isBetterRandomLoaded) random else (this as IMatteryLevel).otmRandom
|
|
||||||
|
Loading…
Reference in New Issue
Block a user