Merge remote-tracking branch 'origin/1.21' into 1.21

This commit is contained in:
GearShocky 2025-01-20 12:40:14 +05:00
commit 75e9b782fa
4 changed files with 81 additions and 40 deletions

View File

@ -261,6 +261,8 @@ private fun misc(provider: MatteryLanguageProvider) {
misc("suffix.exa", "%s E%s") misc("suffix.exa", "%s E%s")
misc("suffix.zetta", "%s Z%s") misc("suffix.zetta", "%s Z%s")
misc("suffix.yotta", "%s Y%s") misc("suffix.yotta", "%s Y%s")
misc("suffix.ronna", "%s R%s")
misc("suffix.quetta", "%s Q%s")
misc("suffix.deci", "%s d%s") misc("suffix.deci", "%s d%s")
misc("suffix.centi", "%s c%s") misc("suffix.centi", "%s c%s")
@ -282,6 +284,8 @@ private fun misc(provider: MatteryLanguageProvider) {
misc("suffix_concise.exa", "%sE") misc("suffix_concise.exa", "%sE")
misc("suffix_concise.zetta", "%sZ") misc("suffix_concise.zetta", "%sZ")
misc("suffix_concise.yotta", "%sY") misc("suffix_concise.yotta", "%sY")
misc("suffix_concise.ronna", "%sR")
misc("suffix_concise.quetta", "%sQ")
misc("suffix_concise.deci", "%sd") misc("suffix_concise.deci", "%sd")
misc("suffix_concise.centi", "%sc") misc("suffix_concise.centi", "%sc")
@ -302,6 +306,9 @@ private fun misc(provider: MatteryLanguageProvider) {
misc("suffix_raw.exa", "E") misc("suffix_raw.exa", "E")
misc("suffix_raw.zetta", "Z") misc("suffix_raw.zetta", "Z")
misc("suffix_raw.yotta", "Y") misc("suffix_raw.yotta", "Y")
misc("suffix_raw.ronna", "R")
misc("suffix_raw.quetta", "Q")
misc("suffix_raw.deci", "d") misc("suffix_raw.deci", "d")
misc("suffix_raw.centi", "c") misc("suffix_raw.centi", "c")
misc("suffix_raw.milli", "m") misc("suffix_raw.milli", "m")

View File

@ -269,6 +269,8 @@ private fun misc(provider: MatteryLanguageProvider) {
misc("suffix.exa", "%s Э%s") misc("suffix.exa", "%s Э%s")
misc("suffix.zetta", "%s З%s") misc("suffix.zetta", "%s З%s")
misc("suffix.yotta", "%s И%s") misc("suffix.yotta", "%s И%s")
misc("suffix.ronna", "%s Рн%s")
misc("suffix.quetta", "%s Кв%s")
misc("suffix.deci", "%s д%s") misc("suffix.deci", "%s д%s")
misc("suffix.centi", "%s с%s") misc("suffix.centi", "%s с%s")
@ -290,6 +292,9 @@ private fun misc(provider: MatteryLanguageProvider) {
misc("suffix_concise.exa", "%sЭ") misc("suffix_concise.exa", "%sЭ")
misc("suffix_concise.zetta", "%sЗ") misc("suffix_concise.zetta", "%sЗ")
misc("suffix_concise.yotta", "%sИ") misc("suffix_concise.yotta", "%sИ")
misc("suffix_concise.ronna", "%sРн")
misc("suffix_concise.quetta", "%sКв")
misc("suffix_concise.deci", "%sд") misc("suffix_concise.deci", "%sд")
misc("suffix_concise.centi", "%sс") misc("suffix_concise.centi", "%sс")
misc("suffix_concise.milli", "%sм") misc("suffix_concise.milli", "%sм")
@ -309,6 +314,9 @@ private fun misc(provider: MatteryLanguageProvider) {
misc("suffix_raw.exa", "Э") misc("suffix_raw.exa", "Э")
misc("suffix_raw.zetta", "З") misc("suffix_raw.zetta", "З")
misc("suffix_raw.yotta", "И") misc("suffix_raw.yotta", "И")
misc("suffix_raw.ronna", "Рн")
misc("suffix_raw.quetta", "Кв")
misc("suffix_raw.deci", "д") misc("suffix_raw.deci", "д")
misc("suffix_raw.centi", "с") misc("suffix_raw.centi", "с")
misc("suffix_raw.milli", "м") misc("suffix_raw.milli", "м")

View File

@ -1,11 +1,8 @@
package ru.dbotthepony.mc.otm.block.entity.cable package ru.dbotthepony.mc.otm.block.entity.cable
import it.unimi.dsi.fastutil.ints.IntLists
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.ReferenceArraySet import it.unimi.dsi.fastutil.objects.ReferenceArraySet
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import ru.dbotthepony.mc.otm.SERVER_IS_LIVE import ru.dbotthepony.mc.otm.SERVER_IS_LIVE
@ -19,6 +16,7 @@ import ru.dbotthepony.mc.otm.onceServer
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlin.collections.HashSet import kotlin.collections.HashSet
import kotlin.collections.LinkedHashSet
import kotlin.math.ln import kotlin.math.ln
class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableGraph>() { class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableGraph>() {
@ -69,7 +67,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
} }
class SegmentPath(private val a: BlockPos, private val b: BlockPos) { class SegmentPath(private val a: BlockPos, private val b: BlockPos) {
val segments = ObjectLinkedOpenHashSet<Segment>() val segments = LinkedHashSet<Segment>()
private var shortCircuit = false private var shortCircuit = false
private var lastTickTransfers = 0 private var lastTickTransfers = 0
private var lastTick = 0 private var lastTick = 0
@ -134,13 +132,25 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
nodes.add(node) nodes.add(node)
} }
private val nodes = ObjectLinkedOpenHashSet<EnergyCableBlockEntity.Node>() private val nodes = LinkedHashSet<EnergyCableBlockEntity.Node>()
private val paths = ReferenceOpenHashSet<SegmentPath>() private var paths = ReferenceLinkedOpenHashSet<SegmentPath>()
operator fun contains(node: EnergyCableBlockEntity.Node): Boolean { operator fun contains(node: EnergyCableBlockEntity.Node): Boolean {
return node in nodes return node in nodes
} }
fun missingNodes(from: Collection<EnergyCableBlockEntity.Node>): List<EnergyCableBlockEntity.Node> {
val missing = ArrayList<EnergyCableBlockEntity.Node>()
this.nodes.forEach {
if (it !in from) {
missing.add(it)
}
}
return missing
}
var throughput = Decimal.ZERO var throughput = Decimal.ZERO
private set private set
@ -192,9 +202,9 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
lastPoweredSwitchFrequency = (lastPoweredSwitchFrequency shl 1) or (if (changed) 1 else 0) lastPoweredSwitchFrequency = (lastPoweredSwitchFrequency shl 1) or (if (changed) 1 else 0)
if (hasBlockstateTimer && SERVER_IS_LIVE) { if (hasBlockstateTimer && SERVER_IS_LIVE) {
var i = 20 var i = 30
for (index in 0 .. 16) { for (index in 0 .. 26) {
if (lastPoweredSwitchFrequency and (1 shl index) != 0) { if (lastPoweredSwitchFrequency and (1 shl index) != 0) {
i-- i--
} }
@ -284,8 +294,9 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
} }
fun add(path: SegmentPath) { fun add(path: SegmentPath) {
check(paths.add(path)) { "Path $path shouldn't contain $this" } if (paths.add(path)) {
check(path.segments.add(this)) { "Path set and Segment disagree whenever $this is absent from $path" } check(path.segments.add(this)) { "Path set and Segment disagree whenever $this is absent from $path" }
}
} }
fun remove(path: SegmentPath) { fun remove(path: SegmentPath) {
@ -295,23 +306,23 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
// breaks "instant snapshots" of segments atm // breaks "instant snapshots" of segments atm
// shouldn't cause major gameplay issues though // shouldn't cause major gameplay issues though
fun split(): List<Segment> { fun split(nodes: Collection<EnergyCableBlockEntity.Node>): List<Segment> {
if (nodes.isEmpty()) { for (node in nodes)
throw IllegalStateException("Empty segment somehow?") require(node in this.nodes) { "$node does not belong to $this" }
} else if (nodes.size == 1) {
if (this.nodes.size == 1) {
return listOf(this) return listOf(this)
} else { } else {
lastPoweredStatus = 0
val list = ArrayList(nodes)
val itr = list.iterator()
itr.next()
val result = ArrayList<Segment>() val result = ArrayList<Segment>()
result.add(this) result.add(this)
for (v in itr) { for (v in nodes) {
v.segment = Segment() v.segment = Segment()
v.segment.throughput = v.energyThroughput
v.segment.throughputKnown = true
v.segment.transferredLastTick = transferredLastTick v.segment.transferredLastTick = transferredLastTick
v.segment.paths.addAll(paths) v.segment.lastPoweredStatus = lastPoweredStatus
v.segment.paths = paths.clone()
paths.forEach { it.segments.add(v.segment) } paths.forEach { it.segments.add(v.segment) }
result.add(v.segment) result.add(v.segment)
} }
@ -391,7 +402,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
if (first.node === b) { if (first.node === b) {
// solution found // solution found
val solution = ArrayList<EnergyCableBlockEntity.Node>() val solution = LinkedHashSet<EnergyCableBlockEntity.Node>()
var last = first.parent var last = first.parent
solution.add(first.node) solution.add(first.node)
@ -402,10 +413,23 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
} }
val touchedSegments = ReferenceArraySet<Segment>() val touchedSegments = ReferenceArraySet<Segment>()
solution.forEach { touchedSegments.addAll(it.segment.split()) }
for (it in solution) {
if (it.segment in touchedSegments)
continue
val diff = it.segment.missingNodes(solution)
// segment satisfies new constraints
if (diff.isEmpty()) {
touchedSegments.add(it.segment)
} else {
touchedSegments.addAll(it.segment.split(diff))
}
}
val path = SegmentPath(a.blockEntity.blockPos, b.blockEntity.blockPos) val path = SegmentPath(a.blockEntity.blockPos, b.blockEntity.blockPos)
solution.forEach { it.segment.add(path) } solution.forEach { it.segment.add(path) }
touchedSegments.forEach { it.tryCombine(touchedSegments) } touchedSegments.forEach { it.tryCombine(touchedSegments) }
return path return path

View File

@ -9,14 +9,14 @@ import java.math.BigInteger
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
enum class SiPrefix(val power: Int, val symbol: String) { enum class SiPrefix(val power: Int, val symbol: String) {
YOCTO(-8, "y"), YOCTO (-8, "y"),
ZEPTO(-7, "z"), ZEPTO (-7, "z"),
ATTO (-6, "a"), ATTO (-6, "a"),
FEMTO(-5, "f"), FEMTO (-5, "f"),
PICO (-4, "p"), PICO (-4, "p"),
NANO (-3, "n"), NANO (-3, "n"),
MICRO(-2, "μ"), MICRO (-2, "μ"),
MILLI(-1, "m"), MILLI (-1, "m"),
NONE(0, "") { NONE(0, "") {
override val isEmpty: Boolean override val isEmpty: Boolean
@ -26,14 +26,16 @@ enum class SiPrefix(val power: Int, val symbol: String) {
get() = 0 get() = 0
}, },
KILO (1, "k"), KILO (1, "k"),
MEGA (2, "M"), MEGA (2, "M"),
GIGA (3, "G"), GIGA (3, "G"),
TERA (4, "T"), TERA (4, "T"),
PETA (5, "P"), PETA (5, "P"),
EXA (6, "E"), EXA (6, "E"),
ZETTA(7, "Z"), ZETTA (7, "Z"),
YOTTA(8, "Y"); YOTTA (8, "Y"),
RONNA (9, "R"),
QUETTA(10, "Q");
open val isEmpty: Boolean get() = false open val isEmpty: Boolean get() = false