mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-08 06:41:23 -04:00
Make it possible to insert an Analyzer inside a tablet.
This makes it so that the tablet can accept the Analyzer, which makes it possible to "scan" the component type, and address of the component, making the data available as a table in the `tablet_use` event, under `analyzed`.
This commit is contained in:
parent
920e66bafd
commit
e0174b973f
@ -284,6 +284,7 @@ object Items extends ItemAPI {
|
||||
Option(safeGetStack(Constants.ItemName.PistonUpgrade)),
|
||||
Option(safeGetStack(Constants.BlockName.Geolyzer)),
|
||||
Option(safeGetStack(Constants.ItemName.NavigationUpgrade)),
|
||||
Option(safeGetStack(Constants.ItemName.Analyzer)),
|
||||
|
||||
Option(safeGetStack(Constants.ItemName.GraphicsCardTier2)),
|
||||
Option(safeGetStack(Constants.ItemName.RedstoneCardTier2)),
|
||||
|
@ -0,0 +1,27 @@
|
||||
package li.cil.oc.integration.opencomputers
|
||||
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.api.driver.EnvironmentProvider
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.driver.item.{HostAware, Slot}
|
||||
import li.cil.oc.api.network.{EnvironmentHost, ManagedEnvironment}
|
||||
import li.cil.oc.server.component
|
||||
import li.cil.oc.server.component.UpgradeBarcodeReader
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
object DriverUpgradeBarcodeReader extends Item with HostAware {
|
||||
override def worksWith(stack: ItemStack) = isOneOf(stack,
|
||||
api.Items.get(Constants.ItemName.Analyzer))
|
||||
|
||||
override def createEnvironment(stack: ItemStack, host: EnvironmentHost): ManagedEnvironment =
|
||||
new UpgradeBarcodeReader(host)
|
||||
|
||||
override def slot(stack: ItemStack) = Slot.Upgrade
|
||||
|
||||
object Provider extends EnvironmentProvider {
|
||||
override def getEnvironment(stack: ItemStack): Class[_] =
|
||||
if (worksWith(stack))
|
||||
classOf[component.UpgradeBarcodeReader]
|
||||
else null
|
||||
}
|
||||
}
|
@ -151,6 +151,7 @@ object ModOpenComputers extends ModProxy {
|
||||
api.Driver.add(DriverTerminalServer)
|
||||
|
||||
api.Driver.add(DriverUpgradeAngel)
|
||||
api.Driver.add(DriverUpgradeBarcodeReader)
|
||||
api.Driver.add(DriverUpgradeBattery)
|
||||
api.Driver.add(DriverUpgradeChunkloader)
|
||||
api.Driver.add(DriverUpgradeCrafting)
|
||||
@ -212,6 +213,7 @@ object ModOpenComputers extends ModProxy {
|
||||
Constants.BlockName.ScreenTier1,
|
||||
Constants.BlockName.Transposer,
|
||||
Constants.BlockName.CarpetedCapacitor,
|
||||
Constants.ItemName.Analyzer,
|
||||
Constants.ItemName.AngelUpgrade,
|
||||
Constants.ItemName.BatteryUpgradeTier1,
|
||||
Constants.ItemName.BatteryUpgradeTier2,
|
||||
@ -235,6 +237,7 @@ object ModOpenComputers extends ModProxy {
|
||||
Constants.BlockName.ScreenTier1,
|
||||
Constants.BlockName.Transposer,
|
||||
Constants.BlockName.CarpetedCapacitor,
|
||||
Constants.ItemName.Analyzer,
|
||||
Constants.ItemName.APUTier1,
|
||||
Constants.ItemName.APUTier2,
|
||||
Constants.ItemName.GraphicsCardTier1,
|
||||
@ -250,6 +253,7 @@ object ModOpenComputers extends ModProxy {
|
||||
Constants.BlockName.Keyboard,
|
||||
Constants.BlockName.ScreenTier1,
|
||||
Constants.BlockName.CarpetedCapacitor,
|
||||
Constants.ItemName.Analyzer,
|
||||
Constants.ItemName.APUTier1,
|
||||
Constants.ItemName.APUTier2,
|
||||
Constants.ItemName.GraphicsCardTier1,
|
||||
@ -275,6 +279,7 @@ object ModOpenComputers extends ModProxy {
|
||||
blacklistHost(classOf[internal.Robot],
|
||||
Constants.BlockName.Transposer,
|
||||
Constants.BlockName.CarpetedCapacitor,
|
||||
Constants.ItemName.Analyzer,
|
||||
Constants.ItemName.LeashUpgrade)
|
||||
blacklistHost(classOf[internal.Tablet],
|
||||
Constants.BlockName.ScreenTier1,
|
||||
|
@ -0,0 +1,77 @@
|
||||
package li.cil.oc.server.component
|
||||
|
||||
import java.util
|
||||
|
||||
import li.cil.oc.{Constants, OpenComputers, api}
|
||||
import li.cil.oc.api.driver.DeviceInfo
|
||||
import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute
|
||||
import li.cil.oc.api.driver.DeviceInfo.DeviceClass
|
||||
import li.cil.oc.api.internal
|
||||
import li.cil.oc.api.network._
|
||||
import li.cil.oc.api.prefab
|
||||
import li.cil.oc.util.BlockPosition
|
||||
import li.cil.oc.util.ExtendedWorld._
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.nbt.NBTTagList
|
||||
import net.minecraft.util.EnumFacing
|
||||
import net.minecraft.world.WorldServer
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
import scala.collection.convert.WrapAsJava._
|
||||
|
||||
class UpgradeBarcodeReader(val host: EnvironmentHost) extends prefab.ManagedEnvironment with DeviceInfo {
|
||||
override val node = api.Network.newNode(this, Visibility.Network).
|
||||
withComponent("barcode_reader").
|
||||
withConnector().
|
||||
create()
|
||||
|
||||
private final lazy val deviceInfo = Map(
|
||||
DeviceAttribute.Class -> DeviceClass.Generic,
|
||||
DeviceAttribute.Description -> "Barcode reader upgrade",
|
||||
DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor,
|
||||
DeviceAttribute.Product -> "Readerizer Deluxe"
|
||||
)
|
||||
|
||||
override def getDeviceInfo: util.Map[String, String] = deviceInfo
|
||||
|
||||
override def onMessage(message: Message): Unit = {
|
||||
super.onMessage(message)
|
||||
if (message.name == "tablet.use") message.source.host match {
|
||||
case machine: api.machine.Machine => (machine.host, message.data) match {
|
||||
case (tablet: internal.Tablet, Array(nbt: NBTTagCompound, stack: ItemStack, player: EntityPlayer, blockPos: BlockPosition, side: ForgeDirection, hitX: java.lang.Float, hitY: java.lang.Float, hitZ: java.lang.Float)) =>
|
||||
host.world.getTileEntity(blockPos) match {
|
||||
case analyzable: Analyzable =>
|
||||
processNodes(analyzable.onAnalyze(player, side.ordinal(), hitX.toFloat, hitY.toFloat, hitZ.toFloat), nbt)
|
||||
case host: SidedEnvironment =>
|
||||
processNodes(Array(host.sidedNode(side)), nbt)
|
||||
case host: Environment =>
|
||||
processNodes(Array(host.node), nbt)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def processNodes(nodes: Array[Node], nbt: NBTTagCompound): Unit = if (nodes != null) {
|
||||
val readerNBT = new NBTTagList()
|
||||
|
||||
for (node <- nodes if node != null) {
|
||||
val nodeNBT = new NBTTagCompound()
|
||||
node match {
|
||||
case component: Component =>
|
||||
nodeNBT.setString("type", component.name)
|
||||
case _ =>
|
||||
}
|
||||
|
||||
val address = node.address()
|
||||
if (address != null && !address.isEmpty) {
|
||||
nodeNBT.setString("address", node.address())
|
||||
}
|
||||
|
||||
readerNBT.appendTag(nodeNBT)
|
||||
}
|
||||
|
||||
nbt.setTag("analyzed", readerNBT)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user