Merge branch 'master-MC1.8.9' of github.com:MightyPirates/OpenComputers into master-MC1.9.4

This commit is contained in:
Florian Nücke 2016-06-05 11:05:49 +02:00
commit 296795e15f
7 changed files with 26 additions and 9 deletions

View File

@ -7,6 +7,11 @@ import java.util.Map;
* expose some (typically static) information about the device represented by
* that environment to a {@link li.cil.oc.api.Machine} connected to it.
* <p/>
* You may also implement this on a {@link li.cil.oc.api.machine.MachineHost}
* in which case the <code>Machine</code> will forward that information as
* its own (since <code>MachineHost</code>s usually use the machine's node as
* their own, this avoids a dummy environment used solely for device info).
* <p/>
* This is intended to permit programs to reflect on the hardware they are
* running on, typically for purely informational purposes, but possibly to
* toggle certain hardware specific features.
@ -30,7 +35,11 @@ public interface DeviceInfo {
* <p/>
* For example, OC's tier one memory module returns the following:
* <table>
* <tr></tr>
* <tr><td>class</td><td>memory</td></tr>
* <tr><td>description</td><td>Memory bank</td></tr>
* <tr><td>vendor</td><td>MightyPirates GmbH & Co. KG</td></tr>
* <tr><td>product</td><td>Multipurpose RAM Type</td></tr>
* <tr><td>clock</td><td>500</td></tr>
* </table>
*
* @return the table of information on this device, or <code>null</code>.

View File

@ -41,7 +41,7 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
DeviceAttribute.Class -> DeviceClass.Display,
DeviceAttribute.Description -> "Holographic projector",
DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor,
DeviceAttribute.Product -> ("VirtualViewer H1-" + tier.toString),
DeviceAttribute.Product -> ("VirtualViewer H1-" + (tier + 1).toString),
DeviceAttribute.Capacity -> (width * width * height).toString,
DeviceAttribute.Width -> colors.length.toString
)

View File

@ -14,7 +14,7 @@ class APU(tier: Int) extends GraphicsCard(tier) {
DeviceAttribute.Class -> DeviceClass.Processor,
DeviceAttribute.Description -> "APU",
DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor,
DeviceAttribute.Product -> ("FlexiArch " + tier.toString + " Processor (Builtin Graphics)"),
DeviceAttribute.Product -> ("FlexiArch " + (tier + 1).toString + " Processor (Builtin Graphics)"),
DeviceAttribute.Capacity -> capacityInfo,
DeviceAttribute.Width -> widthInfo,
DeviceAttribute.Clock -> ((Settings.get.callBudgets(tier) * 1000).toInt.toString + "+" + clockInfo)

View File

@ -14,14 +14,14 @@ import li.cil.oc.api.prefab
import scala.collection.convert.WrapAsJava._
class CPU(val tier: Int) extends prefab.ManagedEnvironment with DeviceInfo {
override val node = Network.newNode(this, Visibility.Network).
override val node = Network.newNode(this, Visibility.Neighbors).
create()
private final lazy val deviceInfo = Map(
DeviceAttribute.Class -> DeviceClass.Processor,
DeviceAttribute.Description -> "CPU",
DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor,
DeviceAttribute.Product -> ("FlexiArch " + tier.toString + " Processor"),
DeviceAttribute.Product -> ("FlexiArch " + (tier + 1).toString + " Processor"),
DeviceAttribute.Clock -> (Settings.get.callBudgets(tier) * 1000).toInt.toString
)

View File

@ -65,7 +65,7 @@ class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment with DeviceI
DeviceAttribute.Class -> DeviceClass.Display,
DeviceAttribute.Description -> "Graphics controller",
DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor,
DeviceAttribute.Product -> ("MPG" + (tier * 1000).toString + " GTZ"),
DeviceAttribute.Product -> ("MPG" + ((tier + 1) * 1000).toString + " GTZ"),
DeviceAttribute.Capacity -> capacityInfo,
DeviceAttribute.Width -> widthInfo,
DeviceAttribute.Clock -> clockInfo

View File

@ -14,7 +14,7 @@ import li.cil.oc.api.prefab
import scala.collection.convert.WrapAsJava._
class Memory(val tier: Int) extends prefab.ManagedEnvironment with DeviceInfo {
override val node = Network.newNode(this, Visibility.Network).
override val node = Network.newNode(this, Visibility.Neighbors).
create()
private final lazy val deviceInfo = Map(

View File

@ -1,5 +1,6 @@
package li.cil.oc.server.machine
import java.util
import java.util.concurrent.TimeUnit
import li.cil.oc.OpenComputers
@ -47,7 +48,7 @@ import scala.collection.convert.WrapAsJava._
import scala.collection.convert.WrapAsScala._
import scala.collection.mutable
class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with machine.Machine with Runnable {
class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with machine.Machine with Runnable with DeviceInfo {
override val node = Network.newNode(this, Visibility.Network).
withComponent("computer", Visibility.Neighbors).
withConnector(Settings.get.bufferComputer).
@ -178,6 +179,13 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
// ----------------------------------------------------------------------- //
override def getDeviceInfo: util.Map[String, String] = host match {
case deviceInfo: DeviceInfo => deviceInfo.getDeviceInfo
case _ => null
}
// ----------------------------------------------------------------------- //
override def canInteract(player: String) = !Settings.get.canComputersBeOwned ||
_users.synchronized(_users.isEmpty || _users.contains(player)) ||
FMLCommonHandler.instance.getMinecraftServerInstance.isSinglePlayer || {
@ -426,7 +434,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
context.pause(1) // Iterating all nodes is potentially expensive, and I see no practical reason for having to call this frequently.
Array[AnyRef](node.network.nodes.map(n => (n, n.host)).collect {
case (n: Component, deviceInfo: DeviceInfo) =>
if (n.canBeSeenFrom(node)) {
if (n.canBeSeenFrom(node) || n == node) {
Option(deviceInfo.getDeviceInfo) match {
case Some(info) => Option(n.address -> info)
case _ => None