Merge branch '1.21' into worldgen-placement-providers

This commit is contained in:
DBotThePony 2025-03-29 22:05:15 +07:00
commit 07e6369454
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 121 additions and 83 deletions

View File

@ -358,6 +358,9 @@ abstract class MatteryBlockEntity(type: BlockEntityType<*>, pos: BlockPos, state
} }
override fun get(): T? { override fun get(): T? {
if (isRemoved)
return null
return cache?.capability return cache?.capability
} }
@ -371,13 +374,13 @@ abstract class MatteryBlockEntity(type: BlockEntityType<*>, pos: BlockPos, state
if (!SERVER_IS_LIVE) return if (!SERVER_IS_LIVE) return
val level = level as? ServerLevel val level = level as? ServerLevel
val creationVersion = ++currentVersion
if (level == null) { if (level == null) {
cache = null cache = null
return return
} }
val creationVersion = ++currentVersion
val direction = blockRotation.side2Dir(side) val direction = blockRotation.side2Dir(side)
cache = BlockCapabilityCache.create( cache = BlockCapabilityCache.create(

View File

@ -1,5 +1,6 @@
package ru.dbotthepony.mc.otm.block.entity.cable package ru.dbotthepony.mc.otm.block.entity.cable
import it.unimi.dsi.fastutil.objects.ObjectArraySet
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.core.Direction import net.minecraft.core.Direction
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
@ -114,6 +115,8 @@ abstract class EnergyCableBlockEntity(type: BlockEntityType<*>, blockPos: BlockP
val sides get() = energySides val sides get() = energySides
val currentlyTransferringTo = ObjectArraySet<Pair<Node, RelativeSide>>()
override fun onNeighbour(link: Link) { override fun onNeighbour(link: Link) {
if (link is DirectionLink) { if (link is DirectionLink) {
updateBlockState(link.direction, true) updateBlockState(link.direction, true)

View File

@ -1,5 +1,6 @@
package ru.dbotthepony.mc.otm.block.entity.cable package ru.dbotthepony.mc.otm.block.entity.cable
import it.unimi.dsi.fastutil.ints.IntRBTreeSet
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.ReferenceLinkedOpenHashSet import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet
@ -19,6 +20,7 @@ import ru.dbotthepony.mc.otm.core.shuffle
import ru.dbotthepony.mc.otm.graph.GraphNodeList import ru.dbotthepony.mc.otm.graph.GraphNodeList
import ru.dbotthepony.mc.otm.onceServer import ru.dbotthepony.mc.otm.onceServer
import java.util.* import java.util.*
import java.util.concurrent.atomic.AtomicLong
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlin.collections.HashSet import kotlin.collections.HashSet
import kotlin.collections.LinkedHashSet import kotlin.collections.LinkedHashSet
@ -626,21 +628,36 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
notifyThroughputsChanged() notifyThroughputsChanged()
} }
private val indicesToRemove = IntRBTreeSet()
private var recursionLevel = 0
fun receiveEnergy(howMuch: Decimal, simulate: Boolean, fromNode: EnergyCableBlockEntity.Node, fromSide: RelativeSide): Decimal { fun receiveEnergy(howMuch: Decimal, simulate: Boolean, fromNode: EnergyCableBlockEntity.Node, fromSide: RelativeSide): Decimal {
val thisLevel = ++recursionLevel
val isMaster = thisLevel == 1
if (isMaster)
livelyNodesList.shuffle(fromNode.blockEntity.level!!.otmRandom) livelyNodesList.shuffle(fromNode.blockEntity.level!!.otmRandom)
var i = -1
val itr = livelyNodesList.iterator() val itr = livelyNodesList.iterator()
var received = Decimal.ZERO var received = Decimal.ZERO
var residue = howMuch.coerceAtMost(fromNode.energyThroughput) var residue = howMuch.coerceAtMost(fromNode.energyThroughput)
val snapshot = Reference2ObjectOpenHashMap<Segment, Decimal>() val snapshot = Reference2ObjectOpenHashMap<Segment, Decimal>()
for (pair in itr) { for (pair in itr) {
i++
// recursion prevention
if (!fromNode.currentlyTransferringTo.add(pair))
continue
try {
val (node, relSide) = pair val (node, relSide) = pair
val side = node.sides[relSide]!! val side = node.sides[relSide]!!
if (!side.isEnabled) { if (!side.isEnabled) {
itr.remove() indicesToRemove.add(i)
check(livelyNodes.remove(pair)) { "Lively nodes Set does not contain $pair" } livelyNodes.remove(pair)
continue continue
} else if (fromNode === node && side.side === fromSide) { } else if (fromNode === node && side.side === fromSide) {
continue continue
@ -649,8 +666,8 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
val it = side.neighbour.get() val it = side.neighbour.get()
if (it == null || it is EnergyCableBlockEntity.CableSide) { if (it == null || it is EnergyCableBlockEntity.CableSide) {
itr.remove() indicesToRemove.add(i)
check(livelyNodes.remove(pair)) { "Lively nodes Set does not contain $pair" } livelyNodes.remove(pair)
continue continue
} }
@ -726,6 +743,21 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
paths.forEach { it.shortCircuit = true } paths.forEach { it.shortCircuit = true }
} }
} }
} finally {
fromNode.currentlyTransferringTo.remove(pair)
}
}
recursionLevel--
if (isMaster && indicesToRemove.isNotEmpty()) {
val indices = indicesToRemove.iterator(indicesToRemove.lastInt())
while (indices.hasPrevious()) {
livelyNodesList.removeAt(indices.previousInt())
}
indicesToRemove.clear()
} }
return received return received

View File

@ -77,7 +77,7 @@ open class MatteryMenuSlot(container: Container, index: Int, x: Int = 0, y: Int
} }
open fun canTakeItemForPickAll(): Boolean { open fun canTakeItemForPickAll(): Boolean {
return (container.containerSlotOrNull(slotIndex) as? IFilteredContainerSlot)?.filter == null return (container.containerSlotOrNull(slotIndex) as? IFilteredContainerSlot)?.filter?.allowAll != false
} }
override fun getMaxStackSize(): Int { override fun getMaxStackSize(): Int {