mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComputers into master-MC1.8
Conflicts: src/main/scala/li/cil/oc/integration/opencomputers/DriverMemory.scala src/main/scala/li/cil/oc/server/network/Network.scala
This commit is contained in:
commit
94c7f7a9c2
@ -25,7 +25,7 @@ class Raid(protected implicit val tileTag: ClassTag[tileentity.Raid]) extends Si
|
||||
super.tooltipTail(metadata, stack, player, tooltip, advanced)
|
||||
if (KeyBindings.showExtendedTooltips) {
|
||||
val data = new RaidData(stack)
|
||||
for (disk <- data.disks) {
|
||||
for (disk <- data.disks if disk != null) {
|
||||
tooltip.add("- " + disk.getDisplayName)
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import net.minecraft.item.ItemStack
|
||||
|
||||
object DriverMemory extends Item with driver.item.Memory {
|
||||
override def amount(stack: ItemStack) = Delegator.subItem(stack) match {
|
||||
case Some(memory: item.Memory) => memory.tier
|
||||
case Some(memory: item.Memory) => memory.tier + 1
|
||||
case _ => 0.0
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ import li.cil.oc.OpenComputers
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.network
|
||||
import li.cil.oc.api.network.{Node => ImmutableNode}
|
||||
import li.cil.oc.api.network._
|
||||
import li.cil.oc.api.network.{Node => ImmutableNode}
|
||||
import li.cil.oc.common.tileentity
|
||||
import li.cil.oc.integration.Mods
|
||||
import li.cil.oc.server.network.{Node => MutableNode}
|
||||
@ -26,7 +26,6 @@ import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.util.EnumFacing
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
import scala.collection.mutable
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
|
||||
@ -54,13 +53,21 @@ private class Network private(private val data: mutable.Map[String, Network.Vert
|
||||
node.data.network = wrapper
|
||||
})
|
||||
|
||||
// Called by nodes when they may have changed address from loading.
|
||||
def remap(node: MutableNode) {
|
||||
data.find(_._2.data == node) match {
|
||||
case Some((address, vertex)) =>
|
||||
data -= address
|
||||
data += node.address -> vertex
|
||||
case _ => // Eh?
|
||||
// Called by nodes when they want to change address from loading.
|
||||
def remap(remappedNode: MutableNode, newAddress: String) {
|
||||
data.get(remappedNode.address) match {
|
||||
case Some(node) =>
|
||||
val neighbors = node.edges.map(_.other(node))
|
||||
node.data.remove()
|
||||
node.data.address = newAddress
|
||||
while (data.contains(node.data.address)) {
|
||||
node.data.address = java.util.UUID.randomUUID().toString
|
||||
}
|
||||
if (neighbors.isEmpty)
|
||||
addNew(node.data)
|
||||
else
|
||||
neighbors.foreach(_.data.connect(node.data))
|
||||
case _ => throw new AssertionError("Node believes it belongs to a network it doesn't.")
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +228,7 @@ private class Network private(private val data: mutable.Map[String, Network.Vert
|
||||
newNode
|
||||
}
|
||||
|
||||
private def add(oldNode: Network.Vertex, addedNode: MutableNode) = {
|
||||
private def add(oldNode: Network.Vertex, addedNode: MutableNode): Boolean = {
|
||||
// Queue onConnect calls to avoid side effects from callbacks.
|
||||
val connects = mutable.Buffer.empty[(ImmutableNode, Iterable[ImmutableNode])]
|
||||
// Check if the other node is new or if we have to merge networks.
|
||||
@ -252,44 +259,52 @@ private class Network private(private val data: mutable.Map[String, Network.Vert
|
||||
// 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: Network.Vertex) =>
|
||||
case (_, node: Network.Vertex) =>
|
||||
val neighbors = node.edges.map(_.other(node))
|
||||
node.data.remove()
|
||||
node.data.address = java.util.UUID.randomUUID().toString
|
||||
do {
|
||||
node.data.address = java.util.UUID.randomUUID().toString
|
||||
} while (data.contains(node.data.address) || otherNetwork.data.contains(node.data.address))
|
||||
if (neighbors.isEmpty)
|
||||
otherNetwork.addNew(node.data)
|
||||
else
|
||||
neighbors.foreach(_.data.connect(node.data))
|
||||
}
|
||||
|
||||
if (addedNode.reachability == Visibility.Neighbors)
|
||||
connects += ((addedNode, Iterable(oldNode.data)))
|
||||
if (oldNode.data.reachability == Visibility.Neighbors)
|
||||
connects += ((oldNode.data, Iterable(addedNode)))
|
||||
// The address change can theoretically cause the node to be kicked from
|
||||
// its old network (via onConnect callbacks), so we make sure it's still
|
||||
// in the same network. If it isn't we start over.
|
||||
if (addedNode.network != null && addedNode.network.asInstanceOf[Network.Wrapper].network == otherNetwork) {
|
||||
if (addedNode.reachability == Visibility.Neighbors)
|
||||
connects += ((addedNode, Iterable(oldNode.data)))
|
||||
if (oldNode.data.reachability == Visibility.Neighbors)
|
||||
connects += ((oldNode.data, Iterable(addedNode)))
|
||||
|
||||
val oldNodes = nodes
|
||||
val newNodes = otherNetwork.nodes
|
||||
val oldVisibleNodes = oldNodes.filter(_.reachability == Visibility.Network)
|
||||
val newVisibleNodes = newNodes.filter(_.reachability == Visibility.Network)
|
||||
val oldNodes = nodes
|
||||
val newNodes = otherNetwork.nodes
|
||||
val oldVisibleNodes = oldNodes.filter(_.reachability == Visibility.Network)
|
||||
val newVisibleNodes = newNodes.filter(_.reachability == Visibility.Network)
|
||||
|
||||
newVisibleNodes.foreach(node => connects += ((node, oldNodes)))
|
||||
oldVisibleNodes.foreach(node => connects += ((node, newNodes)))
|
||||
newVisibleNodes.foreach(node => connects += ((node, oldNodes)))
|
||||
oldVisibleNodes.foreach(node => connects += ((node, newNodes)))
|
||||
|
||||
data ++= otherNetwork.data
|
||||
connectors ++= otherNetwork.connectors
|
||||
globalBuffer += otherNetwork.globalBuffer
|
||||
globalBufferSize += otherNetwork.globalBufferSize
|
||||
otherNetwork.data.values.foreach(node => {
|
||||
node.data match {
|
||||
case connector: Connector => connector.distributor = Some(wrapper)
|
||||
case _ =>
|
||||
}
|
||||
node.data.network = wrapper
|
||||
})
|
||||
otherNetwork.data.clear()
|
||||
otherNetwork.connectors.clear()
|
||||
data ++= otherNetwork.data
|
||||
connectors ++= otherNetwork.connectors
|
||||
globalBuffer += otherNetwork.globalBuffer
|
||||
globalBufferSize += otherNetwork.globalBufferSize
|
||||
otherNetwork.data.values.foreach(node => {
|
||||
node.data match {
|
||||
case connector: Connector => connector.distributor = Some(wrapper)
|
||||
case _ =>
|
||||
}
|
||||
node.data.network = wrapper
|
||||
})
|
||||
otherNetwork.data.clear()
|
||||
otherNetwork.connectors.clear()
|
||||
|
||||
Network.Edge(oldNode, node(addedNode))
|
||||
Network.Edge(oldNode, node(addedNode))
|
||||
}
|
||||
else add(oldNode, addedNode)
|
||||
}
|
||||
|
||||
for ((node, nodes) <- connects) nodes.foreach(_.asInstanceOf[MutableNode].onConnect(node))
|
||||
|
@ -67,11 +67,10 @@ trait Node extends ImmutableNode {
|
||||
|
||||
def load(nbt: NBTTagCompound) = {
|
||||
if (nbt.hasKey("address")) {
|
||||
val oldAddress = address
|
||||
address = nbt.getString("address")
|
||||
if (address != oldAddress) network match {
|
||||
case wrapper: Network.Wrapper => wrapper.network.remap(this)
|
||||
case _ =>
|
||||
val newAddress = nbt.getString("address")
|
||||
if (newAddress != address) network match {
|
||||
case wrapper: Network.Wrapper => wrapper.network.remap(this, newAddress)
|
||||
case _ => address = newAddress
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user