Attach CMWC random to Level class, as alternative random to be used in OTM

This commit is contained in:
DBotThePony 2025-03-03 12:20:29 +07:00
parent 32ef2911fa
commit bc2c531e1f
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 36 additions and 1 deletions

View File

@ -0,0 +1,18 @@
package ru.dbotthepony.mc.otm.mixin;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import ru.dbotthepony.mc.otm.core.IMatteryWorld;
import ru.dbotthepony.mc.otm.core.util.CMWCRandom;
@Mixin(Level.class)
public abstract class LevelMixin implements IMatteryWorld {
public final RandomSource otm_random = new CMWCRandom();
@Override
public @NotNull RandomSource getOtmRandom() {
return otm_random;
}
}

View File

@ -0,0 +1,16 @@
package ru.dbotthepony.mc.otm.core
import net.minecraft.util.RandomSource
import net.minecraft.world.level.Level
interface IMatteryWorld {
/**
* OTM provided [RandomSource], which has better statistical parameters
*
* 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 Level.otmRandom: RandomSource get() = (this as IMatteryWorld).otmRandom

View File

@ -18,7 +18,8 @@
"HopperBlockEntityMixin",
"DispenserBlockEntityMixin",
"GuiGraphicsMixin",
"BlockStateBaseMixin"
"BlockStateBaseMixin",
"LevelMixin"
],
"client": [
"MixinGameRenderer",