mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 17:56:34 -04:00
Added redstone.get/setWakeThreshold
, allows setting a redstone signal threshold that, when crossed from low to high causes connect computers to start.
This commit is contained in:
parent
42d5d997a3
commit
f981a05c0f
@ -1,12 +1,44 @@
|
|||||||
package li.cil.oc.server.component
|
package li.cil.oc.server.component
|
||||||
|
|
||||||
import li.cil.oc.api.Persistable
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.api.network.Node
|
import li.cil.oc.api.machine.Arguments
|
||||||
|
import li.cil.oc.api.machine.Callback
|
||||||
|
import li.cil.oc.api.machine.Context
|
||||||
|
import li.cil.oc.api.prefab
|
||||||
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
|
|
||||||
trait RedstoneSignaller extends Persistable {
|
trait RedstoneSignaller extends prefab.ManagedEnvironment {
|
||||||
def node: Node
|
var wakeThreshold = 0
|
||||||
|
|
||||||
def onRedstoneChanged(side: AnyRef, oldMaxValue: AnyRef, newMaxValue: AnyRef): Unit = {
|
// ----------------------------------------------------------------------- //
|
||||||
node.sendToReachable("computer.signal", "redstone_changed", side, oldMaxValue, newMaxValue)
|
|
||||||
|
@Callback(direct = true, doc = """function():number -- Get the current wake-up threshold.""")
|
||||||
|
def getWakeThreshold(context: Context, args: Arguments): Array[AnyRef] = result(wakeThreshold)
|
||||||
|
|
||||||
|
@Callback(doc = """function(threshold:number) -- Set the wake-up threshold.""")
|
||||||
|
def setWakeThreshold(context: Context, args: Arguments): Array[AnyRef] = {
|
||||||
|
wakeThreshold = args.checkInteger(0)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
def onRedstoneChanged(side: AnyRef, oldMaxValue: Int, newMaxValue: Int): Unit = {
|
||||||
|
node.sendToReachable("computer.signal", "redstone_changed", side, int2Integer(oldMaxValue), int2Integer(newMaxValue))
|
||||||
|
if (oldMaxValue < wakeThreshold && newMaxValue >= wakeThreshold) {
|
||||||
|
node.sendToNeighbors("computer.start")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
override def load(nbt: NBTTagCompound): Unit = {
|
||||||
|
super.load(nbt)
|
||||||
|
wakeThreshold = nbt.getInteger(Settings.namespace + "wakeThreshold")
|
||||||
|
}
|
||||||
|
|
||||||
|
override def save(nbt: NBTTagCompound): Unit = {
|
||||||
|
super.save(nbt)
|
||||||
|
nbt.setInteger(Settings.namespace + "wakeThreshold", wakeThreshold)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,10 @@ import li.cil.oc.api.machine.Arguments
|
|||||||
import li.cil.oc.api.machine.Callback
|
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.common.tileentity.traits.RedstoneAware
|
import li.cil.oc.common.tileentity.traits.RedstoneAware
|
||||||
import net.minecraftforge.common.util.ForgeDirection
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
|
|
||||||
trait RedstoneVanilla extends prefab.ManagedEnvironment with RedstoneSignaller {
|
trait RedstoneVanilla extends 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()
|
||||||
@ -46,7 +45,7 @@ trait RedstoneVanilla extends prefab.ManagedEnvironment with RedstoneSignaller {
|
|||||||
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, oldMaxValue: Number, newMaxValue: Number) =>
|
case Array(side: ForgeDirection, oldMaxValue: Number, newMaxValue: Number) =>
|
||||||
onRedstoneChanged(int2Integer(side.ordinal()), oldMaxValue, newMaxValue)
|
onRedstoneChanged(int2Integer(side.ordinal()), oldMaxValue.intValue(), newMaxValue.intValue())
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import li.cil.oc.api.machine.Arguments
|
|||||||
import li.cil.oc.api.machine.Callback
|
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.common.EventHandler
|
import li.cil.oc.common.EventHandler
|
||||||
import li.cil.oc.integration.Mods
|
import li.cil.oc.integration.Mods
|
||||||
import li.cil.oc.integration.util
|
import li.cil.oc.integration.util
|
||||||
@ -19,7 +18,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 RedstoneSignaller with WirelessReceivingDevice with WirelessTransmittingDevice {
|
trait RedstoneWireless extends RedstoneSignaller with WirelessReceivingDevice with WirelessTransmittingDevice {
|
||||||
def redstone: EnvironmentHost
|
def redstone: EnvironmentHost
|
||||||
|
|
||||||
var wirelessFrequency = 0
|
var wirelessFrequency = 0
|
||||||
@ -77,7 +76,7 @@ trait RedstoneWireless extends prefab.ManagedEnvironment with RedstoneSignaller
|
|||||||
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
|
||||||
onRedstoneChanged("wireless", boolean2Boolean(!on), boolean2Boolean(on))
|
onRedstoneChanged("wireless", if (on) 0 else 1, if (on) 1 else 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
|
|||||||
|
|
||||||
override def getBootAddress = bootAddress
|
override def getBootAddress = bootAddress
|
||||||
|
|
||||||
override def setBootAddress(value: String) = bootAddress = Option(value).map(_.take(36)).getOrElse("")
|
override def setBootAddress(value: String) = bootAddress = Option(value).fold("")(_.take(36))
|
||||||
|
|
||||||
override def components = scala.collection.convert.WrapAsJava.mapAsJavaMap(_components)
|
override def components = scala.collection.convert.WrapAsJava.mapAsJavaMap(_components)
|
||||||
|
|
||||||
@ -490,6 +490,8 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
|
|||||||
if (canInteract(player.getCommandSenderName))
|
if (canInteract(player.getCommandSenderName))
|
||||||
signal(name, Seq(message.source.address) ++ args: _*)
|
signal(name, Seq(message.source.address) ++ args: _*)
|
||||||
case _ =>
|
case _ =>
|
||||||
|
if (message.name == "computer.start" && !isPaused) start()
|
||||||
|
else if (message.name == "computer.stop") stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user