diff --git a/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala b/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala index 24ef6c657..8e7c76a71 100644 --- a/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala +++ b/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala @@ -173,7 +173,7 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai private def drawNEIHighlights(): Unit = { val panel = LayoutManager.itemPanel if (panel == null) return - zLevel += 500 + zLevel += 350 for (index <- 0 until ItemPanel.items.size()) { val rect = panel.getSlotRect(index) val slot = panel.getSlotMouseOver(rect.x, rect.y) @@ -188,6 +188,6 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai case _ => } } - zLevel -= 500 + zLevel -= 350 } } diff --git a/src/main/scala/li/cil/oc/common/tileentity/Redstone.scala b/src/main/scala/li/cil/oc/common/tileentity/Redstone.scala index 9e48604ab..7810ca194 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Redstone.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Redstone.scala @@ -1,6 +1,7 @@ package li.cil.oc.common.tileentity import li.cil.oc.Settings +import li.cil.oc.api import li.cil.oc.api.network.Visibility import li.cil.oc.common.tileentity.traits.BundledRedstoneAware import li.cil.oc.common.tileentity.traits.Environment @@ -17,10 +18,12 @@ class Redstone extends Environment with BundledRedstoneAware { else new component.Redstone.Vanilla(this) val node = instance.node - if (node != null) { + val dummyNode = if (node != null) { node.setVisibility(Visibility.Network) _isOutputEnabled = true + api.Network.newNode(this, Visibility.None).create() } + else null override def canUpdate = isServer @@ -38,8 +41,9 @@ class Redstone extends Environment with BundledRedstoneAware { // ----------------------------------------------------------------------- // - override protected def onRedstoneInputChanged(side: ForgeDirection) { - super.onRedstoneInputChanged(side) - node.sendToReachable("computer.signal", "redstone_changed", Int.box(side.ordinal())) + override protected def onRedstoneInputChanged(side: ForgeDirection, oldMaxValue: Int, newMaxValue: Int) { + super.onRedstoneInputChanged(side, oldMaxValue, newMaxValue) + node.connect(dummyNode) + dummyNode.sendToNeighbors("redstone.changed", side, int2Integer(oldMaxValue), int2Integer(newMaxValue)) } } diff --git a/src/main/scala/li/cil/oc/common/tileentity/Screen.scala b/src/main/scala/li/cil/oc/common/tileentity/Screen.scala index 4812ceb8d..4c26a868f 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Screen.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Screen.scala @@ -314,8 +314,8 @@ class Screen(var tier: Int) extends traits.TextBuffer with SidedEnvironment with override def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float) = Array(origin.node) - override protected def onRedstoneInputChanged(side: ForgeDirection) { - super.onRedstoneInputChanged(side) + override protected def onRedstoneInputChanged(side: ForgeDirection, oldMaxValue: Int, newMaxValue: Int) { + super.onRedstoneInputChanged(side, oldMaxValue, newMaxValue) val hasRedstoneInput = screens.map(_.maxInput).max > 0 if (hasRedstoneInput != hadRedstoneInput) { hadRedstoneInput = hasRedstoneInput diff --git a/src/main/scala/li/cil/oc/common/tileentity/ServerRack.scala b/src/main/scala/li/cil/oc/common/tileentity/ServerRack.scala index e2b988277..07efb74c1 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/ServerRack.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/ServerRack.scala @@ -506,10 +506,10 @@ class ServerRack extends traits.PowerAcceptor with traits.Hub with traits.PowerB checkRedstoneInputChanged() } - override protected def onRedstoneInputChanged(side: ForgeDirection) { - super.onRedstoneInputChanged(side) + override protected def onRedstoneInputChanged(side: ForgeDirection, oldMaxValue: Int, newMaxValue: Int) { + super.onRedstoneInputChanged(side, oldMaxValue, newMaxValue) servers collect { - case Some(server) => server.machine.node.sendToNeighbors("redstone.changed", toLocal(side)) + case Some(server) => server.machine.node.sendToNeighbors("redstone.changed", toLocal(side), int2Integer(oldMaxValue), int2Integer(newMaxValue)) } } diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/BundledRedstoneAware.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/BundledRedstoneAware.scala index a0a3b16fb..3178f5769 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/BundledRedstoneAware.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/BundledRedstoneAware.scala @@ -48,13 +48,15 @@ trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBund def bundledInput(side: ForgeDirection, color: Int) = math.max(_bundledInput(side.ordinal())(color), _rednetInput(side.ordinal())(color)) - def rednetInput(side: ForgeDirection, color: Int, value: Int) = - if (_rednetInput(side.ordinal())(color) != value) { - if (_rednetInput(side.ordinal())(color) != -1) { - onRedstoneInputChanged(side) + def rednetInput(side: ForgeDirection, color: Int, value: Int): Unit = { + val oldValue = _rednetInput(side.ordinal())(color) + if (oldValue != value) { + if (oldValue != -1) { + onRedstoneInputChanged(side, oldValue, value) } _rednetInput(side.ordinal())(color) = value } + } def bundledOutput(side: ForgeDirection) = _bundledOutput(toLocal(side).ordinal()) @@ -78,19 +80,20 @@ trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBund override protected def updateRedstoneInput(side: ForgeDirection) { super.updateRedstoneInput(side) - val oldBundledInput = _bundledInput(side.ordinal()) + val ownBundledInput = _bundledInput(side.ordinal()) val newBundledInput = computeBundledInput(side) + val oldMaxValue = ownBundledInput.max var changed = false if (newBundledInput != null) for (color <- 0 until 16) { - changed = changed || (oldBundledInput(color) >= 0 && oldBundledInput(color) != newBundledInput(color)) - oldBundledInput(color) = newBundledInput(color) + changed = changed || (ownBundledInput(color) >= 0 && ownBundledInput(color) != newBundledInput(color)) + ownBundledInput(color) = newBundledInput(color) } else for (color <- 0 until 16) { - changed = changed || oldBundledInput(color) > 0 - oldBundledInput(color) = 0 + changed = changed || ownBundledInput(color) > 0 + ownBundledInput(color) = 0 } if (changed) { - onRedstoneInputChanged(side) + onRedstoneInputChanged(side, oldMaxValue, ownBundledInput.max) } } diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala index 300f68b46..495f50f2b 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala @@ -204,9 +204,9 @@ trait Computer extends Environment with ComponentInventory with Rotatable with B checkRedstoneInputChanged() } - override protected def onRedstoneInputChanged(side: ForgeDirection) { - super.onRedstoneInputChanged(side) - machine.node.sendToNeighbors("redstone.changed", toLocal(side)) + override protected def onRedstoneInputChanged(side: ForgeDirection, oldMaxValue: Int, newMaxValue: Int) { + super.onRedstoneInputChanged(side, oldMaxValue, newMaxValue) + machine.node.sendToNeighbors("redstone.changed", toLocal(side), int2Integer(oldMaxValue), int2Integer(newMaxValue)) } // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/RedstoneAware.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/RedstoneAware.scala index 8653b1b5e..e17cfaf0d 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/RedstoneAware.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/RedstoneAware.scala @@ -79,8 +79,8 @@ trait RedstoneAware extends RotationAware with IConnectable with IRedstoneEmitte val oldInput = _input(side.ordinal()) val newInput = computeInput(side) _input(side.ordinal()) = newInput - if (oldInput >= 0 && input(side) != oldInput) { - onRedstoneInputChanged(side) + if (oldInput >= 0 && newInput != oldInput) { + onRedstoneInputChanged(side, oldInput, newInput) } } @@ -140,7 +140,7 @@ trait RedstoneAware extends RotationAware with IConnectable with IRedstoneEmitte } } - protected def onRedstoneInputChanged(side: ForgeDirection) {} + protected def onRedstoneInputChanged(side: ForgeDirection, oldMaxValue: Int, newMaxValue: Int) {} protected def onRedstoneOutputEnabledChanged() { world.notifyBlocksOfNeighborChange(position, block) diff --git a/src/main/scala/li/cil/oc/server/component/RedstoneSignaller.scala b/src/main/scala/li/cil/oc/server/component/RedstoneSignaller.scala new file mode 100644 index 000000000..8ea7c31a4 --- /dev/null +++ b/src/main/scala/li/cil/oc/server/component/RedstoneSignaller.scala @@ -0,0 +1,12 @@ +package li.cil.oc.server.component + +import li.cil.oc.api.Persistable +import li.cil.oc.api.network.Node + +trait RedstoneSignaller extends Persistable { + def node: Node + + def onRedstoneChanged(side: AnyRef, oldMaxValue: AnyRef, newMaxValue: AnyRef): Unit = { + node.sendToReachable("computer.signal", "redstone_changed", side, oldMaxValue, newMaxValue) + } +} diff --git a/src/main/scala/li/cil/oc/server/component/RedstoneVanilla.scala b/src/main/scala/li/cil/oc/server/component/RedstoneVanilla.scala index aabcc2855..fd83cc951 100644 --- a/src/main/scala/li/cil/oc/server/component/RedstoneVanilla.scala +++ b/src/main/scala/li/cil/oc/server/component/RedstoneVanilla.scala @@ -7,12 +7,10 @@ import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context import li.cil.oc.api.network._ import li.cil.oc.api.prefab -import li.cil.oc.common.tileentity.traits.BundledRedstoneAware import li.cil.oc.common.tileentity.traits.RedstoneAware -import li.cil.oc.server.component import net.minecraftforge.common.util.ForgeDirection -trait RedstoneVanilla extends prefab.ManagedEnvironment { +trait RedstoneVanilla extends prefab.ManagedEnvironment with RedstoneSignaller { override val node = Network.newNode(this, Visibility.Network). withComponent("redstone", Visibility.Neighbors). create() @@ -47,7 +45,8 @@ trait RedstoneVanilla extends prefab.ManagedEnvironment { override def onMessage(message: Message): Unit = { super.onMessage(message) if (message.name == "redstone.changed") message.data match { - case Array(side: ForgeDirection) => node.sendToReachable("computer.signal", "redstone_changed", Int.box(side.ordinal())) + case Array(side: ForgeDirection, oldMaxValue: Number, newMaxValue: Number) => + onRedstoneChanged(int2Integer(side.ordinal()), oldMaxValue, newMaxValue) case _ => } } diff --git a/src/main/scala/li/cil/oc/server/component/RedstoneWireless.scala b/src/main/scala/li/cil/oc/server/component/RedstoneWireless.scala index 8b35769e9..dbcd54f2c 100644 --- a/src/main/scala/li/cil/oc/server/component/RedstoneWireless.scala +++ b/src/main/scala/li/cil/oc/server/component/RedstoneWireless.scala @@ -19,7 +19,7 @@ import net.minecraft.nbt.NBTTagCompound new Optional.Interface(iface = "codechicken.wirelessredstone.core.WirelessReceivingDevice", modid = Mods.IDs.WirelessRedstoneCBE), new Optional.Interface(iface = "codechicken.wirelessredstone.core.WirelessTransmittingDevice", modid = Mods.IDs.WirelessRedstoneCBE) )) -trait RedstoneWireless extends prefab.ManagedEnvironment with WirelessReceivingDevice with WirelessTransmittingDevice { +trait RedstoneWireless extends prefab.ManagedEnvironment with RedstoneSignaller with WirelessReceivingDevice with WirelessTransmittingDevice { def redstone: EnvironmentHost var wirelessFrequency = 0 @@ -77,7 +77,7 @@ trait RedstoneWireless extends prefab.ManagedEnvironment with WirelessReceivingD override def updateDevice(frequency: Int, on: Boolean) { if (frequency == wirelessFrequency && on != wirelessInput) { wirelessInput = on - node.sendToReachable("computer.signal", "redstone_changed", "wireless") + onRedstoneChanged("wireless", boolean2Boolean(!on), boolean2Boolean(on)) } }