From b921658eb2f7118b59c0f292766b17f5b5ee6ee3 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 21 Mar 2025 13:34:53 +0700 Subject: [PATCH] Remove `randomGenerator` from editable panel --- .../client/screen/panels/DecimalHistoryChartPanel.kt | 2 +- .../mc/otm/client/screen/panels/EditablePanel.kt | 4 ---- .../otm/client/screen/tech/AndroidStationScreen.kt | 12 +++++++----- .../ru/dbotthepony/mc/otm/core/math/Clustering.kt | 5 +++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/DecimalHistoryChartPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/DecimalHistoryChartPanel.kt index 1b262ce32..dfc9287ab 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/DecimalHistoryChartPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/DecimalHistoryChartPanel.kt @@ -52,7 +52,7 @@ open class DecimalHistoryChartPanel>( map[1f] = formatText(maximum) - for (cluster in chart.asIterable().clusterize(randomGenerator)) { + for (cluster in chart.asIterable().clusterize(random)) { val perc = (cluster.center / maximum).toFloat() if (map.keys.none { (it - perc).absoluteValue < 0.08f }) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt index 501315db1..f828af807 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/EditablePanel.kt @@ -232,10 +232,6 @@ open class EditablePanel( } } - val randomGenerator: RandomGenerator by lazy { - RandomSource2Generator(random) - } - /** * Bigger values means lesser priority while docking, rendering and processing inputs. */ diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt index f6edd683a..0b52df472 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt @@ -7,6 +7,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap import net.minecraft.ChatFormatting import net.minecraft.client.Minecraft import net.minecraft.network.chat.Component +import net.minecraft.util.RandomSource import net.minecraft.world.entity.player.Inventory import net.minecraft.world.item.ItemStack import net.neoforged.neoforge.network.PacketDistributor @@ -34,6 +35,7 @@ import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.kommons.math.RGBAColor import ru.dbotthepony.mc.otm.player.matteryPlayer import ru.dbotthepony.mc.otm.client.screen.panels.button.BooleanButtonPanel +import ru.dbotthepony.mc.otm.core.nextFloat import ru.dbotthepony.mc.otm.menu.tech.AndroidStationMenu import ru.dbotthepony.mc.otm.network.AndroidResearchRequestPacket import java.util.* @@ -443,8 +445,8 @@ private class AndroidResearchButton( } private enum class PreviewScrollers( - val init: (EditablePanel<*>, RandomGenerator) -> Unit, - val scroll: (EditablePanel<*>, RandomGenerator) -> Boolean + val init: (EditablePanel<*>, RandomSource) -> Unit, + val scroll: (EditablePanel<*>, RandomSource) -> Boolean ) { LEFT_TO_RIGHT( init = { it, random -> @@ -540,14 +542,14 @@ class AndroidStationScreen(p_97741_: AndroidStationMenu, p_97742_: Inventory, p_ if (isPreview && !layoutInvalidated) { if (firstTick) { - scroller.init.invoke(this, randomGenerator) + scroller.init.invoke(this, random) } - val status = scroller.scroll.invoke(this, randomGenerator) + val status = scroller.scroll.invoke(this, random) if (!status) { scroller = PreviewScrollers.entries.let { it[random.nextInt(it.size)] } - scroller.init.invoke(this, randomGenerator) + scroller.init.invoke(this, random) } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Clustering.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Clustering.kt index a13d846c0..267d40356 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Clustering.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Clustering.kt @@ -1,6 +1,7 @@ package ru.dbotthepony.mc.otm.core.math import it.unimi.dsi.fastutil.objects.ObjectArrayList +import net.minecraft.util.RandomSource import ru.dbotthepony.mc.otm.core.random import java.util.random.RandomGenerator import kotlin.math.min @@ -88,7 +89,7 @@ private class MutableCluster>(var center: V) { } private fun > Iterable.clusterize( - random: RandomGenerator, + random: RandomSource, initialClusters: Int = 1, zeroBound: Boolean = false, identity: V, @@ -202,7 +203,7 @@ private fun > Iterable.clusterize( // TODO: could use some tweaking private val DECIMAL_ERROR_TOLERANCE = Decimal("0.02") -fun Iterable.clusterize(random: RandomGenerator, clusters: Int? = null, zeroBound: Boolean = false): List> { +fun Iterable.clusterize(random: RandomSource, clusters: Int? = null, zeroBound: Boolean = false): List> { return clusterize(random, clusters ?: 1, zeroBound, Decimal.ZERO, Decimal::plus, Decimal::minus, Decimal::div, Decimal::absoluteValue) { min, max, error -> if (clusters != null) false