Merge branch '1.21' into new-container-api
This commit is contained in:
commit
29c51617b9
@ -52,7 +52,7 @@ open class DecimalHistoryChartPanel<out S : MatteryScreen<*>>(
|
|||||||
|
|
||||||
map[1f] = formatText(maximum)
|
map[1f] = formatText(maximum)
|
||||||
|
|
||||||
for (cluster in chart.asIterable().clusterize(randomGenerator)) {
|
for (cluster in chart.asIterable().clusterize(random)) {
|
||||||
val perc = (cluster.center / maximum).toFloat()
|
val perc = (cluster.center / maximum).toFloat()
|
||||||
|
|
||||||
if (map.keys.none { (it - perc).absoluteValue < 0.08f }) {
|
if (map.keys.none { (it - perc).absoluteValue < 0.08f }) {
|
||||||
|
@ -11,9 +11,7 @@ import net.minecraft.client.gui.components.events.GuiEventListener
|
|||||||
import net.minecraft.client.gui.navigation.FocusNavigationEvent
|
import net.minecraft.client.gui.navigation.FocusNavigationEvent
|
||||||
import net.minecraft.client.gui.navigation.ScreenRectangle
|
import net.minecraft.client.gui.navigation.ScreenRectangle
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
import net.minecraft.client.renderer.Rect2i
|
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.util.RandomSource
|
|
||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.mc.otm.SystemTime
|
import ru.dbotthepony.mc.otm.SystemTime
|
||||||
import ru.dbotthepony.mc.otm.client.CursorType
|
import ru.dbotthepony.mc.otm.client.CursorType
|
||||||
@ -26,83 +24,16 @@ import ru.dbotthepony.mc.otm.client.render.popScissorRect
|
|||||||
import ru.dbotthepony.mc.otm.client.render.pushScissorRect
|
import ru.dbotthepony.mc.otm.client.render.pushScissorRect
|
||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.input.QueryUserPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.input.QueryUserPanel
|
||||||
import ru.dbotthepony.mc.otm.core.RandomSource2Generator
|
|
||||||
import ru.dbotthepony.mc.otm.core.collect.concatIterators
|
import ru.dbotthepony.mc.otm.core.collect.concatIterators
|
||||||
import ru.dbotthepony.mc.otm.core.collect.flatMap
|
import ru.dbotthepony.mc.otm.core.collect.flatMap
|
||||||
|
import ru.dbotthepony.mc.otm.core.util.GJRAND64RandomSource
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.CopyOnWriteArrayList
|
import java.util.concurrent.CopyOnWriteArrayList
|
||||||
import java.util.function.Predicate
|
import java.util.function.Predicate
|
||||||
import java.util.random.RandomGenerator
|
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
data class ScreenPos(val x: Float, val y: Float)
|
|
||||||
|
|
||||||
data class DockProperty(val left: Float = 0f, val top: Float = 0f, val right: Float = 0f, val bottom: Float = 0f) {
|
|
||||||
val isEmpty get() = left == 0f && right == 0f && top == 0f && bottom == 0f
|
|
||||||
val horizontal get() = left + right
|
|
||||||
val vertical get() = top + bottom
|
|
||||||
|
|
||||||
operator fun plus(other: DockProperty): DockProperty {
|
|
||||||
return DockProperty(
|
|
||||||
left + other.left,
|
|
||||||
top + other.top,
|
|
||||||
right + other.right,
|
|
||||||
bottom + other.bottom
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
operator fun minus(other: DockProperty): DockProperty {
|
|
||||||
return DockProperty(
|
|
||||||
left - other.left,
|
|
||||||
top - other.top,
|
|
||||||
right - other.right,
|
|
||||||
bottom - other.bottom
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
operator fun plus(other: Float): DockProperty {
|
|
||||||
return DockProperty(
|
|
||||||
left + other,
|
|
||||||
top + other,
|
|
||||||
right + other,
|
|
||||||
bottom + other
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
operator fun minus(other: Float): DockProperty {
|
|
||||||
return DockProperty(
|
|
||||||
left - other,
|
|
||||||
top - other,
|
|
||||||
right - other,
|
|
||||||
bottom - other
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val EMPTY = DockProperty()
|
|
||||||
|
|
||||||
fun all(value: Float): DockProperty {
|
|
||||||
return DockProperty(value, value, value, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class Dock {
|
|
||||||
NONE, LEFT, RIGHT, TOP, BOTTOM, FILL
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class DockResizeMode(val changeWidth: Boolean, val changeHeight: Boolean) {
|
|
||||||
ALL(true, true), NONE(false, false), WIDTH(true, false), HEIGHT(false, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
data class Rect2f(val x: Float, val y: Float, val width: Float, val height: Float) {
|
|
||||||
fun toIntRect(): Rect2i {
|
|
||||||
return Rect2i(x.roundToInt(), y.roundToInt(), width.roundToInt(), height.roundToInt())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
open class EditablePanel<out S : Screen>(
|
open class EditablePanel<out S : Screen>(
|
||||||
val screen: S,
|
val screen: S,
|
||||||
parent: EditablePanel<*>?,
|
parent: EditablePanel<*>?,
|
||||||
@ -179,18 +110,14 @@ open class EditablePanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val random: RandomSource by lazy {
|
val random: GJRAND64RandomSource by lazy {
|
||||||
if (screen is MatteryScreen<*>) {
|
if (screen is MatteryScreen<*>) {
|
||||||
screen.menu.random
|
screen.menu.random
|
||||||
} else {
|
} else {
|
||||||
RandomSource.create()
|
GJRAND64RandomSource()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val randomGenerator: RandomGenerator by lazy {
|
|
||||||
RandomSource2Generator(random)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bigger values means lesser priority while docking, rendering and processing inputs.
|
* Bigger values means lesser priority while docking, rendering and processing inputs.
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,115 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.client.screen.panels
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.Rect2i
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
data class ScreenPos(val x: Float, val y: Float)
|
||||||
|
|
||||||
|
data class DockProperty(val left: Float = 0f, val top: Float = 0f, val right: Float = 0f, val bottom: Float = 0f) {
|
||||||
|
val isEmpty get() = left == 0f && right == 0f && top == 0f && bottom == 0f
|
||||||
|
val horizontal get() = left + right
|
||||||
|
val vertical get() = top + bottom
|
||||||
|
|
||||||
|
operator fun plus(other: DockProperty): DockProperty {
|
||||||
|
return DockProperty(
|
||||||
|
left + other.left,
|
||||||
|
top + other.top,
|
||||||
|
right + other.right,
|
||||||
|
bottom + other.bottom
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun minus(other: DockProperty): DockProperty {
|
||||||
|
return DockProperty(
|
||||||
|
left - other.left,
|
||||||
|
top - other.top,
|
||||||
|
right - other.right,
|
||||||
|
bottom - other.bottom
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun plus(other: Float): DockProperty {
|
||||||
|
return DockProperty(
|
||||||
|
left + other,
|
||||||
|
top + other,
|
||||||
|
right + other,
|
||||||
|
bottom + other
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun minus(other: Float): DockProperty {
|
||||||
|
return DockProperty(
|
||||||
|
left - other,
|
||||||
|
top - other,
|
||||||
|
right - other,
|
||||||
|
bottom - other
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val EMPTY = DockProperty()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun all(value: Float): DockProperty {
|
||||||
|
return DockProperty(value, value, value, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@JvmOverloads
|
||||||
|
fun topLeft(top: Float, left: Float = top): DockProperty {
|
||||||
|
return DockProperty(left = left, top = top)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun left(value: Float): DockProperty {
|
||||||
|
return DockProperty(left = value)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@JvmOverloads
|
||||||
|
fun topRight(top: Float, right: Float = top): DockProperty {
|
||||||
|
return DockProperty(right = right, top = top)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun right(value: Float): DockProperty {
|
||||||
|
return DockProperty(right = value)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun top(value: Float): DockProperty {
|
||||||
|
return DockProperty(top = value)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@JvmOverloads
|
||||||
|
fun bottomLeft(bottom: Float, left: Float = bottom): DockProperty {
|
||||||
|
return DockProperty(left = left, bottom = bottom)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@JvmOverloads
|
||||||
|
fun bottomRight(bottom: Float, right: Float = bottom): DockProperty {
|
||||||
|
return DockProperty(right = right, bottom = bottom)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun bottom(value: Float): DockProperty {
|
||||||
|
return DockProperty(bottom = value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Dock {
|
||||||
|
NONE, LEFT, RIGHT, TOP, BOTTOM, FILL
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class DockResizeMode(val changeWidth: Boolean, val changeHeight: Boolean) {
|
||||||
|
ALL(true, true), NONE(false, false), WIDTH(true, false), HEIGHT(false, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Rect2f(val x: Float, val y: Float, val width: Float, val height: Float) {
|
||||||
|
fun toIntRect(): Rect2i {
|
||||||
|
return Rect2i(x.roundToInt(), y.roundToInt(), width.roundToInt(), height.roundToInt())
|
||||||
|
}
|
||||||
|
}
|
@ -68,12 +68,12 @@ open class GridPanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun columns(last: Int): IntIterator {
|
override fun columns(last: Int): IntIterator {
|
||||||
return (last - 1 downTo 1).iterator()
|
return (last - 1 downTo 0).iterator()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
BOTTOM_LEFT {
|
BOTTOM_LEFT {
|
||||||
override fun rows(last: Int): IntIterator {
|
override fun rows(last: Int): IntIterator {
|
||||||
return (last - 1 downTo 1).iterator()
|
return (last - 1 downTo 0).iterator()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun columns(last: Int): IntIterator {
|
override fun columns(last: Int): IntIterator {
|
||||||
@ -83,11 +83,11 @@ open class GridPanel<out S : Screen>(
|
|||||||
|
|
||||||
BOTTOM_RIGHT {
|
BOTTOM_RIGHT {
|
||||||
override fun rows(last: Int): IntIterator {
|
override fun rows(last: Int): IntIterator {
|
||||||
return (last - 1 downTo 1).iterator()
|
return (last - 1 downTo 0).iterator()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun columns(last: Int): IntIterator {
|
override fun columns(last: Int): IntIterator {
|
||||||
return (last - 1 downTo 1).iterator()
|
return (last - 1 downTo 0).iterator()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
|
|||||||
import net.minecraft.ChatFormatting
|
import net.minecraft.ChatFormatting
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.util.RandomSource
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.neoforged.neoforge.network.PacketDistributor
|
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.kommons.math.RGBAColor
|
||||||
import ru.dbotthepony.mc.otm.player.matteryPlayer
|
import ru.dbotthepony.mc.otm.player.matteryPlayer
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.BooleanButtonPanel
|
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.menu.tech.AndroidStationMenu
|
||||||
import ru.dbotthepony.mc.otm.network.AndroidResearchRequestPacket
|
import ru.dbotthepony.mc.otm.network.AndroidResearchRequestPacket
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -540,14 +542,14 @@ class AndroidStationScreen(p_97741_: AndroidStationMenu, p_97742_: Inventory, p_
|
|||||||
|
|
||||||
if (isPreview && !layoutInvalidated) {
|
if (isPreview && !layoutInvalidated) {
|
||||||
if (firstTick) {
|
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) {
|
if (!status) {
|
||||||
scroller = PreviewScrollers.entries.let { it[random.nextInt(it.size)] }
|
scroller = PreviewScrollers.entries.let { it[random.nextInt(it.size)] }
|
||||||
scroller.init.invoke(this, randomGenerator)
|
scroller.init.invoke(this, random)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -680,3 +680,21 @@ fun <K : Any, V> SimpleCache(size: Long, freshness: Duration): Cache<K, V> {
|
|||||||
.expireAfterWrite(freshness)
|
.expireAfterWrite(freshness)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun RandomSource.nextFloat(min: Float, max: Float): Float {
|
||||||
|
if (this is RandomGenerator)
|
||||||
|
return nextFloat(min, max)
|
||||||
|
|
||||||
|
require(max >= min) { "Min is bigger than max: $min vs $max" }
|
||||||
|
if (min == max) return min
|
||||||
|
return min + nextFloat() * (max - min)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun RandomSource.nextDouble(min: Double, max: Double): Double {
|
||||||
|
if (this is RandomGenerator)
|
||||||
|
return nextDouble(min, max)
|
||||||
|
|
||||||
|
require(max >= min) { "Min is bigger than max: $min vs $max" }
|
||||||
|
if (min == max) return min
|
||||||
|
return min + nextDouble() * (max - min)
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ru.dbotthepony.mc.otm.core.math
|
package ru.dbotthepony.mc.otm.core.math
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList
|
||||||
|
import net.minecraft.util.RandomSource
|
||||||
import ru.dbotthepony.mc.otm.core.random
|
import ru.dbotthepony.mc.otm.core.random
|
||||||
import java.util.random.RandomGenerator
|
import java.util.random.RandomGenerator
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
@ -88,7 +89,7 @@ private class MutableCluster<V : Comparable<V>>(var center: V) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun <V : Comparable<V>> Iterable<V>.clusterize(
|
private fun <V : Comparable<V>> Iterable<V>.clusterize(
|
||||||
random: RandomGenerator,
|
random: RandomSource,
|
||||||
initialClusters: Int = 1,
|
initialClusters: Int = 1,
|
||||||
zeroBound: Boolean = false,
|
zeroBound: Boolean = false,
|
||||||
identity: V,
|
identity: V,
|
||||||
@ -202,7 +203,7 @@ private fun <V : Comparable<V>> Iterable<V>.clusterize(
|
|||||||
// TODO: could use some tweaking
|
// TODO: could use some tweaking
|
||||||
private val DECIMAL_ERROR_TOLERANCE = Decimal("0.02")
|
private val DECIMAL_ERROR_TOLERANCE = Decimal("0.02")
|
||||||
|
|
||||||
fun Iterable<Decimal>.clusterize(random: RandomGenerator, clusters: Int? = null, zeroBound: Boolean = false): List<Cluster<Decimal>> {
|
fun Iterable<Decimal>.clusterize(random: RandomSource, clusters: Int? = null, zeroBound: Boolean = false): List<Cluster<Decimal>> {
|
||||||
return clusterize(random, clusters ?: 1, zeroBound, Decimal.ZERO, Decimal::plus, Decimal::minus, Decimal::div, Decimal::absoluteValue) { min, max, error ->
|
return clusterize(random, clusters ?: 1, zeroBound, Decimal.ZERO, Decimal::plus, Decimal::minus, Decimal::div, Decimal::absoluteValue) { min, max, error ->
|
||||||
if (clusters != null)
|
if (clusters != null)
|
||||||
false
|
false
|
||||||
|
@ -43,6 +43,7 @@ import ru.dbotthepony.mc.otm.core.ResourceLocation
|
|||||||
import ru.dbotthepony.mc.otm.core.collect.ConditionalSet
|
import ru.dbotthepony.mc.otm.core.collect.ConditionalSet
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.entity.checkCanInteract
|
import ru.dbotthepony.mc.otm.entity.checkCanInteract
|
||||||
|
import ru.dbotthepony.mc.otm.core.util.GJRAND64RandomSource
|
||||||
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
|
||||||
import ru.dbotthepony.mc.otm.menu.widget.ProfiledLevelGaugeWidget
|
import ru.dbotthepony.mc.otm.menu.widget.ProfiledLevelGaugeWidget
|
||||||
import ru.dbotthepony.mc.otm.network.MatteryStreamCodec
|
import ru.dbotthepony.mc.otm.network.MatteryStreamCodec
|
||||||
@ -81,7 +82,7 @@ abstract class MatteryMenu(
|
|||||||
val mSynchronizer = SynchableGroup()
|
val mSynchronizer = SynchableGroup()
|
||||||
val synchronizerRemote = mSynchronizer.Remote()
|
val synchronizerRemote = mSynchronizer.Remote()
|
||||||
val player: Player get() = inventory.player
|
val player: Player get() = inventory.player
|
||||||
val random: RandomSource = RandomSource.create()
|
val random = GJRAND64RandomSource()
|
||||||
|
|
||||||
private val _playerInventorySlots = ArrayList<InventorySlot>()
|
private val _playerInventorySlots = ArrayList<InventorySlot>()
|
||||||
private val _playerHotbarSlots = ArrayList<InventorySlot>()
|
private val _playerHotbarSlots = ArrayList<InventorySlot>()
|
||||||
|
Loading…
Reference in New Issue
Block a user