Yet more redstone refactoring, also passing along old and new max signal values for convenience.

This commit is contained in:
Florian Nücke 2015-01-15 19:16:22 +01:00
parent 0db6028ecd
commit 42d5d997a3
10 changed files with 51 additions and 33 deletions

View File

@ -173,7 +173,7 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
private def drawNEIHighlights(): Unit = { private def drawNEIHighlights(): Unit = {
val panel = LayoutManager.itemPanel val panel = LayoutManager.itemPanel
if (panel == null) return if (panel == null) return
zLevel += 500 zLevel += 350
for (index <- 0 until ItemPanel.items.size()) { for (index <- 0 until ItemPanel.items.size()) {
val rect = panel.getSlotRect(index) val rect = panel.getSlotRect(index)
val slot = panel.getSlotMouseOver(rect.x, rect.y) val slot = panel.getSlotMouseOver(rect.x, rect.y)
@ -188,6 +188,6 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
case _ => case _ =>
} }
} }
zLevel -= 500 zLevel -= 350
} }
} }

View File

@ -1,6 +1,7 @@
package li.cil.oc.common.tileentity package li.cil.oc.common.tileentity
import li.cil.oc.Settings import li.cil.oc.Settings
import li.cil.oc.api
import li.cil.oc.api.network.Visibility import li.cil.oc.api.network.Visibility
import li.cil.oc.common.tileentity.traits.BundledRedstoneAware import li.cil.oc.common.tileentity.traits.BundledRedstoneAware
import li.cil.oc.common.tileentity.traits.Environment import li.cil.oc.common.tileentity.traits.Environment
@ -17,10 +18,12 @@ class Redstone extends Environment with BundledRedstoneAware {
else else
new component.Redstone.Vanilla(this) new component.Redstone.Vanilla(this)
val node = instance.node val node = instance.node
if (node != null) { val dummyNode = if (node != null) {
node.setVisibility(Visibility.Network) node.setVisibility(Visibility.Network)
_isOutputEnabled = true _isOutputEnabled = true
api.Network.newNode(this, Visibility.None).create()
} }
else null
override def canUpdate = isServer override def canUpdate = isServer
@ -38,8 +41,9 @@ class Redstone extends Environment with BundledRedstoneAware {
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //
override protected def onRedstoneInputChanged(side: ForgeDirection) { override protected def onRedstoneInputChanged(side: ForgeDirection, oldMaxValue: Int, newMaxValue: Int) {
super.onRedstoneInputChanged(side) super.onRedstoneInputChanged(side, oldMaxValue, newMaxValue)
node.sendToReachable("computer.signal", "redstone_changed", Int.box(side.ordinal())) node.connect(dummyNode)
dummyNode.sendToNeighbors("redstone.changed", side, int2Integer(oldMaxValue), int2Integer(newMaxValue))
} }
} }

View File

@ -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 def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float) = Array(origin.node)
override protected def onRedstoneInputChanged(side: ForgeDirection) { override protected def onRedstoneInputChanged(side: ForgeDirection, oldMaxValue: Int, newMaxValue: Int) {
super.onRedstoneInputChanged(side) super.onRedstoneInputChanged(side, oldMaxValue, newMaxValue)
val hasRedstoneInput = screens.map(_.maxInput).max > 0 val hasRedstoneInput = screens.map(_.maxInput).max > 0
if (hasRedstoneInput != hadRedstoneInput) { if (hasRedstoneInput != hadRedstoneInput) {
hadRedstoneInput = hasRedstoneInput hadRedstoneInput = hasRedstoneInput

View File

@ -506,10 +506,10 @@ class ServerRack extends traits.PowerAcceptor with traits.Hub with traits.PowerB
checkRedstoneInputChanged() checkRedstoneInputChanged()
} }
override protected def onRedstoneInputChanged(side: ForgeDirection) { override protected def onRedstoneInputChanged(side: ForgeDirection, oldMaxValue: Int, newMaxValue: Int) {
super.onRedstoneInputChanged(side) super.onRedstoneInputChanged(side, oldMaxValue, newMaxValue)
servers collect { 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))
} }
} }

View File

