mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-11 08:16:19 -04:00
Merge branch 'master' of https://github.com/MightyPirates/OpenComputers into MC1.7
Conflicts: src/main/scala/li/cil/oc/common/tileentity/WirelessRouter.scala src/main/scala/li/cil/oc/server/driver/CompoundBlockDriver.scala
This commit is contained in:
commit
5609bb4c93
@ -49,7 +49,7 @@ while term.isAvailable() do
|
|||||||
io.stderr:write(tostring(result[2]) .. "\n")
|
io.stderr:write(tostring(result[2]) .. "\n")
|
||||||
else
|
else
|
||||||
for i = 2, result.n do
|
for i = 2, result.n do
|
||||||
term.write(text.serialize(result[i], true) .. "\t")
|
term.write(text.serialize(result[i], true) .. "\t", true)
|
||||||
end
|
end
|
||||||
if term.getCursor() > 1 then
|
if term.getCursor() > 1 then
|
||||||
term.write("\n")
|
term.write("\n")
|
||||||
|
@ -2,14 +2,32 @@ package li.cil.oc.common.tileentity
|
|||||||
|
|
||||||
import li.cil.oc.api.network._
|
import li.cil.oc.api.network._
|
||||||
import li.cil.oc.server.component.NetworkCard.Packet
|
import li.cil.oc.server.component.NetworkCard.Packet
|
||||||
|
import li.cil.oc.util.ExtendedNBT._
|
||||||
import li.cil.oc.util.WirelessNetwork
|
import li.cil.oc.util.WirelessNetwork
|
||||||
import li.cil.oc.{api, Settings}
|
import li.cil.oc.{api, Settings}
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import net.minecraftforge.common.util.ForgeDirection
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
|
import scala.collection.convert.WrapAsScala._
|
||||||
|
import net.minecraftforge.common.util.Constants.NBT
|
||||||
|
|
||||||
class WirelessRouter extends Router with WirelessNetwork.Endpoint {
|
class WirelessRouter extends Router with WirelessNetwork.Endpoint {
|
||||||
var strength = Settings.get.maxWirelessRange
|
var strength = Settings.get.maxWirelessRange
|
||||||
|
|
||||||
|
val componentNodes = Array.fill(6)(api.Network.newNode(this, Visibility.Network).withComponent("access_point").create())
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
@Callback(direct = true, doc = """function():number -- Get the signal strength (range) used when relaying messages.""")
|
||||||
|
def getStrength(context: Context, args: Arguments): Array[AnyRef] = synchronized(result(strength))
|
||||||
|
|
||||||
|
@Callback(doc = """function(strength:number):number -- Set the signal strength (range) used when relaying messages.""")
|
||||||
|
def setStrength(context: Context, args: Arguments): Array[AnyRef] = synchronized {
|
||||||
|
strength = math.max(args.checkDouble(0), math.min(0, Settings.get.maxWirelessRange))
|
||||||
|
result(strength)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def owner = this
|
override def owner = this
|
||||||
|
|
||||||
override def receivePacket(packet: Packet, distance: Double) {
|
override def receivePacket(packet: Packet, distance: Double) {
|
||||||
@ -31,31 +49,47 @@ class WirelessRouter extends Router with WirelessNetwork.Endpoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override protected def createNode(plug: Plug) = api.Network.newNode(plug, Visibility.Network).withConnector().create()
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override protected def onPlugConnect(plug: Plug, node: Node) {
|
override protected def onPlugConnect(plug: Plug, node: Node) {
|
||||||
super.onPlugConnect(plug, node)
|
super.onPlugConnect(plug, node)
|
||||||
if (node == plug.node) {
|
if (node == plug.node) {
|
||||||
WirelessNetwork.add(this)
|
WirelessNetwork.add(this)
|
||||||
}
|
}
|
||||||
|
if (!node.network.nodes.exists(componentNodes.contains)) {
|
||||||
|
node.connect(componentNodes(plug.side.ordinal))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected def onPlugDisconnect(plug: Plug, node: Node) {
|
override protected def onPlugDisconnect(plug: Plug, node: Node) {
|
||||||
super.onPlugDisconnect(plug, node)
|
super.onPlugDisconnect(plug, node)
|
||||||
if (node == plug.node) {
|
if (node == plug.node) {
|
||||||
WirelessNetwork.remove(this)
|
WirelessNetwork.remove(this)
|
||||||
|
componentNodes(plug.side.ordinal).remove()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def readFromNBT(nbt: NBTTagCompound) = {
|
override def readFromNBT(nbt: NBTTagCompound) = {
|
||||||
super.readFromNBT(nbt)
|
super.readFromNBT(nbt)
|
||||||
if (nbt.hasKey("strength")) {
|
if (nbt.hasKey(Settings.namespace + "strength")) {
|
||||||
strength = nbt.getDouble("strength") max 0 min Settings.get.maxWirelessRange
|
strength = nbt.getDouble(Settings.namespace + "strength") max 0 min Settings.get.maxWirelessRange
|
||||||
|
}
|
||||||
|
nbt.getTagList(Settings.namespace + "componentNodes", NBT.TAG_COMPOUND).foreach {
|
||||||
|
case (list, index) => componentNodes(index).load(list.getCompoundTagAt(index))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def writeToNBT(nbt: NBTTagCompound) = {
|
override def writeToNBT(nbt: NBTTagCompound) = {
|
||||||
super.writeToNBT(nbt)
|
super.writeToNBT(nbt)
|
||||||
nbt.setDouble("strength", strength)
|
nbt.setDouble(Settings.namespace + "strength", strength)
|
||||||
|
nbt.setNewTagList(Settings.namespace + "componentNodes", componentNodes.map(node => {
|
||||||
|
val tag = new NBTTagCompound()
|
||||||
|
node.save(tag)
|
||||||
|
tag
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected def createNode(plug: Plug) = api.Network.newNode(plug, Visibility.Network).withConnector().create()
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class CompoundBlockDriver(val blocks: driver.Block*) extends driver.Block {
|
|||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
try world.getTileEntity(x, y, z) match {
|
try world.getTileEntity(x, y, z) match {
|
||||||
case inventory: IInventory => return inventory.getInventoryName.stripPrefix("container.")
|
case inventory: IInventory if !Strings.isNullOrEmpty(inventory.getInventoryName) => return inventory.getInventoryName.stripPrefix("container.")
|
||||||
} catch {
|
} catch {
|
||||||
case _: Throwable =>
|
case _: Throwable =>
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package li.cil.oc.server.fs
|
package li.cil.oc.server.fs
|
||||||
|
|
||||||
import java.io
|
import java.io
|
||||||
import java.io.{FileNotFoundException, RandomAccessFile, FileOutputStream}
|
import java.io.RandomAccessFile
|
||||||
import li.cil.oc.api.fs.Mode
|
import li.cil.oc.api.fs.Mode
|
||||||
|
|
||||||
trait FileOutputStreamFileSystem extends FileInputStreamFileSystem with OutputStreamFileSystem {
|
trait FileOutputStreamFileSystem extends FileInputStreamFileSystem with OutputStreamFileSystem {
|
||||||
@ -28,6 +28,8 @@ trait FileOutputStreamFileSystem extends FileInputStreamFileSystem with OutputSt
|
|||||||
}), this, id, path))
|
}), this, id, path))
|
||||||
|
|
||||||
protected class FileHandle(val file: RandomAccessFile, owner: OutputStreamFileSystem, handle: Int, path: String) extends OutputHandle(owner, handle, path) {
|
protected class FileHandle(val file: RandomAccessFile, owner: OutputStreamFileSystem, handle: Int, path: String) extends OutputHandle(owner, handle, path) {
|
||||||
|
override def position() = file.getFilePointer
|
||||||
|
|
||||||
override def length() = file.length()
|
override def length() = file.length()
|
||||||
|
|
||||||
override def close() {
|
override def close() {
|
||||||
@ -35,8 +37,6 @@ trait FileOutputStreamFileSystem extends FileInputStreamFileSystem with OutputSt
|
|||||||
file.close()
|
file.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
override def position() = file.getFilePointer
|
|
||||||
|
|
||||||
override def seek(to: Long) = {
|
override def seek(to: Long) = {
|
||||||
file.seek(to)
|
file.seek(to)
|
||||||
to
|
to
|
||||||
@ -44,4 +44,5 @@ trait FileOutputStreamFileSystem extends FileInputStreamFileSystem with OutputSt
|
|||||||
|
|
||||||
override def write(value: Array[Byte]) = file.write(value)
|
override def write(value: Array[Byte]) = file.write(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user