Compare commits
No commits in common. "ab2cc33b7a330f1ec0164748e263e6f9d0822c31" and "10f250b822d12fb49c6fd5ec1a2b167a0310b474" have entirely different histories.
ab2cc33b7a
...
10f250b822
@ -14,8 +14,6 @@ import net.minecraft.world.inventory.tooltip.TooltipComponent
|
|||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
import ru.dbotthepony.kommons.math.RGBAColor
|
import ru.dbotthepony.kommons.math.RGBAColor
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.ScreenPos
|
|
||||||
import java.util.Arrays
|
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@ -47,73 +45,6 @@ class MGUIGraphics(val parent: GuiGraphics) {
|
|||||||
drawLine(pose.last().pose(), startX, startY, endX, endY, width, z, color)
|
drawLine(pose.last().pose(), startX, startY, endX, endY, width, z, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun drawLine(
|
|
||||||
points: Iterable<LinePoint>,
|
|
||||||
width: Float,
|
|
||||||
color: RGBAColor = RGBAColor.WHITE
|
|
||||||
) {
|
|
||||||
drawLine(pose.last().pose(), points, width, color)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun drawLine(
|
|
||||||
points: Array<out LinePoint>,
|
|
||||||
width: Float,
|
|
||||||
color: RGBAColor = RGBAColor.WHITE
|
|
||||||
) {
|
|
||||||
drawLine(pose.last().pose(), points, width, color)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun drawLine(
|
|
||||||
width: Float,
|
|
||||||
color: RGBAColor,
|
|
||||||
vararg points: LinePoint,
|
|
||||||
) {
|
|
||||||
drawLine(pose.last().pose(), points, width, color)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun drawLine(
|
|
||||||
width: Float,
|
|
||||||
color: RGBAColor,
|
|
||||||
points: Iterable<LinePoint>,
|
|
||||||
) {
|
|
||||||
drawLine(pose.last().pose(), points, width, color)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun drawLine(
|
|
||||||
width: Float,
|
|
||||||
color: RGBAColor,
|
|
||||||
z: Float,
|
|
||||||
points: List<ScreenPos>,
|
|
||||||
) {
|
|
||||||
require(points.size >= 2) { "Degenerate point list: only ${points.size} defined" }
|
|
||||||
|
|
||||||
val result = ArrayList<LinePoint>(points.size)
|
|
||||||
|
|
||||||
for (i in 1 until points.size) {
|
|
||||||
val (x0, y0) = points[i - 1]
|
|
||||||
val (x1, y1) = points[i]
|
|
||||||
|
|
||||||
result.add(
|
|
||||||
LinePoint(
|
|
||||||
x0, y0,
|
|
||||||
x1, y1,
|
|
||||||
z
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
drawLine(pose.last().pose(), result, width, color)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun drawLine(
|
|
||||||
width: Float,
|
|
||||||
color: RGBAColor,
|
|
||||||
z: Float,
|
|
||||||
vararg points: ScreenPos,
|
|
||||||
) {
|
|
||||||
drawLine(width, color, z, Arrays.asList(*points))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun renderRect(
|
fun renderRect(
|
||||||
x: Float,
|
x: Float,
|
||||||
y: Float,
|
y: Float,
|
||||||
|
@ -294,65 +294,6 @@ fun renderColoredSphere(pose: PoseStack, radius: Float, color: RGBAColor = RGBAC
|
|||||||
BufferUploader.drawWithShader(builder.buildOrThrow())
|
BufferUploader.drawWithShader(builder.buildOrThrow())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun uploadLineSegment(
|
|
||||||
builder: BufferBuilder,
|
|
||||||
matrix: Matrix4f,
|
|
||||||
startX: Float,
|
|
||||||
startY: Float,
|
|
||||||
endX: Float,
|
|
||||||
endY: Float,
|
|
||||||
width: Float,
|
|
||||||
z: Float,
|
|
||||||
color: RGBAColor = RGBAColor.WHITE
|
|
||||||
) {
|
|
||||||
val length = ((startX - endX).pow(2f) + (startY - endY).pow(2f)).pow(0.5f)
|
|
||||||
var angle = acos((endX - startX) / length)
|
|
||||||
|
|
||||||
if (startY > endY)
|
|
||||||
angle *= -1f
|
|
||||||
|
|
||||||
val cos = cos(angle)
|
|
||||||
val sin = sin(angle)
|
|
||||||
|
|
||||||
val y0 = -width
|
|
||||||
|
|
||||||
val y1 = width
|
|
||||||
|
|
||||||
val x2 = length
|
|
||||||
val y2 = width
|
|
||||||
|
|
||||||
val x3 = length
|
|
||||||
val y3 = -width
|
|
||||||
|
|
||||||
builder.vertex(matrix,
|
|
||||||
startX - y0 * sin,
|
|
||||||
startY + y0 * cos,
|
|
||||||
z).color(color)
|
|
||||||
|
|
||||||
builder.vertex(matrix,
|
|
||||||
startX - y1 * sin,
|
|
||||||
startY + y1 * cos,
|
|
||||||
z).color(color)
|
|
||||||
|
|
||||||
builder.vertex(matrix,
|
|
||||||
startX + x2 * cos - y2 * sin,
|
|
||||||
startY + x2 * sin + y2 * cos,
|
|
||||||
z).color(color)
|
|
||||||
|
|
||||||
builder.vertex(matrix,
|
|
||||||
startX + x3 * cos - y3 * sin,
|
|
||||||
startY + x3 * sin + y3 * cos,
|
|
||||||
z).color(color)
|
|
||||||
}
|
|
||||||
|
|
||||||
data class LinePoint(
|
|
||||||
val startX: Float,
|
|
||||||
val startY: Float,
|
|
||||||
val endX: Float,
|
|
||||||
val endY: Float,
|
|
||||||
val z: Float = 0f,
|
|
||||||
)
|
|
||||||
|
|
||||||
fun drawLine(
|
fun drawLine(
|
||||||
matrix: Matrix4f,
|
matrix: Matrix4f,
|
||||||
startX: Float,
|
startX: Float,
|
||||||
@ -371,46 +312,46 @@ fun drawLine(
|
|||||||
RenderSystem.depthFunc(GL_ALWAYS)
|
RenderSystem.depthFunc(GL_ALWAYS)
|
||||||
|
|
||||||
val builder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR)
|
val builder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR)
|
||||||
uploadLineSegment(builder, matrix, startX, startY, endX, endY, width, z, color)
|
|
||||||
BufferUploader.drawWithShader(builder.buildOrThrow())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun drawLine(
|
val length = ((startX - endX).pow(2f) + (startY - endY).pow(2f)).pow(0.5f)
|
||||||
matrix: Matrix4f,
|
val angle = acos((endX - startX) / length)
|
||||||
points: Iterable<LinePoint>,
|
|
||||||
width: Float,
|
|
||||||
color: RGBAColor = RGBAColor.WHITE
|
|
||||||
) {
|
|
||||||
val itr = points.iterator()
|
|
||||||
|
|
||||||
if (!itr.hasNext()) {
|
val cos = cos(angle)
|
||||||
throw IllegalArgumentException("No line points were provided")
|
val sin = sin(angle)
|
||||||
}
|
|
||||||
|
|
||||||
RenderSystem.setShader(GameRenderer::getPositionColorShader)
|
val y0 = -width
|
||||||
RenderSystem.enableBlend()
|
|
||||||
RenderSystem.defaultBlendFunc()
|
|
||||||
|
|
||||||
if (!is3DContext)
|
val y1 = width
|
||||||
RenderSystem.depthFunc(GL_ALWAYS)
|
|
||||||
|
|
||||||
val builder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR)
|
val x2 = length
|
||||||
|
val y2 = width
|
||||||
|
|
||||||
for ((startX, startY, endX, endY, z) in itr)
|
val x3 = length
|
||||||
uploadLineSegment(builder, matrix, startX, startY, endX, endY, width, z, color)
|
val y3 = -width
|
||||||
|
|
||||||
|
builder.vertex(matrix,
|
||||||
|
startX - y0 * sin,
|
||||||
|
startY + y0 * cos,
|
||||||
|
z).color(color)
|
||||||
|
|
||||||
|
builder.vertex(matrix,
|
||||||
|
startX - y1 * sin,
|
||||||
|
startY + y1 * cos,
|
||||||
|
z).color(color)
|
||||||
|
|
||||||
|
builder.vertex(matrix,
|
||||||
|
startX + x2 * cos - y2 * sin,
|
||||||
|
startY + x2 * sin + y2 * cos,
|
||||||
|
z).color(color)
|
||||||
|
|
||||||
|
builder.vertex(matrix,
|
||||||
|
startX + x3 * cos - y3 * sin,
|
||||||
|
startY + x3 * sin + y3 * cos,
|
||||||
|
z).color(color)
|
||||||
|
|
||||||
BufferUploader.drawWithShader(builder.buildOrThrow())
|
BufferUploader.drawWithShader(builder.buildOrThrow())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun drawLine(
|
|
||||||
matrix: Matrix4f,
|
|
||||||
points: Array<out LinePoint>,
|
|
||||||
width: Float,
|
|
||||||
color: RGBAColor = RGBAColor.WHITE
|
|
||||||
) {
|
|
||||||
return drawLine(matrix, points.asIterable(), width, color)
|
|
||||||
}
|
|
||||||
|
|
||||||
data class ScissorRect(val xStart: Int, val yStart: Int, val xEnd: Int, val yEnd: Int, val lock: Boolean = false) {
|
data class ScissorRect(val xStart: Int, val yStart: Int, val xEnd: Int, val yEnd: Int, val lock: Boolean = false) {
|
||||||
val width: Int
|
val width: Int
|
||||||
get() = (xEnd - xStart).coerceAtLeast(0)
|
get() = (xEnd - xStart).coerceAtLeast(0)
|
||||||
|
@ -30,7 +30,6 @@ object Widgets18 {
|
|||||||
val RESTOCK_FROM_STORAGE = storageGrid.next()
|
val RESTOCK_FROM_STORAGE = storageGrid.next()
|
||||||
val RESTOCK_WITH_MOVE_TO_STORAGE = storageGrid.next()
|
val RESTOCK_WITH_MOVE_TO_STORAGE = storageGrid.next()
|
||||||
val RESTOCK_WITH_MOVE_FROM_STORAGE = storageGrid.next()
|
val RESTOCK_WITH_MOVE_FROM_STORAGE = storageGrid.next()
|
||||||
val SMART_STORAGE_EXCHANGE = storageGrid.next()
|
|
||||||
|
|
||||||
private val miscGrid = WidgetLocation.WIDGET_18.grid(4, 4)
|
private val miscGrid = WidgetLocation.WIDGET_18.grid(4, 4)
|
||||||
|
|
||||||
|
@ -20,13 +20,12 @@ import ru.dbotthepony.mc.otm.core.math.asAngle
|
|||||||
import ru.dbotthepony.mc.otm.core.math.clusterize
|
import ru.dbotthepony.mc.otm.core.math.clusterize
|
||||||
import ru.dbotthepony.mc.otm.core.util.formatPower
|
import ru.dbotthepony.mc.otm.core.util.formatPower
|
||||||
import ru.dbotthepony.mc.otm.core.math.times
|
import ru.dbotthepony.mc.otm.core.math.times
|
||||||
import ru.dbotthepony.mc.otm.core.util.GJRAND64RandomSource
|
|
||||||
import java.util.Random
|
import java.util.Random
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
class EnergyCounterRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<EnergyCounterBlockEntity> {
|
class EnergyCounterRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<EnergyCounterBlockEntity> {
|
||||||
private val random = GJRAND64RandomSource()
|
private val random = Random()
|
||||||
|
|
||||||
override fun render(
|
override fun render(
|
||||||
tile: EnergyCounterBlockEntity,
|
tile: EnergyCounterBlockEntity,
|
||||||
|
@ -17,11 +17,9 @@ import net.neoforged.neoforge.common.NeoForge
|
|||||||
import org.lwjgl.opengl.GL11
|
import org.lwjgl.opengl.GL11
|
||||||
import ru.dbotthepony.kommons.util.getValue
|
import ru.dbotthepony.kommons.util.getValue
|
||||||
import ru.dbotthepony.kommons.util.setValue
|
import ru.dbotthepony.kommons.util.setValue
|
||||||
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.render.MGUIGraphics
|
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||||
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
||||||
import ru.dbotthepony.mc.otm.client.render.LinePoint
|
|
||||||
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
||||||
import ru.dbotthepony.mc.otm.client.render.Widgets18
|
import ru.dbotthepony.mc.otm.client.render.Widgets18
|
||||||
import ru.dbotthepony.mc.otm.client.render.translation
|
import ru.dbotthepony.mc.otm.client.render.translation
|
||||||
@ -57,7 +55,6 @@ import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
|||||||
import ru.dbotthepony.mc.otm.menu.widget.ProfiledLevelGaugeWidget
|
import ru.dbotthepony.mc.otm.menu.widget.ProfiledLevelGaugeWidget
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.CopyOnWriteArrayList
|
import java.util.concurrent.CopyOnWriteArrayList
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
import kotlin.collections.List
|
import kotlin.collections.List
|
||||||
import kotlin.collections.MutableSet
|
import kotlin.collections.MutableSet
|
||||||
import kotlin.collections.isNotEmpty
|
import kotlin.collections.isNotEmpty
|
||||||
@ -693,13 +690,7 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
|||||||
for (panel in panelsReversed) {
|
for (panel in panelsReversed) {
|
||||||
RenderSystem.depthFunc(GL11.GL_ALWAYS)
|
RenderSystem.depthFunc(GL11.GL_ALWAYS)
|
||||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
|
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
|
||||||
val segments = ArrayList<LinePoint>()
|
panel.render(wrap, mouseXf, mouseYf, partialTick)
|
||||||
|
|
||||||
panel.render(wrap, mouseXf, mouseYf, partialTick, segments)
|
|
||||||
|
|
||||||
if (segments.isNotEmpty()) {
|
|
||||||
wrap.drawLine(0.5f, RGBAColor.GOLD, segments)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!panelsReversed.any { it.updateCursor0() })
|
if (!panelsReversed.any { it.updateCursor0() })
|
||||||
|
@ -52,7 +52,7 @@ open class DecimalHistoryChartPanel<out S : MatteryScreen<*>>(
|
|||||||
|
|
||||||
map[1f] = formatText(maximum)
|
map[1f] = formatText(maximum)
|
||||||
|
|
||||||
for (cluster in chart.asIterable().clusterize(random)) {
|
for (cluster in chart.asIterable().clusterize(randomGenerator)) {
|
||||||
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,31 +11,94 @@ 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.kommons.math.RGBAColor
|
|
||||||
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
|
||||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
import ru.dbotthepony.mc.otm.client.moveMousePosScaled
|
||||||
import ru.dbotthepony.mc.otm.client.render.LinePoint
|
|
||||||
import ru.dbotthepony.mc.otm.client.render.RenderGravity
|
import ru.dbotthepony.mc.otm.client.render.RenderGravity
|
||||||
import ru.dbotthepony.mc.otm.client.render.currentScissorRect
|
import ru.dbotthepony.mc.otm.client.render.currentScissorRect
|
||||||
import ru.dbotthepony.mc.otm.client.render.popScissorRect
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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<*>?,
|
||||||
@ -112,14 +175,18 @@ open class EditablePanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val random: GJRAND64RandomSource by lazy {
|
val random: RandomSource by lazy {
|
||||||
if (screen is MatteryScreen<*>) {
|
if (screen is MatteryScreen<*>) {
|
||||||
screen.menu.random
|
screen.menu.random
|
||||||
} else {
|
} else {
|
||||||
GJRAND64RandomSource()
|
RandomSource.create()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
||||||
*/
|
*/
|
||||||
@ -283,13 +350,11 @@ open class EditablePanel<out S : Screen>(
|
|||||||
|
|
||||||
if (visibleChildrenParent?.contains(this) == false) {
|
if (visibleChildrenParent?.contains(this) == false) {
|
||||||
visibleChildrenParent.add(this)
|
visibleChildrenParent.add(this)
|
||||||
parent?.invalidateChildrenSorting()
|
|
||||||
parent?.layoutInvalidated = true
|
parent?.layoutInvalidated = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (visibleChildrenParent?.contains(this) == true) {
|
if (visibleChildrenParent?.contains(this) == true) {
|
||||||
visibleChildrenParent.remove(this)
|
visibleChildrenParent.remove(this)
|
||||||
parent?.invalidateChildrenSorting()
|
|
||||||
parent?.layoutInvalidated = true
|
parent?.layoutInvalidated = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -778,12 +843,6 @@ open class EditablePanel<out S : Screen>(
|
|||||||
childrenSortingInvalidated = true
|
childrenSortingInvalidated = true
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun onChildrenAdded(child: EditablePanel<*>) {}
|
|
||||||
protected open fun onChildrenRemoved(child: EditablePanel<*>) {}
|
|
||||||
|
|
||||||
protected open fun onParented(parent: EditablePanel<*>) {}
|
|
||||||
protected open fun onUnParented(parent: EditablePanel<*>) {}
|
|
||||||
|
|
||||||
private fun onParent(child: EditablePanel<*>) {
|
private fun onParent(child: EditablePanel<*>) {
|
||||||
if (childrenInternal.contains(child)) throw IllegalStateException("Already containing $child")
|
if (childrenInternal.contains(child)) throw IllegalStateException("Already containing $child")
|
||||||
childrenInternal.add(child)
|
childrenInternal.add(child)
|
||||||
@ -801,15 +860,11 @@ open class EditablePanel<out S : Screen>(
|
|||||||
else
|
else
|
||||||
updateVisibility = true
|
updateVisibility = true
|
||||||
}
|
}
|
||||||
|
|
||||||
onChildrenAdded(child)
|
|
||||||
child.onParented(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onUnParent(child: EditablePanel<*>) {
|
private fun onUnParent(child: EditablePanel<*>) {
|
||||||
val indexOf = childrenInternal.indexOf(child)
|
val indexOf = childrenInternal.indexOf(child)
|
||||||
if (indexOf == -1) throw IllegalStateException("Already not containing $child")
|
if (indexOf == -1) throw IllegalStateException("Already not containing $child")
|
||||||
child.onUnParented(this)
|
|
||||||
childrenInternal.removeAt(indexOf)
|
childrenInternal.removeAt(indexOf)
|
||||||
invalidateChildrenSorting()
|
invalidateChildrenSorting()
|
||||||
|
|
||||||
@ -821,8 +876,6 @@ open class EditablePanel<out S : Screen>(
|
|||||||
if (child.isVisible() != isVisible()) {
|
if (child.isVisible() != isVisible()) {
|
||||||
updateVisible()
|
updateVisible()
|
||||||
}
|
}
|
||||||
|
|
||||||
onChildrenRemoved(child)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sortChildren() {
|
private fun sortChildren() {
|
||||||
@ -891,11 +944,12 @@ open class EditablePanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun render(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float, debugSegments: MutableList<LinePoint>) {
|
fun render(graphics: MGUIGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
once = true
|
once = true
|
||||||
|
|
||||||
if (!isVisible())
|
if (!isVisible()) {
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val poseStack = graphics.pose
|
val poseStack = graphics.pose
|
||||||
|
|
||||||
@ -943,19 +997,12 @@ open class EditablePanel<out S : Screen>(
|
|||||||
child.absoluteX = absoluteX + child.x + xOffset
|
child.absoluteX = absoluteX + child.x + xOffset
|
||||||
child.absoluteY = absoluteY + child.y + yOffset
|
child.absoluteY = absoluteY + child.y + yOffset
|
||||||
|
|
||||||
child.render(graphics, mouseX, mouseY, partialTick, debugSegments)
|
child.render(graphics, mouseX, mouseY, partialTick)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scissor) {
|
if (scissor) {
|
||||||
popScissorRect()
|
popScissorRect()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minecraft.entityRenderDispatcher.shouldRenderHitBoxes()) {
|
|
||||||
debugSegments.add(LinePoint(absoluteX, absoluteY, absoluteX + width, absoluteY))
|
|
||||||
debugSegments.add(LinePoint(absoluteX + width, absoluteY, absoluteX + width, absoluteY + height))
|
|
||||||
debugSegments.add(LinePoint(absoluteX + width, absoluteY + height, absoluteX, absoluteY + height))
|
|
||||||
debugSegments.add(LinePoint(absoluteX, absoluteY + height, absoluteX, absoluteY))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateCursor0(): Boolean {
|
fun updateCursor0(): Boolean {
|
||||||
@ -1461,7 +1508,6 @@ open class EditablePanel<out S : Screen>(
|
|||||||
|
|
||||||
if (old != new) {
|
if (old != new) {
|
||||||
child.visibilityChanges(new, old)
|
child.visibilityChanges(new, old)
|
||||||
child.invalidateChildrenSorting()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
child.updateVisible()
|
child.updateVisible()
|
||||||
|
@ -4,8 +4,6 @@ import net.minecraft.client.gui.GuiGraphics
|
|||||||
import net.minecraft.client.gui.components.Renderable
|
import net.minecraft.client.gui.components.Renderable
|
||||||
import net.minecraft.client.gui.components.events.GuiEventListener
|
import net.minecraft.client.gui.components.events.GuiEventListener
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
import ru.dbotthepony.kommons.math.RGBAColor
|
|
||||||
import ru.dbotthepony.mc.otm.client.render.LinePoint
|
|
||||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||||
|
|
||||||
// before 1.19.3 Renderable was Widget
|
// before 1.19.3 Renderable was Widget
|
||||||
@ -23,17 +21,11 @@ class Panel2Widget<out S: Screen, out P : EditablePanel<S>>(
|
|||||||
val yFloat = mouseY.toFloat()
|
val yFloat = mouseY.toFloat()
|
||||||
|
|
||||||
val wrap = MGUIGraphics(graphics)
|
val wrap = MGUIGraphics(graphics)
|
||||||
val segments = ArrayList<LinePoint>()
|
|
||||||
|
|
||||||
panel.tickHovered0(xFloat, yFloat, false)
|
panel.tickHovered0(xFloat, yFloat, false)
|
||||||
panel.tickHovered1()
|
panel.tickHovered1()
|
||||||
panel.tickHovered2()
|
panel.tickHovered2()
|
||||||
panel.render(wrap, xFloat, yFloat, partialTick, segments)
|
panel.render(wrap, xFloat, yFloat, partialTick)
|
||||||
|
|
||||||
if (segments.isNotEmpty()) {
|
|
||||||
wrap.drawLine(0.5f, RGBAColor.GOLD, segments)
|
|
||||||
}
|
|
||||||
|
|
||||||
panel.renderTooltips(wrap, xFloat, yFloat, partialTick)
|
panel.renderTooltips(wrap, xFloat, yFloat, partialTick)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,115 +0,0 @@
|
|||||||
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())
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,9 +7,6 @@ import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
|
||||||
import ru.dbotthepony.mc.otm.core.collect.filter
|
import ru.dbotthepony.mc.otm.core.collect.filter
|
||||||
import ru.dbotthepony.mc.otm.core.collect.maybe
|
import ru.dbotthepony.mc.otm.core.collect.maybe
|
||||||
import java.util.stream.IntStream
|
|
||||||
import java.util.stream.Stream
|
|
||||||
import kotlin.math.max
|
|
||||||
|
|
||||||
open class GridPanel<out S : Screen>(
|
open class GridPanel<out S : Screen>(
|
||||||
screen: S,
|
screen: S,
|
||||||
@ -23,150 +20,25 @@ open class GridPanel<out S : Screen>(
|
|||||||
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
||||||
var columns: Int = columns
|
var columns: Int = columns
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field != value) {
|
field = value
|
||||||
field = value
|
invalidateLayout()
|
||||||
invalidateLayout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var rows: Int = rows
|
var rows: Int = rows
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field != value) {
|
field = value
|
||||||
field = value
|
invalidateLayout()
|
||||||
invalidateLayout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var gravity: RenderGravity = RenderGravity.CENTER_CENTER
|
var gravity: RenderGravity = RenderGravity.CENTER_CENTER
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field != value) {
|
field = value
|
||||||
field = value
|
invalidateLayout()
|
||||||
invalidateLayout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var layout: Layout = Layout.TOP_LEFT
|
|
||||||
set(value) {
|
|
||||||
if (field != value) {
|
|
||||||
field = value
|
|
||||||
invalidateLayout()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var columnMajorOrder = false
|
|
||||||
set(value) {
|
|
||||||
if (field != value) {
|
|
||||||
field = value
|
|
||||||
invalidateLayout()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class Layout {
|
|
||||||
TOP_LEFT {
|
|
||||||
override fun get(
|
|
||||||
list: List<EditablePanel<*>>,
|
|
||||||
row: Int,
|
|
||||||
column: Int,
|
|
||||||
rows: Int,
|
|
||||||
columns: Int,
|
|
||||||
columnMajorOrder: Boolean
|
|
||||||
): EditablePanel<*>? {
|
|
||||||
if (columnMajorOrder) {
|
|
||||||
return list.getOrNull(row + column * rows)
|
|
||||||
} else {
|
|
||||||
return list.getOrNull(column + row * columns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
TOP_RIGHT {
|
|
||||||
override fun get(
|
|
||||||
list: List<EditablePanel<*>>,
|
|
||||||
row: Int,
|
|
||||||
column: Int,
|
|
||||||
rows: Int,
|
|
||||||
columns: Int,
|
|
||||||
columnMajorOrder: Boolean
|
|
||||||
): EditablePanel<*>? {
|
|
||||||
if (columnMajorOrder) {
|
|
||||||
return list.getOrNull(row + (columns - column - 1) * rows)
|
|
||||||
} else {
|
|
||||||
return list.getOrNull((columns - column - 1) + row * columns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
BOTTOM_LEFT {
|
|
||||||
override fun get(
|
|
||||||
list: List<EditablePanel<*>>,
|
|
||||||
row: Int,
|
|
||||||
column: Int,
|
|
||||||
rows: Int,
|
|
||||||
columns: Int,
|
|
||||||
columnMajorOrder: Boolean
|
|
||||||
): EditablePanel<*>? {
|
|
||||||
if (columnMajorOrder) {
|
|
||||||
return list.getOrNull((rows - row - 1) + column * rows)
|
|
||||||
} else {
|
|
||||||
return list.getOrNull(column + (rows - row - 1) * columns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
BOTTOM_RIGHT {
|
|
||||||
override fun get(
|
|
||||||
list: List<EditablePanel<*>>,
|
|
||||||
row: Int,
|
|
||||||
column: Int,
|
|
||||||
rows: Int,
|
|
||||||
columns: Int,
|
|
||||||
columnMajorOrder: Boolean
|
|
||||||
): EditablePanel<*>? {
|
|
||||||
if (columnMajorOrder) {
|
|
||||||
return list.getOrNull((rows - row - 1) + (columns - column - 1) * rows)
|
|
||||||
} else {
|
|
||||||
return list.getOrNull((columns - column - 1) + (rows - row - 1) * columns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
abstract fun get(list: List<EditablePanel<*>>, row: Int, column: Int, rows: Int, columns: Int, columnMajorOrder: Boolean): EditablePanel<*>?
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun sizeToContents() {
|
|
||||||
if (visibleChildren.isEmpty()) {
|
|
||||||
// nothing to size against
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
visibleChildren.forEach { it.sizeToContents() }
|
|
||||||
|
|
||||||
var width = 0f
|
|
||||||
var height = 0f
|
|
||||||
|
|
||||||
val children = visibleChildren.filter { it.dock == Dock.NONE }
|
|
||||||
|
|
||||||
for (row in 0 until rows) {
|
|
||||||
var maxHeight = 0f
|
|
||||||
var rowWidth = 0f
|
|
||||||
|
|
||||||
for (column in 0 until columns) {
|
|
||||||
val nextChild = layout.get(children, row, column, rows, columns, columnMajorOrder) ?: continue
|
|
||||||
rowWidth += nextChild.width + nextChild.dockMargin.horizontal
|
|
||||||
maxHeight = max(maxHeight, nextChild.height + nextChild.dockMargin.vertical)
|
|
||||||
}
|
|
||||||
|
|
||||||
height += maxHeight
|
|
||||||
width = max(width, rowWidth)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.width = width
|
|
||||||
this.height = height
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun performLayout() {
|
override fun performLayout() {
|
||||||
super.performLayout()
|
super.performLayout()
|
||||||
val children = visibleChildren.filter { it.dock == Dock.NONE }
|
var children = visibleChildren.iterator().filter { it.dock == Dock.NONE }
|
||||||
|
|
||||||
var totalWidth = 0f
|
var totalWidth = 0f
|
||||||
var totalHeight = 0f
|
var totalHeight = 0f
|
||||||
@ -176,7 +48,7 @@ open class GridPanel<out S : Screen>(
|
|||||||
var width = 0f
|
var width = 0f
|
||||||
|
|
||||||
for (column in 0 until columns) {
|
for (column in 0 until columns) {
|
||||||
val child = layout.get(children, row, column, rows, columns, columnMajorOrder) ?: continue
|
val child = children.maybe() ?: break
|
||||||
width += child.dockedWidth
|
width += child.dockedWidth
|
||||||
maxHeight = maxHeight.coerceAtLeast(child.dockedHeight)
|
maxHeight = maxHeight.coerceAtLeast(child.dockedHeight)
|
||||||
}
|
}
|
||||||
@ -187,6 +59,7 @@ open class GridPanel<out S : Screen>(
|
|||||||
|
|
||||||
val alignX = gravity.repositionX(width, totalWidth)
|
val alignX = gravity.repositionX(width, totalWidth)
|
||||||
val alignY = gravity.repositionY(height, totalHeight)
|
val alignY = gravity.repositionY(height, totalHeight)
|
||||||
|
children = visibleChildren.iterator().filter { it.dock == Dock.NONE }
|
||||||
|
|
||||||
totalWidth = 0f
|
totalWidth = 0f
|
||||||
totalHeight = 0f
|
totalHeight = 0f
|
||||||
@ -196,7 +69,7 @@ open class GridPanel<out S : Screen>(
|
|||||||
var width = 0f
|
var width = 0f
|
||||||
|
|
||||||
for (column in 0 until columns) {
|
for (column in 0 until columns) {
|
||||||
val child = layout.get(children, row, column, rows, columns, columnMajorOrder) ?: continue
|
val child = children.maybe() ?: break
|
||||||
child.x = alignX + width
|
child.x = alignX + width
|
||||||
child.y = alignY + totalHeight
|
child.y = alignY + totalHeight
|
||||||
width += child.dockedWidth
|
width += child.dockedWidth
|
||||||
|
@ -7,7 +7,6 @@ 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
|
||||||
@ -35,7 +34,6 @@ 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.*
|
||||||
@ -542,14 +540,14 @@ class AndroidStationScreen(p_97741_: AndroidStationMenu, p_97742_: Inventory, p_
|
|||||||
|
|
||||||
if (isPreview && !layoutInvalidated) {
|
if (isPreview && !layoutInvalidated) {
|
||||||
if (firstTick) {
|
if (firstTick) {
|
||||||
scroller.init.invoke(this, random)
|
scroller.init.invoke(this, randomGenerator)
|
||||||
}
|
}
|
||||||
|
|
||||||
val status = scroller.scroll.invoke(this, random)
|
val status = scroller.scroll.invoke(this, randomGenerator)
|
||||||
|
|
||||||
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, random)
|
scroller.init.invoke(this, randomGenerator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -662,21 +662,3 @@ fun RandomSource.nextNormalDoubles(stddev: Double, mean: Double): DoublePair {
|
|||||||
fun RandomSource.nextNormalDouble(stddev: Double, mean: Double): Double {
|
fun RandomSource.nextNormalDouble(stddev: Double, mean: Double): Double {
|
||||||
return nextGaussian() * stddev + mean
|
return nextGaussian() * stddev + mean
|
||||||
}
|
}
|
||||||
|
|
||||||
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,7 +1,6 @@
|
|||||||
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
|
||||||
@ -89,7 +88,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: RandomSource,
|
random: RandomGenerator,
|
||||||
initialClusters: Int = 1,
|
initialClusters: Int = 1,
|
||||||
zeroBound: Boolean = false,
|
zeroBound: Boolean = false,
|
||||||
identity: V,
|
identity: V,
|
||||||
@ -203,7 +202,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: RandomSource, clusters: Int? = null, zeroBound: Boolean = false): List<Cluster<Decimal>> {
|
fun Iterable<Decimal>.clusterize(random: RandomGenerator, 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
|
||||||
|
@ -9,7 +9,6 @@ import net.minecraft.network.chat.FormattedText
|
|||||||
import net.minecraft.network.chat.MutableComponent
|
import net.minecraft.network.chat.MutableComponent
|
||||||
import net.minecraft.world.inventory.tooltip.TooltipComponent
|
import net.minecraft.world.inventory.tooltip.TooltipComponent
|
||||||
import ru.dbotthepony.kommons.math.RGBAColor
|
import ru.dbotthepony.kommons.math.RGBAColor
|
||||||
import ru.dbotthepony.mc.otm.THREAD_LOCAL_RANDOM
|
|
||||||
import ru.dbotthepony.mc.otm.client.render.ChartLevelLabels
|
import ru.dbotthepony.mc.otm.client.render.ChartLevelLabels
|
||||||
import ru.dbotthepony.mc.otm.client.render.ChartTooltipElement
|
import ru.dbotthepony.mc.otm.client.render.ChartTooltipElement
|
||||||
import ru.dbotthepony.mc.otm.config.ClientConfig
|
import ru.dbotthepony.mc.otm.config.ClientConfig
|
||||||
@ -454,8 +453,10 @@ private fun formatHistoryChart(
|
|||||||
labelNames[0f] = (-maxTransferred).formatSiComponent(suffix, decimals, formatAsReadable = verbose, bias = bias)
|
labelNames[0f] = (-maxTransferred).formatSiComponent(suffix, decimals, formatAsReadable = verbose, bias = bias)
|
||||||
labelNames[1f] = maxReceived.formatSiComponent(suffix, decimals, formatAsReadable = verbose, bias = bias)
|
labelNames[1f] = maxReceived.formatSiComponent(suffix, decimals, formatAsReadable = verbose, bias = bias)
|
||||||
|
|
||||||
|
val rand = java.util.Random()
|
||||||
|
|
||||||
if (maxTransferred.isNotZero && transferredMult > 0.2f) {
|
if (maxTransferred.isNotZero && transferredMult > 0.2f) {
|
||||||
for (cluster in widget.transferred.clusterize(THREAD_LOCAL_RANDOM, zeroBound = true)) {
|
for (cluster in widget.transferred.clusterize(rand, zeroBound = true)) {
|
||||||
val perc = (cluster.center / maxTransferred).toFloat() * transferredMult
|
val perc = (cluster.center / maxTransferred).toFloat() * transferredMult
|
||||||
|
|
||||||
if (labelNames.keys.none { (it - perc).absoluteValue < 0.08f })
|
if (labelNames.keys.none { (it - perc).absoluteValue < 0.08f })
|
||||||
@ -464,7 +465,7 @@ private fun formatHistoryChart(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (maxReceived.isNotZero && receivedMult > 0.2f) {
|
if (maxReceived.isNotZero && receivedMult > 0.2f) {
|
||||||
for (cluster in widget.received.clusterize(THREAD_LOCAL_RANDOM, zeroBound = true)) {
|
for (cluster in widget.received.clusterize(rand, zeroBound = true)) {
|
||||||
val perc = zero + (cluster.center / maxReceived).toFloat() * receivedMult
|
val perc = zero + (cluster.center / maxReceived).toFloat() * receivedMult
|
||||||
|
|
||||||
if (labelNames.keys.none { (it - perc).absoluteValue < 0.08f })
|
if (labelNames.keys.none { (it - perc).absoluteValue < 0.08f })
|
||||||
@ -472,7 +473,7 @@ private fun formatHistoryChart(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val clusters = diff.asIterable().clusterize(THREAD_LOCAL_RANDOM, zeroBound = true)
|
val clusters = diff.asIterable().clusterize(rand, zeroBound = true)
|
||||||
|
|
||||||
for (cluster in clusters) {
|
for (cluster in clusters) {
|
||||||
val perc: Float
|
val perc: Float
|
||||||
|
@ -44,7 +44,6 @@ import ru.dbotthepony.mc.otm.container.sortWithIndices
|
|||||||
import ru.dbotthepony.mc.otm.core.ResourceLocation
|
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.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
|
||||||
@ -82,7 +81,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 = GJRAND64RandomSource()
|
val random: RandomSource = RandomSource.create()
|
||||||
|
|
||||||
private val _playerInventorySlots = ArrayList<InventorySlot>()
|
private val _playerInventorySlots = ArrayList<InventorySlot>()
|
||||||
private val _playerHotbarSlots = ArrayList<InventorySlot>()
|
private val _playerHotbarSlots = ArrayList<InventorySlot>()
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
Loading…
Reference in New Issue
Block a user