subnode bullshit

This commit is contained in:
2026-04-12 00:16:52 +02:00
parent f456b9b04e
commit 59358e6b08
4 changed files with 14 additions and 4 deletions

View File

@@ -40,8 +40,7 @@ class CapacitorEntity(pos: BlockPos, state: BlockState) : NodeEntity(BlockEntiti
class CapacitorBlock : BaseBlock("capacitor"), EntityBlock {
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? {
val cap = CapacitorEntity(blockPos, blockState)
cap.syncReachable()
Networking.addNode(cap.getNode())
cap.initNetworking()
return cap
}

View File

@@ -26,7 +26,7 @@ class ScreenBlock() : BaseBlock("screen"), EntityBlock {
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? {
val scr = ScreenEntity(blockPos, blockState)
Networking.addNode(scr.getNode())
scr.initNetworking()
return scr
}

View File

@@ -12,6 +12,15 @@ open class NodeEntity(blockEntityType: BlockEntityType<*>, blockPos: BlockPos, b
// stuff
open fun getNode(): Networking.Node? = null
open fun getSubnodes(): List<Networking.Node> = listOf()
fun initNetworking() {
val node = getNode()
if(node != null) Networking.addNode(node)
getSubnodes().forEach { Networking.addNode(it) }
syncReachable()
}
open fun getDirectConnections(): List<NodeEntity> {
if(level == null) return listOf();
val offs = listOf(
@@ -80,6 +89,7 @@ open class NodeEntity(blockEntityType: BlockEntityType<*>, blockPos: BlockPos, b
super.setRemoved()
syncReachable()
val n = getNode()
if(n != null) Networking.removeNode(n);
if(n != null) Networking.removeNode(n)
getSubnodes().forEach { Networking.removeNode(it) }
}
}

View File

@@ -146,6 +146,7 @@ object Networking {
}
fun directConnectTo(other: Node) {
if(other == this) return;
if(other in connections) return;
connections.add(other);
this.onConnect(other);