subnode bullshit
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user