From 08ae897c6f94a41aab5660c5398160b7d56d5b43 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sun, 9 Mar 2025 22:36:55 +0700 Subject: [PATCH 1/6] Make Medical Pill provide only Regeneration III for 8 seconds Because it completely overshadows Enchanted Golden Apples with current state of things --- src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt | 2 +- src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt | 2 +- .../ru/dbotthepony/mc/otm/item/consumables/HealPillItem.kt | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt index 9dc45033e..67ead1708 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt @@ -381,7 +381,7 @@ private fun misc(provider: MatteryLanguageProvider) { misc("pill.oblivion", "Items and Experience spent on research is fully refunded.") misc("pill.message_oblivion", "All android features are removed and all research refunded.") - misc("pill.heal", "Instantly restores 4 hearts upon ingestion, provides 2 min Absorption V and 8 seconds Regeneration III.") + misc("pill.heal", "Provides 8 seconds of Regeneration III.") misc("pill.heal_android", "Does nothing to androids.") misc("pill.not_normal", "Instantly kills fleshy creatures upon ingestion") diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt index 9a8cfdc09..cc3b3a7d4 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt @@ -390,7 +390,7 @@ private fun misc(provider: MatteryLanguageProvider) { misc("pill.oblivion", "Предметы и Очки опыта, потраченные на исследования полностью возвращаются.") misc("pill.message_oblivion", "Все возможности андроида были удалены, а потраченные на исследования предметы и опыт возвращены.") - misc("pill.heal", "Мгновенно восполняет 4 сердца при употреблении, а так же даёт на 2 минуты поглощение V и на 8 секунд регенерацию III.") + misc("pill.heal", "Даёт регенерацию III на 8 секунд.") misc("pill.heal_android", "Не действует на андроидов.") misc("pill.not_normal", "Мгновенно убивает существ из плоти") diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/HealPillItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/HealPillItem.kt index 6a2212f23..6af3533ab 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/HealPillItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/HealPillItem.kt @@ -38,9 +38,7 @@ class HealPillItem : MatteryItem(Properties().stacksTo(64).rarity(Rarity.UNCOMMO return super.finishUsingItem(stack, level, ent) stack.shrink(1) - ent.addEffect(MobEffectInstance(MobEffects.ABSORPTION, 20 * 60 * 2, 4)) ent.addEffect(MobEffectInstance(MobEffects.REGENERATION, 20 * 8, 2)) - ent.heal(8f) return stack } From 6c0265582acb4a5399d750dbc8ccf7bc3fd94a36 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 10 Mar 2025 20:33:28 +0700 Subject: [PATCH 2/6] 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 From 0159931930767785ed9ad67ac4ead54963902486 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 11 Mar 2025 11:39:22 +0700 Subject: [PATCH 3/6] Faster otmRandom --- .../java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java | 10 ++++------ .../kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt | 8 ++------ 2 files changed, 6 insertions(+), 12 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 7ef475bbd..9930b5a28 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java +++ b/src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java @@ -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; } } 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 cf0ad7e10..583febb3c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt @@ -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 From 5a016bef1b744480e55cbce01576eefb970b6877 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 11 Mar 2025 16:55:55 +0700 Subject: [PATCH 4/6] Remove otmRandom --- .../dbotthepony/mc/otm/mixin/LevelMixin.java | 19 ------------------- .../mixin/MixinAbstractHurtingProjectile.java | 3 +-- .../android/feature/EnderTeleporterFeature.kt | 8 ++++---- .../entity/blackhole/BlackHoleBlockEntity.kt | 4 ++-- .../BlackHoleGeneratorBlockEntity.kt | 6 +++--- .../block/entity/cable/EnergyCableGraph.kt | 4 ++-- .../decorative/CargoCrateBlockEntity.kt | 4 ++-- .../matter/MatterDecomposerBlockEntity.kt | 4 ++-- .../matter/MatterReconstructorBlockEntity.kt | 4 ++-- .../matter/MatterRecyclerBlockEntity.kt | 4 ++-- .../matter/MatterReplicatorBlockEntity.kt | 4 ++-- .../tech/AbstractPoweredFurnaceBlockEntity.kt | 4 ++-- .../entity/tech/AndroidChargerBlockEntity.kt | 4 ++-- .../entity/tech/AndroidStationBlockEntity.kt | 4 ++-- .../entity/tech/BatteryBankBlockEntity.kt | 4 ++-- .../entity/tech/EnergyInterfaceBlockEntity.kt | 4 ++-- .../entity/tech/EssenceStorageBlockEntity.kt | 6 +++--- .../entity/tech/PlatePressBlockEntity.kt | 4 ++-- .../mc/otm/capability/MatteryPlayer.kt | 4 ++-- .../dbotthepony/mc/otm/core/IMatteryLevel.kt | 17 ----------------- .../mc/otm/entity/MinecartCargoCrate.kt | 4 ++-- .../mc/otm/entity/SpawnModifiers.kt | 6 +++--- .../ru/dbotthepony/mc/otm/item/BatteryItem.kt | 4 ++-- .../item/consumables/EssenceCapsuleItem.kt | 4 ++-- .../item/consumables/ImperfectBreadItem.kt | 4 ++-- .../mc/otm/item/tool/ExplosiveHammerItem.kt | 4 ++-- .../mc/otm/item/weapon/EnergySwordItem.kt | 10 +++++----- .../mc/otm/item/weapon/FallingSunItem.kt | 10 +++++----- .../mc/otm/network/MatteryPlayerPackets.kt | 4 ++-- .../mc/otm/network/SmokeParticlesPacket.kt | 4 ++-- .../overdrive_that_matters.mixins.json | 3 +-- 31 files changed, 67 insertions(+), 105 deletions(-) delete mode 100644 src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java delete mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt diff --git a/src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java b/src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java deleted file mode 100644 index 9930b5a28..000000000 --- a/src/main/java/ru/dbotthepony/mc/otm/mixin/LevelMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package ru.dbotthepony.mc.otm.mixin; - -import net.minecraft.util.RandomSource; -import net.minecraft.world.level.Level; -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 final RandomSource otm_random = ModList.get().isLoaded("better_random") ? null : new GJRAND64RandomSource(); - - @Override - public @Nullable RandomSource getOtmRandom() { - return otm_random; - } -} diff --git a/src/main/java/ru/dbotthepony/mc/otm/mixin/MixinAbstractHurtingProjectile.java b/src/main/java/ru/dbotthepony/mc/otm/mixin/MixinAbstractHurtingProjectile.java index 3733aedb7..75c813851 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/mixin/MixinAbstractHurtingProjectile.java +++ b/src/main/java/ru/dbotthepony/mc/otm/mixin/MixinAbstractHurtingProjectile.java @@ -8,7 +8,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import ru.dbotthepony.mc.otm.capability.IMatteryPlayer; -import ru.dbotthepony.mc.otm.core.IMatteryLevel; import ru.dbotthepony.mc.otm.registry.game.MSoundEvents; @Mixin(AbstractHurtingProjectile.class) @@ -25,7 +24,7 @@ public class MixinAbstractHurtingProjectile { AbstractHurtingProjectile proj = (AbstractHurtingProjectile)(Object)this; if (cap.isAndroid() && proj.getOwner() != entity) { - entity.level().playSound(entity, proj.blockPosition(), MSoundEvents.INSTANCE.getANDROID_PROJ_PARRY(), SoundSource.PLAYERS, 1.0f, 0.95f + ((IMatteryLevel) entity.level()).getOtmRandom().nextFloat() * 0.1f); + entity.level().playSound(entity, proj.blockPosition(), MSoundEvents.INSTANCE.getANDROID_PROJ_PARRY(), SoundSource.PLAYERS, 1.0f, 0.95f + entity.level().getRandom().nextFloat() * 0.1f); } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/EnderTeleporterFeature.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/EnderTeleporterFeature.kt index a90aebf88..7668a679d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/EnderTeleporterFeature.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/EnderTeleporterFeature.kt @@ -49,7 +49,7 @@ import ru.dbotthepony.mc.otm.core.math.rotateXDegrees import ru.dbotthepony.mc.otm.core.math.rotateYDegrees import ru.dbotthepony.mc.otm.core.math.shortestDistanceBetween import ru.dbotthepony.mc.otm.core.math.times -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.milliTime import ru.dbotthepony.mc.otm.registry.game.AndroidFeatures import ru.dbotthepony.mc.otm.triggers.EnderTeleporterFallDeathTrigger @@ -303,7 +303,7 @@ class EnderTeleporterFeature(capability: MatteryPlayer) : AndroidActiveFeature(A val event = EventHooks.onEnderTeleport(ply, blockPos.x + 0.5, blockPos.y.toDouble(), blockPos.z + 0.5) if (event.isCanceled) { - (ply as ServerPlayer).connection.send(ClientboundSoundEntityPacket(SoundEvents.ITEM_BREAK.holder, SoundSource.PLAYERS, ply, 0.3f, 0.5f, ply.level().otmRandom.nextLong())) + (ply as ServerPlayer).connection.send(ClientboundSoundEntityPacket(SoundEvents.ITEM_BREAK.holder, SoundSource.PLAYERS, ply, 0.3f, 0.5f, ply.level().random.nextLong())) return false } @@ -311,9 +311,9 @@ class EnderTeleporterFeature(capability: MatteryPlayer) : AndroidActiveFeature(A lastTeleport = ply.server!!.tickCount android.androidEnergy.extractEnergy(AndroidConfig.EnderTeleporter.ENERGY_COST, false) - ply.level().playSound(null, ply, SoundEvents.ENDERMAN_TELEPORT, SoundSource.PLAYERS, 0.3f, 0.8f + ply.level().otmRandom.nextFloat() * 0.4f) + ply.level().playSound(null, ply, SoundEvents.ENDERMAN_TELEPORT, SoundSource.PLAYERS, 0.3f, 0.8f + ply.level().random.nextFloat() * 0.4f) ply.teleportTo(event.targetX, event.targetY, event.targetZ) - ply.level().playSound(null, ply, SoundEvents.ENDERMAN_TELEPORT, SoundSource.PLAYERS, 1f, 0.8f + ply.level().otmRandom.nextFloat() * 0.4f) + ply.level().playSound(null, ply, SoundEvents.ENDERMAN_TELEPORT, SoundSource.PLAYERS, 1f, 0.8f + ply.level().random.nextFloat() * 0.4f) ply.deltaMovement = Vector(0.0, 0.0, 0.0) ply.resetFallDistance() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt index c94c15b68..0cc196d20 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt @@ -44,7 +44,7 @@ import ru.dbotthepony.mc.otm.core.math.getSphericalBlockPositions import ru.dbotthepony.mc.otm.core.math.times import ru.dbotthepony.mc.otm.core.nbt.map import ru.dbotthepony.mc.otm.core.nbt.set -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.isClient import ru.dbotthepony.mc.otm.matter.MatterManager import ru.dbotthepony.mc.otm.registry.MDamageTypes @@ -271,7 +271,7 @@ class BlackHoleBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mattery } // шанс 1% что черная дыра потеряет 0.1 MtU каждую секунду * силу гравитации дыры ^ -1 - if (level.otmRandom.nextDouble() < 0.01 * 0.05 * (1 / gravitationStrength)) { + if (level.random.nextDouble() < 0.01 * 0.05 * (1 / gravitationStrength)) { this.mass += HAWKING_MASS_LOSE_STEP } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleGeneratorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleGeneratorBlockEntity.kt index 84c9bba76..5347f3248 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleGeneratorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleGeneratorBlockEntity.kt @@ -34,7 +34,7 @@ import ru.dbotthepony.mc.otm.core.math.times import ru.dbotthepony.mc.otm.core.multiblock.BlockEntityTag import ru.dbotthepony.mc.otm.core.multiblock.MultiblockStatus import ru.dbotthepony.mc.otm.core.multiblock.shapedMultiblock -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.core.util.InvalidableLazy import ru.dbotthepony.mc.otm.menu.tech.BlackHoleGeneratorMenu import ru.dbotthepony.mc.otm.registry.game.MBlockEntities @@ -86,8 +86,8 @@ class BlackHoleGeneratorBlockEntity(blockPos: BlockPos, blockState: BlockState) multiblock?.blockEntities(MatterHatchBlockEntity.INPUT_TAG)?.iterator()?.map { it.matter }?.toList() ?: listOf() } - val energy = CombinedProfiledEnergyStorage(FlowDirection.NONE, energyTarget::value, { level?.otmRandom }) - val matter = CombinedProfiledMatterStorage(FlowDirection.NONE, matterTarget::value, { level?.otmRandom }) + val energy = CombinedProfiledEnergyStorage(FlowDirection.NONE, energyTarget::value, { level?.random }) + val matter = CombinedProfiledMatterStorage(FlowDirection.NONE, matterTarget::value, { level?.random }) enum class Mode(val label: Component, val tooltip: Component) { TARGET_MASS(TranslatableComponent("otm.gui.black_hole_generator.sustain.mode"), TranslatableComponent("otm.gui.black_hole_generator.sustain.desc")), diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt index 8434ce627..21ebb4928 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt @@ -14,7 +14,7 @@ import ru.dbotthepony.mc.otm.core.collect.map import ru.dbotthepony.mc.otm.core.collect.reduce import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.RelativeSide -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.core.shuffle import ru.dbotthepony.mc.otm.graph.GraphNodeList import ru.dbotthepony.mc.otm.onceServer @@ -627,7 +627,7 @@ class EnergyCableGraph : GraphNodeList= failureChance * upgrades.failureMultiplier) + if (failureChance * upgrades.failureMultiplier <= 0.0 || level!!.random.nextDouble() >= failureChance * upgrades.failureMultiplier) repairProgress += progressPerTick energy.extractEnergy(energyConsumption * (progressPerTick / thisProgressPerTick), false) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt index d8fe21afe..87405bf61 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt @@ -24,7 +24,7 @@ import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.core.math.Decimal -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.graph.matter.MatterGraph import ru.dbotthepony.mc.otm.item.matter.MatterDustItem import ru.dbotthepony.mc.otm.menu.matter.MatterRecyclerMenu @@ -117,7 +117,7 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState) stack.shrink(1) container.setChanged(0) - val actualMatter = dustMatter.matter * (0.4 + level!!.otmRandom.nextDouble() * 0.6) + val actualMatter = dustMatter.matter * (0.4 + level!!.random.nextDouble() * 0.6) return JobContainer.success( RecyclerJob( diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt index ac9f9c181..944b3c954 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt @@ -28,7 +28,7 @@ import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.core.math.Decimal -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.data.codec.DecimalCodec import ru.dbotthepony.mc.otm.data.codec.minRange import ru.dbotthepony.mc.otm.graph.matter.MatterNode @@ -184,7 +184,7 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : task = allocation.task.id, matterValue = matter.matter, pattern = Optional.ofNullable(allocation.pattern), - asDust = (level?.otmRandom?.nextDouble() ?: 1.0) * upgrades.failureMultiplier > (allocation.pattern?.researchPercent ?: 2.0), + asDust = (level?.random?.nextDouble() ?: 1.0) * upgrades.failureMultiplier > (allocation.pattern?.researchPercent ?: 2.0), ticks = ticks, )) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AbstractPoweredFurnaceBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AbstractPoweredFurnaceBlockEntity.kt index 4ca9c7317..48e11140b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AbstractPoweredFurnaceBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AbstractPoweredFurnaceBlockEntity.kt @@ -35,7 +35,7 @@ import ru.dbotthepony.mc.otm.container.balance import ru.dbotthepony.mc.otm.core.collect.filter import ru.dbotthepony.mc.otm.core.collect.maybe import ru.dbotthepony.mc.otm.core.immutableList -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.menu.tech.PoweredFurnaceMenu import ru.dbotthepony.mc.otm.recipe.MatteryCookingRecipe import ru.dbotthepony.mc.otm.recipe.MicrowaveRecipe @@ -153,7 +153,7 @@ sealed class AbstractPoweredFurnaceBlockEntity

0f) { - repairPoints += if ((level?.otmRandom?.nextFloat() ?: 1f) <= diff) 1 else 0 + repairPoints += if ((level?.random?.nextFloat() ?: 1f) <= diff) 1 else 0 } experienceStored -= 1 @@ -202,7 +202,7 @@ class EssenceStorageBlockEntity(blockPos: BlockPos, blockState: BlockState) : Ma level!!.playSound(null, ent.x, ent.y, ent.z, SoundEvents.EXPERIENCE_ORB_PICKUP, SoundSource.BLOCKS, - 0.1F, 0.5F + level!!.otmRandom.nextFloat() * 0.25F + 0.1F, 0.5F + level!!.random.nextFloat() * 0.25F ) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt index bc8c6e1aa..1db3ae35b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt @@ -21,7 +21,7 @@ import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.container.balance import ru.dbotthepony.mc.otm.core.collect.filter import ru.dbotthepony.mc.otm.core.collect.maybe -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.menu.tech.PlatePressMenu import ru.dbotthepony.mc.otm.registry.game.MBlockEntities import ru.dbotthepony.mc.otm.registry.game.MRecipes @@ -90,7 +90,7 @@ class PlatePressBlockEntity( recipe.getResultItem(level.registryAccess()).copyWithCount(toProcess), recipe.workTime * MachinesConfig.PLATE_PRESS.workTimeMultiplier, MachinesConfig.PLATE_PRESS.energyConsumption * toProcess, - experience = recipe.experience.sample(level.otmRandom) * toProcess)) + experience = recipe.experience.sample(level.random) * toProcess)) } override fun tick() { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayer.kt index 717b6d975..24a237b93 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayer.kt @@ -532,7 +532,7 @@ class MatteryPlayer(val ply: Player) { override fun onJobTick(status: JobStatus) { super.onJobTick(status) - if (isExopackVisible && ply.level().otmRandom.nextFloat() <= 0.05f) { + if (isExopackVisible && ply.level().random.nextFloat() <= 0.05f) { PacketDistributor.sendToPlayersTrackingEntityAndSelf(ply, ExopackSmokePacket(ply.uuid)) } } @@ -1397,7 +1397,7 @@ class MatteryPlayer(val ply: Player) { pos.mul(RenderSystem.getProjectionMatrix()) pos.mul(poseStack.last().pose()) - makeSmoke(cam.x + pos.x, cam.y + pos.y, cam.z + pos.z, ply.level().otmRandom, ply.level()) + makeSmoke(cam.x + pos.x, cam.y + pos.y, cam.z + pos.z, ply.level().random, ply.level()) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt deleted file mode 100644 index 583febb3c..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/IMatteryLevel.kt +++ /dev/null @@ -1,17 +0,0 @@ -package ru.dbotthepony.mc.otm.core - -import net.minecraft.util.RandomSource -import net.minecraft.world.level.Level -import net.neoforged.fml.ModList - -interface IMatteryLevel { - /** - * 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 IMatteryLevel).otmRandom ?: random diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/entity/MinecartCargoCrate.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/entity/MinecartCargoCrate.kt index ee09e29ff..5c66894fb 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/entity/MinecartCargoCrate.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/entity/MinecartCargoCrate.kt @@ -19,7 +19,7 @@ import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.gameevent.GameEvent import ru.dbotthepony.mc.otm.block.decorative.CargoCrateBlock import ru.dbotthepony.mc.otm.block.entity.decorative.CargoCrateBlockEntity -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.core.position import ru.dbotthepony.mc.otm.menu.decorative.MinecartCargoCrateMenu import ru.dbotthepony.mc.otm.registry.game.MItems @@ -90,7 +90,7 @@ class MinecartCargoCrate( if (interactingPlayers++ == 0) { if (!isRemoved) { - level().playSound(null, this, MSoundEvents.CARGO_CRATE_OPEN, SoundSource.BLOCKS, 1f, 0.8f + level().otmRandom.nextFloat() * 0.2f) + level().playSound(null, this, MSoundEvents.CARGO_CRATE_OPEN, SoundSource.BLOCKS, 1f, 0.8f + level().random.nextFloat() * 0.2f) this.gameEvent(GameEvent.CONTAINER_OPEN, player) PiglinAi.angerNearbyPiglins(player, true) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/entity/SpawnModifiers.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/entity/SpawnModifiers.kt index d7d1bb5d4..386c0bb06 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/entity/SpawnModifiers.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/entity/SpawnModifiers.kt @@ -7,7 +7,7 @@ import net.minecraft.world.item.Items import net.neoforged.bus.api.SubscribeEvent import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent import ru.dbotthepony.mc.otm.config.ServerConfig -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.registry.game.MItems @@ -17,8 +17,8 @@ object WitheredSkeletonSpawnHandler { val entity = event.entity if (entity is WitherSkeleton) { - val giveHelmet = event.level.otmRandom.nextFloat() < ServerConfig.WITHER_SKELETON_HELMET_CHANCE - val giveSword = event.level.otmRandom.nextFloat() < ServerConfig.WITHER_SKELETON_SWORD_CHANCE + val giveHelmet = event.level.random.nextFloat() < ServerConfig.WITHER_SKELETON_HELMET_CHANCE + val giveSword = event.level.random.nextFloat() < ServerConfig.WITHER_SKELETON_SWORD_CHANCE if (giveHelmet) { if (!entity.hasItemInSlot(EquipmentSlot.HEAD)) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/BatteryItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/BatteryItem.kt index 5cbcab0f0..d7b76d2a1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/BatteryItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/BatteryItem.kt @@ -184,7 +184,7 @@ class CrudeBatteryItem : BatteryItem(ItemsConfig.Batteries.CRUDE) { if (player is ServerPlayer) { if (!mattery.androidEnergy.item.isEmpty) { mattery.androidEnergy.item.getCapability(Capabilities.EnergyStorage.ITEM)?.let { - it.extractEnergy((it.maxEnergyStored * level.otmRandom.nextFloat() * .2f).roundToInt(), false) + it.extractEnergy((it.maxEnergyStored * level.random.nextFloat() * .2f).roundToInt(), false) } mattery.dropBattery() @@ -194,7 +194,7 @@ class CrudeBatteryItem : BatteryItem(ItemsConfig.Batteries.CRUDE) { copyStack.count = 1 mattery.androidEnergy.item = copyStack - val extraDamageMult = level.otmRandom.nextFloat() + val extraDamageMult = level.random.nextFloat() player.hurt(MatteryDamageSource(level.registryAccess().damageType(MDamageTypes.EMP), inflictor = itemStack), 1.5f + extraDamageMult * 3.5f) val debuffDuration = 100 + (100 * (1f - extraDamageMult)).roundToInt() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/EssenceCapsuleItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/EssenceCapsuleItem.kt index 91d300ed5..1ae7e9fdd 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/EssenceCapsuleItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/EssenceCapsuleItem.kt @@ -17,7 +17,7 @@ import ru.dbotthepony.mc.otm.capability.matteryPlayer import ru.dbotthepony.mc.otm.client.isShiftDown import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.core.TranslatableComponent -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.core.util.getLevelFromXp import ru.dbotthepony.mc.otm.item.MatteryItem import ru.dbotthepony.mc.otm.registry.game.MDataComponentTypes @@ -81,7 +81,7 @@ class EssenceCapsuleItem(private val digital: Boolean) : MatteryItem(Properties( } else { if (level is ServerLevel) { level.levelEvent(2002, player.blockPosition(), PotionContents.getColor(Potions.WATER)) - ExperienceOrb.award(level, player.position(), (exp * (.5 + level.otmRandom.nextFloat() * .25)).toInt()) + ExperienceOrb.award(level, player.position(), (exp * (.5 + level.random.nextFloat() * .25)).toInt()) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/ImperfectBreadItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/ImperfectBreadItem.kt index 089de13fc..9a3022448 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/ImperfectBreadItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/consumables/ImperfectBreadItem.kt @@ -9,7 +9,7 @@ import net.minecraft.world.entity.item.ItemEntity import net.minecraft.world.item.ItemStack import net.minecraft.world.level.Level import ru.dbotthepony.mc.otm.core.TranslatableComponent -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.core.position import ru.dbotthepony.mc.otm.entity.BreadMonster import ru.dbotthepony.mc.otm.item.MatteryItem @@ -39,7 +39,7 @@ class ImperfectBreadItem(properties: Properties) : MatteryItem(properties) { // roll multiple times so multiple bread monsters can spawn on tick // and also chance be less biased for (i in 0 until stack.count.coerceAtMost(16)) { - if (entity.level().otmRandom.nextFloat() < 0.001f) { + if (entity.level().random.nextFloat() < 0.001f) { val ent = BreadMonster(entity.level()) ent.position = entity.position entity.level().addFreshEntity(ent) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/tool/ExplosiveHammerItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/tool/ExplosiveHammerItem.kt index 018d1d474..a79ab1ead 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/tool/ExplosiveHammerItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/tool/ExplosiveHammerItem.kt @@ -84,7 +84,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1) itemStack.hurtAndBreak(8, level, player) {} if (isPrimed(itemStack)) { - itemStack.hurtAndBreak(level.otmRandom.nextInt(1, 20), level, player) {} + itemStack.hurtAndBreak(level.random.nextInt(1, 20), level, player) {} unprime(itemStack) val (ex, ey, ez) = Vector.atCenterOf(player.blockPosition()) @@ -226,7 +226,7 @@ class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1) val copy = itemStack.copy() - itemStack.hurtAndBreak(level.otmRandom.nextInt(1, 20), attacker, EquipmentSlot.MAINHAND) + itemStack.hurtAndBreak(level.random.nextInt(1, 20), attacker, EquipmentSlot.MAINHAND) if (!itemStack.isEmpty && attacker.random.nextDouble() <= ToolsConfig.ExplosiveHammer.FLY_OFF_CHANCE) { attacker.setItemInHand(hand, ItemStack.EMPTY) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/EnergySwordItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/EnergySwordItem.kt index ec7cc1d4a..881c3d745 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/EnergySwordItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/EnergySwordItem.kt @@ -33,7 +33,7 @@ import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue import ru.dbotthepony.mc.otm.core.math.defineDecimal import ru.dbotthepony.mc.otm.core.math.nextVariance -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.core.util.WriteOnce import ru.dbotthepony.mc.otm.item.MatteryItem import ru.dbotthepony.mc.otm.item.addSimpleDescription @@ -98,10 +98,10 @@ class EnergySwordItem : MatteryItem(Properties().stacksTo(1).rarity(Rarity.RARE) itemStack.getCapability(MatteryCapability.ITEM_ENERGY)?.let { if (it.extractEnergyExact(ENERGY_PER_SWING, false)) { - it.extractEnergy(attacker.level().otmRandom.nextVariance(ENERGY_PER_SWING_VARIANCE), false) + it.extractEnergy(attacker.level().random.nextVariance(ENERGY_PER_SWING_VARIANCE), false) victim.matteryPlayer?.let { if (it.isAndroid && it.androidEnergy.extractEnergyExact(ENERGY_ZAP, false)) { - it.androidEnergy.extractEnergy(attacker.level().otmRandom.nextVariance(ENERGY_ZAP_VARIANCE), false) + it.androidEnergy.extractEnergy(attacker.level().random.nextVariance(ENERGY_ZAP_VARIANCE), false) victim.hurt(MatteryDamageSource(attacker.level().registryAccess().damageType(MDamageTypes.EMP), attacker, itemStack), 8f) } } @@ -144,12 +144,12 @@ class EnergySwordItem : MatteryItem(Properties().stacksTo(1).rarity(Rarity.RARE) if (blockState.`is`(BlockTags.SWORD_EFFICIENT)) { if (energy?.extractEnergyExact(PLANT_POWER_COST, false) == true) - energy.extractEnergyExact(user.level().otmRandom.nextVariance(PLANT_POWER_COST_VARIANCE), false) + energy.extractEnergyExact(user.level().random.nextVariance(PLANT_POWER_COST_VARIANCE), false) } if (blockState.`is`(Blocks.COBWEB)) { if (energy?.extractEnergyExact(COBWEB_POWER_COST, false) == true) - energy.extractEnergyExact(user.level().otmRandom.nextVariance(COBWEB_POWER_COST_VARIANCE), false) + energy.extractEnergyExact(user.level().random.nextVariance(COBWEB_POWER_COST_VARIANCE), false) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/FallingSunItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/FallingSunItem.kt index 6ba1ef311..23b40cd7d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/FallingSunItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/weapon/FallingSunItem.kt @@ -33,7 +33,7 @@ import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue import ru.dbotthepony.mc.otm.core.math.defineDecimal import ru.dbotthepony.mc.otm.core.math.nextVariance -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.core.util.WriteOnce import ru.dbotthepony.mc.otm.item.MatteryItem import ru.dbotthepony.mc.otm.item.addSimpleDescription @@ -98,10 +98,10 @@ class FallingSunItem : MatteryItem(Properties().stacksTo(1).rarity(Rarity.EPIC)) itemStack.getCapability(MatteryCapability.ITEM_ENERGY)?.let { if (it.extractEnergyExact(ENERGY_PER_SWING, false)) { - it.extractEnergy(attacker.level().otmRandom.nextVariance(ENERGY_PER_SWING_VARIANCE), false) + it.extractEnergy(attacker.level().random.nextVariance(ENERGY_PER_SWING_VARIANCE), false) victim.matteryPlayer?.let { if (it.isAndroid && it.androidEnergy.extractEnergyExact(ENERGY_ZAP, false)) { - it.androidEnergy.extractEnergy(attacker.level().otmRandom.nextVariance(ENERGY_ZAP_VARIANCE), false) + it.androidEnergy.extractEnergy(attacker.level().random.nextVariance(ENERGY_ZAP_VARIANCE), false) victim.hurt(MatteryDamageSource(attacker.level().registryAccess().damageType(MDamageTypes.EMP), attacker, itemStack), 8f) } } @@ -144,12 +144,12 @@ class FallingSunItem : MatteryItem(Properties().stacksTo(1).rarity(Rarity.EPIC)) if (blockState.`is`(BlockTags.SWORD_EFFICIENT)) { if (energy?.extractEnergyExact(PLANT_POWER_COST, false) == true) - energy.extractEnergyExact(user.level().otmRandom.nextVariance(PLANT_POWER_COST_VARIANCE), false) + energy.extractEnergyExact(user.level().random.nextVariance(PLANT_POWER_COST_VARIANCE), false) } if (blockState.`is`(Blocks.COBWEB)) { if (energy?.extractEnergyExact(COBWEB_POWER_COST, false) == true) - energy.extractEnergyExact(user.level().otmRandom.nextVariance(COBWEB_POWER_COST_VARIANCE), false) + energy.extractEnergyExact(user.level().random.nextVariance(COBWEB_POWER_COST_VARIANCE), false) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/network/MatteryPlayerPackets.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/network/MatteryPlayerPackets.kt index 166cadfae..0fb081906 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/network/MatteryPlayerPackets.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/network/MatteryPlayerPackets.kt @@ -24,7 +24,7 @@ import ru.dbotthepony.mc.otm.core.math.component1 import ru.dbotthepony.mc.otm.core.math.component2 import ru.dbotthepony.mc.otm.core.math.component3 import ru.dbotthepony.mc.otm.core.math.toRadians -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random import ru.dbotthepony.mc.otm.core.position import ru.dbotthepony.mc.otm.core.readItem import ru.dbotthepony.mc.otm.core.writeItem @@ -446,7 +446,7 @@ class ExopackSmokePacket(val player: UUID) : CustomPacketPayload { z += kotlin.math.sin(deg) * -0.4 val level = ply.level() - val random = level.otmRandom + val random = level.random for (i in 0 .. random.nextInt(2, 4)) level.addParticle( diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/network/SmokeParticlesPacket.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/network/SmokeParticlesPacket.kt index 5d87e004a..5ab9cc173 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/network/SmokeParticlesPacket.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/network/SmokeParticlesPacket.kt @@ -13,7 +13,7 @@ import net.neoforged.neoforge.network.handling.IPayloadContext import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.core.ResourceLocation -import ru.dbotthepony.mc.otm.core.otmRandom +import ru.dbotthepony.mc.otm.core.random class SmokeParticlesPacket(val x: Double, val y: Double, val z: Double) : CustomPacketPayload { fun write(buff: FriendlyByteBuf) { @@ -24,7 +24,7 @@ class SmokeParticlesPacket(val x: Double, val y: Double, val z: Double) : Custom fun play(context: IPayloadContext) { minecraft.player?.level()?.let { - makeSmoke(x, y, z, it.otmRandom, it) + makeSmoke(x, y, z, it.random, it) } } diff --git a/src/main/resources/overdrive_that_matters.mixins.json b/src/main/resources/overdrive_that_matters.mixins.json index f317fa83a..934ead87e 100644 --- a/src/main/resources/overdrive_that_matters.mixins.json +++ b/src/main/resources/overdrive_that_matters.mixins.json @@ -18,8 +18,7 @@ "HopperBlockEntityMixin", "DispenserBlockEntityMixin", "GuiGraphicsMixin", - "BlockStateBaseMixin", - "LevelMixin" + "BlockStateBaseMixin" ], "client": [ "MixinGameRenderer", From a6ba428518856f1d5d2855ff5ac0a13f44319120 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 11 Mar 2025 16:56:51 +0700 Subject: [PATCH 5/6] Remove custom random generators except for gjrand64 which is used for worldgen --- .../mc/otm/core/util/CMWCRandom.kt | 117 ------------------ .../mc/otm/core/util/LCG64RandomSource.kt | 59 --------- .../mc/otm/core/util/PCG32RandomSource.kt | 51 -------- .../mc/otm/core/util/Xoshiro256Random.kt | 93 -------------- 4 files changed, 320 deletions(-) delete mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/core/util/CMWCRandom.kt delete mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/core/util/LCG64RandomSource.kt delete mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/core/util/PCG32RandomSource.kt delete mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Xoshiro256Random.kt diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/CMWCRandom.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/CMWCRandom.kt deleted file mode 100644 index 16225f78f..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/CMWCRandom.kt +++ /dev/null @@ -1,117 +0,0 @@ -package ru.dbotthepony.mc.otm.core.util - -import net.minecraft.util.Mth -import net.minecraft.util.RandomSource -import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian -import net.minecraft.world.level.levelgen.PositionalRandomFactory -import net.minecraft.world.level.levelgen.RandomSupport -import ru.dbotthepony.kommons.random.PCG32Random -import java.lang.StringBuilder -import java.util.random.RandomGenerator - -/** - * Random number generator with insane period of at least 2^511 - */ -class CMWCRandom(seed: Long = RandomSupport.generateUniqueSeed()) : RandomGenerator, RandomSource { - private val state = IntArray(CMWC_STATE_SIZE) - private var carry = 0 - private var stateIndex = 0 - private val gaussian = MarsagliaPolarGaussian(this) - - init { - setSeed(seed) - } - - override fun setSeed(seed: Long) { - val rng = PCG32Random(seed) - - // init state with regular LCG produced values - for (i in 1 until state.size) { - state[i] = rng.nextInt() - } - - do { - carry = rng.nextInt() - } while(carry !in 0 until CMWC_CARRY_MAX) - - stateIndex = state.size - 1 - gaussian.reset() - } - - override fun nextInt(): Int { - stateIndex = (stateIndex + 1).and(CMWC_STATE_SIZE - 1) - val t = 18782L * state[stateIndex] + carry - - carry = t.ushr(32).toInt() - var x = t.toInt() + carry - - if (x < carry) { - x++ - carry++ - } - - state[stateIndex] = 0xfffffffe.toInt() - x - return state[stateIndex] - } - - override fun nextLong(): Long { - val a = nextInt().toLong() and 0xFFFFFFFFL - val b = nextInt().toLong() and 0xFFFFFFFFL - return a.shl(32) or b - } - - override fun nextInt(bound: Int): Int { - return super.nextInt(bound) - } - - override fun nextInt(origin: Int, bound: Int): Int { - return super.nextInt(origin, bound) - } - - override fun nextBoolean(): Boolean { - return super.nextBoolean() - } - - override fun nextFloat(): Float { - return super.nextFloat() - } - - override fun nextDouble(): Double { - return super.nextDouble() - } - - override fun nextGaussian(): Double { - return gaussian.nextGaussian() - } - - override fun fork(): RandomSource { - return CMWCRandom(nextLong()) - } - - override fun forkPositional(): PositionalRandomFactory { - return Positional(nextLong()) - } - - class Positional(private val seed: Long) : PositionalRandomFactory { - override fun at(x: Int, y: Int, z: Int): RandomSource { - return CMWCRandom(Mth.getSeed(x, y, z).xor(seed)) - } - - override fun fromHashOf(name: String): RandomSource { - return CMWCRandom(name.hashCode().toLong().xor(seed)) - } - - override fun fromSeed(seed: Long): RandomSource { - return CMWCRandom(seed) - } - - override fun parityConfigString(builder: StringBuilder) { - throw UnsupportedOperationException() - } - } - - companion object { - const val CMWC_STATE_SIZE = 32 // 4096 - const val CMWC_CARRY_MAX = 809430660 - } -} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/LCG64RandomSource.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/LCG64RandomSource.kt deleted file mode 100644 index 849e38e87..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/LCG64RandomSource.kt +++ /dev/null @@ -1,59 +0,0 @@ -package ru.dbotthepony.mc.otm.core.util - -import net.minecraft.util.Mth -import net.minecraft.util.RandomSource -import net.minecraft.world.level.levelgen.LegacyRandomSource -import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian -import net.minecraft.world.level.levelgen.PositionalRandomFactory -import net.minecraft.world.level.levelgen.RandomSupport -import ru.dbotthepony.kommons.random.LCG64Random -import java.lang.StringBuilder - -/** - * Simple and insanely fast random number generator, which can be used for seeding (initializing internal state) of other number generators. - * - * While can be used on its own, it probably shouldn't. - * - * Differs from [LegacyRandomSource] (also LCG, created by [RandomSource.create]) Minecraft uses in: - * * Different constants (with supposedly/expected better statistical properties) - * * Always use upper 32 bits instead of implementing BitRandomSource and sampling some upper bits - * * Uses all bits from provided seed - */ -class LCG64RandomSource(seed: Long = RandomSupport.generateUniqueSeed()) : LCG64Random(seed), IRandomSourceGenerator { - private val gaussian = MarsagliaPolarGaussian(this) - - override fun setSeed(seed: Long) { - this.seed = seed - gaussian.reset() - } - - override fun nextGaussian(): Double { - return gaussian.nextGaussian() - } - - override fun fork(): RandomSource { - return LCG64RandomSource(nextLong()) - } - - override fun forkPositional(): PositionalRandomFactory { - return Positional(nextLong()) - } - - class Positional(private val seed: Long) : PositionalRandomFactory { - override fun at(x: Int, y: Int, z: Int): RandomSource { - return LCG64RandomSource(Mth.getSeed(x, y, z).xor(seed)) - } - - override fun fromHashOf(name: String): RandomSource { - return LCG64RandomSource(name.hashCode().toLong().xor(seed)) - } - - override fun fromSeed(seed: Long): RandomSource { - return LCG64RandomSource(seed) - } - - override fun parityConfigString(builder: StringBuilder) { - throw UnsupportedOperationException() - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/PCG32RandomSource.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/PCG32RandomSource.kt deleted file mode 100644 index ae2f74205..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/PCG32RandomSource.kt +++ /dev/null @@ -1,51 +0,0 @@ -package ru.dbotthepony.mc.otm.core.util - -import net.minecraft.util.Mth -import net.minecraft.util.RandomSource -import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian -import net.minecraft.world.level.levelgen.PositionalRandomFactory -import net.minecraft.world.level.levelgen.RandomSupport -import ru.dbotthepony.kommons.random.PCG32Random -import java.lang.StringBuilder - -/** - * @see PCG32Random - */ -class PCG32RandomSource(seed: Long = RandomSupport.generateUniqueSeed()) : PCG32Random(seed), IRandomSourceGenerator { - private val gaussian = MarsagliaPolarGaussian(this) - - override fun setSeed(seed: Long) { - this.seed = seed - gaussian.reset() - } - - override fun nextGaussian(): Double { - return gaussian.nextGaussian() - } - - override fun fork(): RandomSource { - return PCG32RandomSource(nextLong()) - } - - override fun forkPositional(): PositionalRandomFactory { - return Positional(nextLong()) - } - - class Positional(private val seed: Long) : PositionalRandomFactory { - override fun at(x: Int, y: Int, z: Int): RandomSource { - return PCG32RandomSource(Mth.getSeed(x, y, z).xor(seed)) - } - - override fun fromHashOf(name: String): RandomSource { - return PCG32RandomSource(name.hashCode().toLong().xor(seed)) - } - - override fun fromSeed(seed: Long): RandomSource { - return PCG32RandomSource(seed) - } - - override fun parityConfigString(builder: StringBuilder) { - throw UnsupportedOperationException() - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Xoshiro256Random.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Xoshiro256Random.kt deleted file mode 100644 index 133762f55..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Xoshiro256Random.kt +++ /dev/null @@ -1,93 +0,0 @@ -package ru.dbotthepony.mc.otm.core.util - -import it.unimi.dsi.fastutil.HashCommon -import net.minecraft.util.Mth -import net.minecraft.util.RandomSource -import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian -import net.minecraft.world.level.levelgen.PositionalRandomFactory -import net.minecraft.world.level.levelgen.RandomSupport -import ru.dbotthepony.kommons.random.LCG64Random -import ru.dbotthepony.kommons.random.Xoshiro256StarStarRandom - -/** - * Excellent number generator with guaranteed period of 2^255 - */ -class Xoshiro256Random : Xoshiro256StarStarRandom, IRandomSourceGenerator { - private val gaussian = MarsagliaPolarGaussian(this) - - // raw - private constructor(s0: Long, s1: Long, s2: Long, s3: Long, marker: Nothing?): super(s0, s1, s2, s3, null) - // normal - constructor(s0: Long, s1: Long, s2: Long, s3: Long) : super(s0, s1, s2, s3) - - // 64-bit seeded - constructor(seed: Long) : super(1L, 2L, 3L, 4L, null) { - setSeed(seed) - } - - // completely random - constructor() : super(RandomSupport.generateUniqueSeed(), RandomSupport.generateUniqueSeed(), RandomSupport.generateUniqueSeed(), RandomSupport.generateUniqueSeed(), null) - - override fun setSeed(seed: Long) { - val rng = LCG64Random(seed) - s0 = rng.nextLong() - s1 = rng.nextLong() - s2 = rng.nextLong() - s3 = rng.nextLong() - gaussian.reset() - } - - override fun nextInt(): Int { - // sample upper bits - return nextLong().ushr(32).toInt() - } - - override fun nextGaussian(): Double { - return gaussian.nextGaussian() - } - - override fun fork(): RandomSource { - return Xoshiro256Random(nextLong(), nextLong(), nextLong(), nextLong(), null) - } - - override fun forkPositional(): PositionalRandomFactory { - return Positional(nextLong(), nextLong(), nextLong(), nextLong()) - } - - class Positional( - private val s0: Long, - private val s1: Long, - private val s2: Long, - private val s3: Long, - ) : PositionalRandomFactory { - override fun at(x: Int, y: Int, z: Int): RandomSource { - val rng = LCG64RandomSource(Mth.getSeed(x, y, z)) - - return Xoshiro256Random( - s0.rotateLeft(11).xor(rng.nextLong()), - s1.rotateLeft(22).xor(rng.nextLong()), - s2.rotateLeft(33).xor(rng.nextLong()), - s3.rotateLeft(44).xor(rng.nextLong()), - ) - } - - override fun fromHashOf(name: String): RandomSource { - return Xoshiro256Random(s0, HashCommon.murmurHash3(name.hashCode().toLong()).xor(s1), s2, s3) - } - - override fun fromSeed(seed: Long): RandomSource { - return Xoshiro256Random(seed) - } - - override fun parityConfigString(builder: StringBuilder) { - throw UnsupportedOperationException() - } - } - - companion object { - @JvmStatic - fun raw(s0: Long, s1: Long, s2: Long, s3: Long): Xoshiro256Random { - return Xoshiro256Random(s0, s1, s2, s3, null) - } - } -} From 4df51ce12667c9f6156af185e39b786977105bf5 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 11 Mar 2025 17:53:18 +0700 Subject: [PATCH 6/6] Add better random to recommended mods --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ec780c487..7e67d0f40 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Minecraft tech-oriented mod with science fiction style, about matter, and energy * [Ferrite Core](https://www.curseforge.com/minecraft/mc-mods/ferritecore), reduces memory usage * In case of Overdrive That Matters, ***greatly*** reduces JVM heap bloat caused by model data being duplicated +* Better Random ### Mods with special compatibility code