@ -48,13 +48,15 @@ trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBund
def bundledInput(side: ForgeDirection, color: Int) = def bundledInput(side: ForgeDirection, color: Int) =
math.max(_bundledInput(side.ordinal())(color), _rednetInput(side.ordinal())(color)) math.max(_bundledInput(side.ordinal())(color), _rednetInput(side.ordinal())(color))
def rednetInput(side: ForgeDirection, color: Int, value: Int) = def rednetInput(side: ForgeDirection, color: Int, value: Int): Unit = {
if (_rednetInput(side.ordinal())(color) != value) { val oldValue = _rednetInput(side.ordinal())(color)
if (_rednetInput(side.ordinal())(color) != -1) { if (oldValue != value) {
onRedstoneInputChanged(side) if (oldValue != -1) {
onRedstoneInputChanged(side, oldValue, value)
} }
_rednetInput(side.ordinal())(color) = value _rednetInput(side.ordinal())(color) = value
} }
}
def bundledOutput(side: ForgeDirection) = _bundledOutput(toLocal(side).ordinal()) 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) { override protected def updateRedstoneInput(side: ForgeDirection) {
super.updateRedstoneInput(side) super.updateRedstoneInput(side)
val oldBundledInput = _bundledInput(side.ordinal()) val ownBundledInput = _bundledInput(side.ordinal())
val newBundledInput = computeBundledInput(side) val newBundledInput = computeBundledInput(side)
val oldMaxValue = ownBundledInput.max
var changed = false var changed = false
if (newBundledInput != null) for (color <- 0 until 16) { if (newBundledInput != null) for (color <- 0 until 16) {
changed = changed || (oldBundledInput(color) >= 0 && oldBundledInput(color) != newBundledInput(color)) changed = changed || (ownBundledInput(color) >= 0 && ownBundledInput(color) != newBundledInput(color))
oldBundledInput(color) = newBundledInput(color) ownBundledInput(color) = newBundledInput(color)
} }
else for (color <- 0 until 16) { else for (color <- 0 until 16) {
changed = changed || oldBundledInput(color) > 0 changed = changed || ownBundledInput(color) > 0
oldBundledInput(color) = 0 ownBundledInput(color) = 0
} }
if (changed) { if (changed) {
onRedstoneInputChanged(side) onRedstoneInputChanged(side, oldMaxValue, ownBundledInput.max)
} }
} }

View File

@ -204,9 +204,9 @@ trait Computer extends Environment with ComponentInventory with Rotatable with B
checkRedstoneInputChanged() checkRedstoneInputChanged()
} }
override protected def onRedstoneInputChanged(side: ForgeDirection) { override protected def onRedstoneInputChanged(side: ForgeDirection, oldMaxValue: Int, newMaxValue: Int) {
super.onRedstoneInputChanged(side) super.onRedstoneInputChanged(side, oldMaxValue, newMaxValue)
machine.node.sendToNeighbors("redstone.changed", toLocal(side)) machine.node.sendToNeighbors("redstone.changed", toLocal(side), int2Integer(oldMaxValue), int2Integer(newMaxValue))
} }
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //

View File

@ -79,8 +79,8 @@ trait RedstoneAware extends RotationAware with IConnectable with IRedstoneEmitte
val oldInput = _input(side.ordinal()) val oldInput = _input(side.ordinal())
val newInput = computeInput(side) val newInput = computeInput(side)
_input(side.ordinal()) = newInput _input(side.ordinal()) = newInput
if (oldInput >= 0 && input(side) != oldInput) { if (oldInput >= 0 && newInput != oldInput) {
onRedstoneInputChanged(side) 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() { protected def onRedstoneOutputEnabledChanged() {
world.notifyBlocksOfNeighborChange(position, block) world.notifyBlocksOfNeighborChange(position, block)

View File

@ -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)
}
}

View File

@ -7,12 +7,10 @@ import li.cil.oc.api.machine.Callback
import li.cil.oc.api.machine.Context import li.cil.oc.api.machine.Context
import li.cil.oc.api.network._ import li.cil.oc.api.network._
import li.cil.oc.api.prefab 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.common.tileentity.traits.RedstoneAware
import li.cil.oc.server.component
import net.minecraftforge.common.util.ForgeDirection 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). override val node = Network.newNode(this, Visibility.Network).
withComponent("redstone", Visibility.Neighbors). withComponent("redstone", Visibility.Neighbors).
create() create()
@ -47,7 +45,8 @@ trait RedstoneVanilla extends prefab.ManagedEnvironment {
override def onMessage(message: Message): Unit = { override def onMessage(message: Message): Unit = {
super.onMessage(message) super.onMessage(message)
if (message.name == "redstone.changed") message.data match { 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 _ => case _ =>
} }
} }

View File

@ -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.WirelessReceivingDevice", modid = Mods.IDs.WirelessRedstoneCBE),
new Optional.Interface(iface = "codechicken.wirelessredstone.core.WirelessTransmittingDevice", 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 def redstone: EnvironmentHost
var wirelessFrequency = 0 var wirelessFrequency = 0
@ -77,7 +77,7 @@ trait RedstoneWireless extends prefab.ManagedEnvironment with WirelessReceivingD
override def updateDevice(frequency: Int, on: Boolean) { override def updateDevice(frequency: Int, on: Boolean) {
if (frequency == wirelessFrequency && on != wirelessInput) { if (frequency == wirelessFrequency && on != wirelessInput) {
wirelessInput = on wirelessInput = on
node.sendToReachable("computer.signal", "redstone_changed", "wireless") onRedstoneChanged("wireless", boolean2Boolean(!on), boolean2Boolean(on))
} }
} }