mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
Added code to handle merges of networks containing nodes with identical addresses. Should do the trick for #790, needs confirmation.
This commit is contained in:
parent
2852ba1591
commit
2c6f0ee181
@ -25,6 +25,7 @@ import net.minecraft.nbt._
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
import scala.collection.JavaConverters._
|
||||
import scala.collection.mutable
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
@ -242,6 +243,22 @@ private class Network private(private val data: mutable.Map[String, Network.Vert
|
||||
else {
|
||||
val otherNetwork = addedNode.network.asInstanceOf[Network.Wrapper].network
|
||||
|
||||
// If the other network contains nodes with addresses used in our local
|
||||
// network we'll have to re-assign those... since dynamically handling
|
||||
// changes to one's address is not expected of nodes / hosts, we have to
|
||||
// remove and reconnect the nodes. This is a pretty shitty solution, and
|
||||
// may break things slightly here and there (e.g. if this is the node of
|
||||
// a running machine the computer will most likely crash), but it should
|
||||
// never happen in normal operation anyway. It *can* happen when NBT
|
||||
// editing stuff or using mods to clone blocks (e.g. WorldEdit).
|
||||
otherNetwork.data.filter(entry => data.contains(entry._1)).toArray.foreach {
|
||||
case (address, node: MutableNode) =>
|
||||
val neighbors = node.neighbors.toArray // Copy to be on the safe side.
|
||||
node.remove()
|
||||
node.address = java.util.UUID.randomUUID().toString
|
||||
neighbors.foreach(_.connect(node))
|
||||
}
|
||||
|
||||
if (addedNode.reachability == Visibility.Neighbors)
|
||||
connects += ((addedNode, Iterable(oldNode.data)))
|
||||
if (oldNode.data.reachability == Visibility.Neighbors)
|
||||
@ -462,7 +479,6 @@ object Network extends api.detail.NetworkAPI {
|
||||
case host: TileMultipart =>
|
||||
host.partList.forall {
|
||||
case part: JNormalOcclusion if !part.isInstanceOf[CablePart] =>
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
val ownBounds = Iterable(new Cuboid6(Cable.cachedBounds(side.flag)))
|
||||
val otherBounds = part.getOcclusionBoxes
|
||||
NormalOcclusionTest(ownBounds, otherBounds)
|
||||
|
Loading…
x
Reference in New Issue
Block a user