From 6e4debf72bf82c986ce93b9dfe9d9db91fa54ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Fri, 13 Feb 2015 16:10:06 +0100 Subject: [PATCH] Underped MCU and Access Points' outer component nodes a little. This also means MCU is now network visible again. --- .../oc/common/tileentity/AccessPoint.scala | 18 ++++++----- .../common/tileentity/Microcontroller.scala | 32 +++++++++++++++++-- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/tileentity/AccessPoint.scala b/src/main/scala/li/cil/oc/common/tileentity/AccessPoint.scala index 79a1c5f75..8abbb7ff5 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/AccessPoint.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/AccessPoint.scala @@ -16,8 +16,6 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.common.util.Constants.NBT import net.minecraftforge.common.util.ForgeDirection -import scala.collection.convert.WrapAsScala._ - class AccessPoint extends Switch with WirelessEndpoint with traits.PowerAcceptor { var strength = Settings.get.maxWirelessRange @@ -94,28 +92,32 @@ class AccessPoint extends Switch with WirelessEndpoint with traits.PowerAcceptor } } + // ----------------------------------------------------------------------- // + override protected def createNode(plug: Plug) = api.Network.newNode(plug, Visibility.Network). withConnector(math.round(Settings.get.bufferAccessPoint)). create() - // ----------------------------------------------------------------------- // - override protected def onPlugConnect(plug: Plug, node: Node) { super.onPlugConnect(plug, node) if (node == plug.node) { api.Network.joinWirelessNetwork(this) } - if (!node.network.nodes.exists(componentNodes.contains)) { - node.connect(componentNodes(plug.side.ordinal)) - } + if (plug.isPrimary) + plug.node.connect(componentNodes(plug.side.ordinal())) + else + componentNodes(plug.side.ordinal).remove() } override protected def onPlugDisconnect(plug: Plug, node: Node) { super.onPlugDisconnect(plug, node) if (node == plug.node) { api.Network.leaveWirelessNetwork(this) - componentNodes(plug.side.ordinal).remove() } + if (plug.isPrimary && node != plug.node) + plug.node.connect(componentNodes(plug.side.ordinal())) + else + componentNodes(plug.side.ordinal).remove() } // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala b/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala index 8af1bc652..b33b7ae67 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala @@ -13,6 +13,7 @@ import li.cil.oc.common.Tier import li.cil.oc.common.item.data.MicrocontrollerData import li.cil.oc.util.ExtendedArguments._ import li.cil.oc.util.ExtendedNBT._ +import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.common.util.Constants.NBT @@ -38,6 +39,7 @@ class Microcontroller extends traits.PowerAcceptor with traits.Hub with traits.C if (machine != null) { machine.node.asInstanceOf[Connector].setLocalBufferSize(0) + machine.setCostPerTick(Settings.get.microcontrollerCost) } override def tier = info.tier @@ -60,6 +62,16 @@ class Microcontroller extends traits.PowerAcceptor with traits.Hub with traits.C // ----------------------------------------------------------------------- // + override def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float): Array[Node] = { + super.onAnalyze(player, side, hitX, hitY, hitZ) + if (ForgeDirection.getOrientation(side) != facing) + Array(componentNodes(side)) + else + Array(machine.node) + } + + // ----------------------------------------------------------------------- // + override def internalComponents(): java.lang.Iterable[ItemStack] = asJavaIterable(info.components) override def componentSlot(address: String) = components.indexWhere(_.exists(env => env.node != null && env.node.address == address)) @@ -132,13 +144,23 @@ class Microcontroller extends traits.PowerAcceptor with traits.Hub with traits.C create() override protected def onPlugConnect(plug: Plug, node: Node): Unit = { + super.onPlugConnect(plug, node) if (node == plug.node) { api.Network.joinNewNetwork(machine.node) machine.node.connect(snooperNode) - machine.setCostPerTick(Settings.get.microcontrollerCost) - node.connect(componentNodes(plug.side.ordinal)) } - super.onPlugConnect(plug, node) + if (plug.isPrimary) + plug.node.connect(componentNodes(plug.side.ordinal())) + else + componentNodes(plug.side.ordinal).remove() + } + + override protected def onPlugDisconnect(plug: Plug, node: Node) { + super.onPlugDisconnect(plug, node) + if (plug.isPrimary && node != plug.node) + plug.node.connect(componentNodes(plug.side.ordinal())) + else + componentNodes(plug.side.ordinal).remove() } override protected def onPlugMessage(plug: Plug, message: Message): Unit = { @@ -166,7 +188,10 @@ class Microcontroller extends traits.PowerAcceptor with traits.Hub with traits.C zipWithIndex.foreach { case (tag, index) => componentNodes(index).load(tag) } + snooperNode.load(nbt.getCompoundTag(Settings.namespace + "snooper")) super.readFromNBTForServer(nbt) + api.Network.joinNewNetwork(machine.node) + machine.node.connect(snooperNode) } override def writeToNBTForServer(nbt: NBTTagCompound) { @@ -180,6 +205,7 @@ class Microcontroller extends traits.PowerAcceptor with traits.Hub with traits.C tag case _ => new NBTTagCompound() }) + nbt.setNewCompoundTag(Settings.namespace + "snooper", snooperNode.save) } // ----------------------------------------------------------------------- //