mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 17:56:34 -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)
|
super.tooltipTail(metadata, stack, player, tooltip, advanced)
|
||||||
if (KeyBindings.showExtendedTooltips) {
|
if (KeyBindings.showExtendedTooltips) {
|
||||||
val data = new RaidData(stack)
|
val data = new RaidData(stack)
|
||||||
for (disk <- data.disks) {
|
for (disk <- data.disks if disk != null) {
|
||||||
tooltip.add("- " + disk.getDisplayName)
|
tooltip.add("- " + disk.getDisplayName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import net.minecraft.item.ItemStack
|
|||||||
|
|
||||||
object DriverMemory extends Item with driver.item.Memory {
|
object DriverMemory extends Item with driver.item.Memory {
|
||||||
override def amount(stack: ItemStack) = Delegator.subItem(stack) match {
|
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
|
case _ => 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ import li.cil.oc.OpenComputers
|
|||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.api
|
import li.cil.oc.api
|
||||||
import li.cil.oc.api.network
|
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._
|
||||||
|
import li.cil.oc.api.network.{Node => ImmutableNode}
|
||||||
import li.cil.oc.common.tileentity
|
import li.cil.oc.common.tileentity
|
||||||
import li.cil.oc.integration.Mods
|
import li.cil.oc.integration.Mods
|
||||||
import li.cil.oc.server.network.{Node => MutableNode}
|
import li.cil.oc.server.network.{Node => MutableNode}
|
||||||
@ -26,7 +26,6 @@ import net.minecraft.tileentity.TileEntity
|
|||||||
import net.minecraft.util.EnumFacing
|
import net.minecraft.util.EnumFacing
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
import scala.collection.convert.WrapAsScala._
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
import scala.collection.mutable.ArrayBuffer
|
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
|
node.data.network = wrapper
|
||||||
})
|
})
|
||||||
|
|
||||||
// Called by nodes when they may have changed address from loading.
|
// Called by nodes when they want to change address from loading.
|
||||||
def remap(node: MutableNode) {
|
def remap(remappedNode: MutableNode, newAddress: String) {
|
||||||
data.find(_._2.data == node) match {
|
data.get(remappedNode.address) match {
|
||||||
case Some((address, vertex)) =>
|
case Some(node) =>
|
||||||
data -= address
|
val neighbors = node.edges.map(_.other(node))
|
||||||
data += node.address -> vertex
|
node.data.remove()
|
||||||
case _ => // Eh?
|
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
|
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.
|
// Queue onConnect calls to avoid side effects from callbacks.
|
||||||
val connects = mutable.Buffer.empty[(ImmutableNode, Iterable[ImmutableNode])]
|
val connects = mutable.Buffer.empty[(ImmutableNode, Iterable[ImmutableNode])]
|
||||||
// Check if the other node is new or if we have to merge networks.
|
// Check if the other node is new or if we have to merge networks.
|
||||||
@ -252,16 +259,22 @@ private class Network private(private val data: mutable.Map[String, Network.Vert
|
|||||||
// never happen in normal operation anyway. It *can* happen when NBT
|
// never happen in normal operation anyway. It *can* happen when NBT
|
||||||
// editing stuff or using mods to clone blocks (e.g. WorldEdit).
|
// editing stuff or using mods to clone blocks (e.g. WorldEdit).
|
||||||
otherNetwork.data.filter(entry => data.contains(entry._1)).toArray.foreach {
|
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))
|
val neighbors = node.edges.map(_.other(node))
|
||||||
node.data.remove()
|
node.data.remove()
|
||||||
|
do {
|
||||||
node.data.address = java.util.UUID.randomUUID().toString
|
node.data.address = java.util.UUID.randomUUID().toString
|
||||||
|
} while (data.contains(node.data.address) || otherNetwork.data.contains(node.data.address))
|
||||||
if (neighbors.isEmpty)
|
if (neighbors.isEmpty)
|
||||||
otherNetwork.addNew(node.data)
|
otherNetwork.addNew(node.data)
|
||||||
else
|
else
|
||||||
neighbors.foreach(_.data.connect(node.data))
|
neighbors.foreach(_.data.connect(node.data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
if (addedNode.reachability == Visibility.Neighbors)
|
||||||
connects += ((addedNode, Iterable(oldNode.data)))
|
connects += ((addedNode, Iterable(oldNode.data)))
|
||||||
if (oldNode.data.reachability == Visibility.Neighbors)
|
if (oldNode.data.reachability == Visibility.Neighbors)
|
||||||
@ -291,6 +304,8 @@ private class Network private(private val data: mutable.Map[String, Network.Vert
|
|||||||
|
|
||||||
Network.Edge(oldNode, node(addedNode))
|
Network.Edge(oldNode, node(addedNode))
|
||||||
}
|
}
|
||||||
|
else add(oldNode, addedNode)
|
||||||
|
}
|
||||||
|
|
||||||
for ((node, nodes) <- connects) nodes.foreach(_.asInstanceOf[MutableNode].onConnect(node))
|
for ((node, nodes) <- connects) nodes.foreach(_.asInstanceOf[MutableNode].onConnect(node))
|
||||||
|
|
||||||
|
@ -67,11 +67,10 @@ trait Node extends ImmutableNode {
|
|||||||
|
|
||||||
def load(nbt: NBTTagCompound) = {
|
def load(nbt: NBTTagCompound) = {
|
||||||
if (nbt.hasKey("address")) {
|
if (nbt.hasKey("address")) {
|
||||||
val oldAddress = address
|
val newAddress = nbt.getString("address")
|
||||||
address = nbt.getString("address")
|
if (newAddress != address) network match {
|
||||||
if (address != oldAddress) network match {
|
case wrapper: Network.Wrapper => wrapper.network.remap(this, newAddress)
|
||||||
case wrapper: Network.Wrapper => wrapper.network.remap(this)
|
case _ => address = newAddress
|
||||||
case _ =>
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user