From 2c6f0ee1811e07795282212b8eecac6a40aad7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 7 Jan 2015 13:32:23 +0100 Subject: [PATCH] Added code to handle merges of networks containing nodes with identical addresses. Should do the trick for #790, needs confirmation. --- .../li/cil/oc/server/network/Network.scala | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/scala/li/cil/oc/server/network/Network.scala b/src/main/scala/li/cil/oc/server/network/Network.scala index deb0043fb..8e2f9355f 100644 --- a/src/main/scala/li/cil/oc/server/network/Network.scala +++ b/src/main/scala/li/cil/oc/server/network/Network.scala @@ -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)