From 59358e6b0884104de29b502ae83f102a14f5a056 Mon Sep 17 00:00:00 2001 From: IonutParau Date: Sun, 12 Apr 2026 00:16:52 +0200 Subject: [PATCH] subnode bullshit --- .../org/neoflock/neocomputers/block/Capacitor.kt | 3 +-- .../org/neoflock/neocomputers/block/ScreenBlock.kt | 2 +- .../org/neoflock/neocomputers/entity/NodeEntity.kt | 12 +++++++++++- .../org/neoflock/neocomputers/network/Networking.kt | 1 + 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt b/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt index d8979ae..50bdf8c 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt @@ -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 } diff --git a/src/main/kotlin/org/neoflock/neocomputers/block/ScreenBlock.kt b/src/main/kotlin/org/neoflock/neocomputers/block/ScreenBlock.kt index cae61c2..b111c0b 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/block/ScreenBlock.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/block/ScreenBlock.kt @@ -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 } diff --git a/src/main/kotlin/org/neoflock/neocomputers/entity/NodeEntity.kt b/src/main/kotlin/org/neoflock/neocomputers/entity/NodeEntity.kt index 8f04ece..ed2356c 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/entity/NodeEntity.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/entity/NodeEntity.kt @@ -12,6 +12,15 @@ open class NodeEntity(blockEntityType: BlockEntityType<*>, blockPos: BlockPos, b // stuff open fun getNode(): Networking.Node? = null + open fun getSubnodes(): List = listOf() + + fun initNetworking() { + val node = getNode() + if(node != null) Networking.addNode(node) + getSubnodes().forEach { Networking.addNode(it) } + syncReachable() + } + open fun getDirectConnections(): List { 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) } } } \ No newline at end of file diff --git a/src/main/kotlin/org/neoflock/neocomputers/network/Networking.kt b/src/main/kotlin/org/neoflock/neocomputers/network/Networking.kt index 915dcc0..c0356fc 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/network/Networking.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/network/Networking.kt @@ -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);