mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-08-03 19:17:27 -04:00
Merge branch 'master-MC1.7.10' into master-MC1.10
This commit is contained in:
commit
2c61578a1a
@ -6,10 +6,11 @@ local internet = {}
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
function internet.request(url, data, headers)
|
function internet.request(url, data, headers, method)
|
||||||
checkArg(1, url, "string")
|
checkArg(1, url, "string")
|
||||||
checkArg(2, data, "string", "table", "nil")
|
checkArg(2, data, "string", "table", "nil")
|
||||||
checkArg(3, headers, "table", "nil")
|
checkArg(3, headers, "table", "nil")
|
||||||
|
checkArg(4, method, "string", "nil")
|
||||||
|
|
||||||
if not component.isAvailable("internet") then
|
if not component.isAvailable("internet") then
|
||||||
error("no primary internet card found", 2)
|
error("no primary internet card found", 2)
|
||||||
@ -26,7 +27,7 @@ function internet.request(url, data, headers)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local request, reason = inet.request(url, post, headers)
|
local request, reason = inet.request(url, post, headers, method)
|
||||||
if not request then
|
if not request then
|
||||||
error(reason, 2)
|
error(reason, 2)
|
||||||
end
|
end
|
||||||
|
@ -80,6 +80,7 @@ Kodos # Contributor
|
|||||||
Laire # Perry Rhodan
|
Laire # Perry Rhodan
|
||||||
Loader 1340 # Borderlands 2
|
Loader 1340 # Borderlands 2
|
||||||
LordFokas # Contributor
|
LordFokas # Contributor
|
||||||
|
Maria # Metropolis
|
||||||
Marvin # Hitchhiker's Guide to the Galaxy
|
Marvin # Hitchhiker's Guide to the Galaxy
|
||||||
Mawhrin-skel # The Player of Games (Iain M Banks)
|
Mawhrin-skel # The Player of Games (Iain M Banks)
|
||||||
Michiyo # Contributor
|
Michiyo # Contributor
|
||||||
|
@ -299,6 +299,7 @@ object Items extends ItemAPI {
|
|||||||
Option(safeGetStack(Constants.ItemName.PistonUpgrade)),
|
Option(safeGetStack(Constants.ItemName.PistonUpgrade)),
|
||||||
Option(safeGetStack(Constants.BlockName.Geolyzer)),
|
Option(safeGetStack(Constants.BlockName.Geolyzer)),
|
||||||
Option(safeGetStack(Constants.ItemName.NavigationUpgrade)),
|
Option(safeGetStack(Constants.ItemName.NavigationUpgrade)),
|
||||||
|
Option(safeGetStack(Constants.ItemName.Analyzer)),
|
||||||
|
|
||||||
Option(safeGetStack(Constants.ItemName.GraphicsCardTier2)),
|
Option(safeGetStack(Constants.ItemName.GraphicsCardTier2)),
|
||||||
Option(safeGetStack(Constants.ItemName.RedstoneCardTier2)),
|
Option(safeGetStack(Constants.ItemName.RedstoneCardTier2)),
|
||||||
|
@ -62,11 +62,14 @@ trait NetworkControl[AETile >: Null <: TileEntity with IActionHost] {
|
|||||||
private def allCraftables: Iterable[IAEItemStack] = allItems.collect{ case aeItem if aeItem.isCraftable => aeCraftItem(aeItem) }
|
private def allCraftables: Iterable[IAEItemStack] = allItems.collect{ case aeItem if aeItem.isCraftable => aeCraftItem(aeItem) }
|
||||||
|
|
||||||
private def convert(aeItem: IAEItemStack): java.util.HashMap[String, AnyRef] = {
|
private def convert(aeItem: IAEItemStack): java.util.HashMap[String, AnyRef] = {
|
||||||
case class StringAnyRefHash (value: java.util.HashMap[String, AnyRef])
|
def hashConvert(value: java.util.HashMap[_, _]) = {
|
||||||
|
val hash = new java.util.HashMap[String, AnyRef]
|
||||||
|
value.collect{ case (k:String, v:AnyRef) => hash += k -> v }
|
||||||
|
hash
|
||||||
|
}
|
||||||
val potentialItem = aePotentialItem(aeItem)
|
val potentialItem = aePotentialItem(aeItem)
|
||||||
val result = Registry
|
val result = Registry.convert(Array[AnyRef](potentialItem.getItemStack))
|
||||||
.convert(Array[AnyRef](potentialItem.getItemStack))
|
.collect { case hash: java.util.HashMap[_,_] => hashConvert(hash) }
|
||||||
.collect { case StringAnyRefHash(hash) => hash }
|
|
||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
val hash = result(0)
|
val hash = result(0)
|
||||||
// it would have been nice to put these fields in a registry convert
|
// it would have been nice to put these fields in a registry convert
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -154,6 +154,7 @@ object ModOpenComputers extends ModProxy {
|
|||||||
api.Driver.add(DriverTerminalServer)
|
api.Driver.add(DriverTerminalServer)
|
||||||
|
|
||||||
api.Driver.add(DriverUpgradeAngel)
|
api.Driver.add(DriverUpgradeAngel)
|
||||||
|
api.Driver.add(DriverUpgradeBarcodeReader)
|
||||||
api.Driver.add(DriverUpgradeBattery)
|
api.Driver.add(DriverUpgradeBattery)
|
||||||
api.Driver.add(DriverUpgradeChunkloader)
|
api.Driver.add(DriverUpgradeChunkloader)
|
||||||
api.Driver.add(DriverUpgradeCrafting)
|
api.Driver.add(DriverUpgradeCrafting)
|
||||||
@ -215,6 +216,7 @@ object ModOpenComputers extends ModProxy {
|
|||||||
Constants.BlockName.ScreenTier1,
|
Constants.BlockName.ScreenTier1,
|
||||||
Constants.BlockName.Transposer,
|
Constants.BlockName.Transposer,
|
||||||
Constants.BlockName.CarpetedCapacitor,
|
Constants.BlockName.CarpetedCapacitor,
|
||||||
|
Constants.ItemName.Analyzer,
|
||||||
Constants.ItemName.AngelUpgrade,
|
Constants.ItemName.AngelUpgrade,
|
||||||
Constants.ItemName.BatteryUpgradeTier1,
|
Constants.ItemName.BatteryUpgradeTier1,
|
||||||
Constants.ItemName.BatteryUpgradeTier2,
|
Constants.ItemName.BatteryUpgradeTier2,
|
||||||
@ -238,6 +240,7 @@ object ModOpenComputers extends ModProxy {
|
|||||||
Constants.BlockName.ScreenTier1,
|
Constants.BlockName.ScreenTier1,
|
||||||
Constants.BlockName.Transposer,
|
Constants.BlockName.Transposer,
|
||||||
Constants.BlockName.CarpetedCapacitor,
|
Constants.BlockName.CarpetedCapacitor,
|
||||||
|
Constants.ItemName.Analyzer,
|
||||||
Constants.ItemName.APUTier1,
|
Constants.ItemName.APUTier1,
|
||||||
Constants.ItemName.APUTier2,
|
Constants.ItemName.APUTier2,
|
||||||
Constants.ItemName.GraphicsCardTier1,
|
Constants.ItemName.GraphicsCardTier1,
|
||||||
@ -253,6 +256,7 @@ object ModOpenComputers extends ModProxy {
|
|||||||
Constants.BlockName.Keyboard,
|
Constants.BlockName.Keyboard,
|
||||||
Constants.BlockName.ScreenTier1,
|
Constants.BlockName.ScreenTier1,
|
||||||
Constants.BlockName.CarpetedCapacitor,
|
Constants.BlockName.CarpetedCapacitor,
|
||||||
|
Constants.ItemName.Analyzer,
|
||||||
Constants.ItemName.APUTier1,
|
Constants.ItemName.APUTier1,
|
||||||
Constants.ItemName.APUTier2,
|
Constants.ItemName.APUTier2,
|
||||||
Constants.ItemName.GraphicsCardTier1,
|
Constants.ItemName.GraphicsCardTier1,
|
||||||
@ -278,6 +282,7 @@ object ModOpenComputers extends ModProxy {
|
|||||||
blacklistHost(classOf[internal.Robot],
|
blacklistHost(classOf[internal.Robot],
|
||||||
Constants.BlockName.Transposer,
|
Constants.BlockName.Transposer,
|
||||||
Constants.BlockName.CarpetedCapacitor,
|
Constants.BlockName.CarpetedCapacitor,
|
||||||
|
Constants.ItemName.Analyzer,
|
||||||
Constants.ItemName.LeashUpgrade)
|
Constants.ItemName.LeashUpgrade)
|
||||||
blacklistHost(classOf[internal.Tablet],
|
blacklistHost(classOf[internal.Tablet],
|
||||||
Constants.BlockName.ScreenTier1,
|
Constants.BlockName.ScreenTier1,
|
||||||
|
@ -62,7 +62,7 @@ class InternetCard extends prefab.ManagedEnvironment with DeviceInfo {
|
|||||||
@Callback(direct = true, doc = """function():boolean -- Returns whether HTTP requests can be made (config setting).""")
|
@Callback(direct = true, doc = """function():boolean -- Returns whether HTTP requests can be made (config setting).""")
|
||||||
def isHttpEnabled(context: Context, args: Arguments): Array[AnyRef] = result(Settings.get.httpEnabled)
|
def isHttpEnabled(context: Context, args: Arguments): Array[AnyRef] = result(Settings.get.httpEnabled)
|
||||||
|
|
||||||
@Callback(doc = """function(url:string[, postData:string[, headers:table]]):userdata -- Starts an HTTP request. If this returns true, further results will be pushed using `http_response` signals.""")
|
@Callback(doc = """function(url:string[, postData:string[, headers:table[, method:string]]]):userdata -- Starts an HTTP request. If this returns true, further results will be pushed using `http_response` signals.""")
|
||||||
def request(context: Context, args: Arguments): Array[AnyRef] = this.synchronized {
|
def request(context: Context, args: Arguments): Array[AnyRef] = this.synchronized {
|
||||||
checkOwner(context)
|
checkOwner(context)
|
||||||
val address = args.checkString(0)
|
val address = args.checkString(0)
|
||||||
@ -80,7 +80,8 @@ class InternetCard extends prefab.ManagedEnvironment with DeviceInfo {
|
|||||||
if (!Settings.get.httpHeadersEnabled && headers.nonEmpty) {
|
if (!Settings.get.httpHeadersEnabled && headers.nonEmpty) {
|
||||||
return result(Unit, "http request headers are unavailable")
|
return result(Unit, "http request headers are unavailable")
|
||||||
}
|
}
|
||||||
val request = new InternetCard.HTTPRequest(this, checkAddress(address), post, headers)
|
val method = if (args.isString(3)) Option(args.checkString(3)) else None
|
||||||
|
val request = new InternetCard.HTTPRequest(this, checkAddress(address), post, headers, method)
|
||||||
connections += request
|
connections += request
|
||||||
result(request)
|
result(request)
|
||||||
}
|
}
|
||||||
@ -366,10 +367,10 @@ object InternetCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class HTTPRequest extends AbstractValue with Closable {
|
class HTTPRequest extends AbstractValue with Closable {
|
||||||
def this(owner: InternetCard, url: URL, post: Option[String], headers: Map[String, String]) {
|
def this(owner: InternetCard, url: URL, post: Option[String], headers: Map[String, String], method: Option[String]) {
|
||||||
this()
|
this()
|
||||||
this.owner = Some(owner)
|
this.owner = Some(owner)
|
||||||
this.stream = threadPool.submit(new RequestSender(url, post, headers))
|
this.stream = threadPool.submit(new RequestSender(url, post, headers, method))
|
||||||
}
|
}
|
||||||
|
|
||||||
private var owner: Option[InternetCard] = None
|
private var owner: Option[InternetCard] = None
|
||||||
@ -468,27 +469,23 @@ object InternetCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This one doesn't (see comment in TCP socket), but I like to keep it consistent.
|
// This one doesn't (see comment in TCP socket), but I like to keep it consistent.
|
||||||
private class RequestSender(val url: URL, val post: Option[String], val headers: Map[String, String]) extends Callable[InputStream] {
|
private class RequestSender(val url: URL, val post: Option[String], val headers: Map[String, String], val method: Option[String]) extends Callable[InputStream] {
|
||||||
override def call() = try {
|
override def call() = try {
|
||||||
checkLists(InetAddress.getByName(url.getHost), url.getHost)
|
checkLists(InetAddress.getByName(url.getHost), url.getHost)
|
||||||
val proxy = Option(FMLCommonHandler.instance.getMinecraftServerInstance.getServerProxy).getOrElse(java.net.Proxy.NO_PROXY)
|
val proxy = Option(FMLCommonHandler.instance.getMinecraftServerInstance.getServerProxy).getOrElse(java.net.Proxy.NO_PROXY)
|
||||||
url.openConnection(proxy) match {
|
url.openConnection(proxy) match {
|
||||||
case http: HttpURLConnection => try {
|
case http: HttpURLConnection => try {
|
||||||
http.setDoInput(true)
|
http.setDoInput(true)
|
||||||
|
http.setDoOutput(post.isDefined)
|
||||||
|
http.setRequestMethod(if (method.isDefined) method.get else if (post.isDefined) "POST" else "GET")
|
||||||
headers.foreach(Function.tupled(http.setRequestProperty))
|
headers.foreach(Function.tupled(http.setRequestProperty))
|
||||||
if (post.isDefined) {
|
if (post.isDefined) {
|
||||||
http.setRequestMethod("POST")
|
|
||||||
http.setDoOutput(true)
|
|
||||||
http.setReadTimeout(Settings.get.httpTimeout)
|
http.setReadTimeout(Settings.get.httpTimeout)
|
||||||
|
|
||||||
val out = new BufferedWriter(new OutputStreamWriter(http.getOutputStream))
|
val out = new BufferedWriter(new OutputStreamWriter(http.getOutputStream))
|
||||||
out.write(post.get)
|
out.write(post.get)
|
||||||
out.close()
|
out.close()
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
http.setRequestMethod("GET")
|
|
||||||
http.setDoOutput(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
val input = http.getInputStream
|
val input = http.getInputStream
|
||||||
HTTPRequest.this.synchronized {
|
HTTPRequest.this.synchronized {
|
||||||
|
@ -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