mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 10:21:45 -04:00
Merge branch master-MC1.7.10 into master-MC1.10
# Conflicts: # src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala
This commit is contained in:
commit
37335d98b6
@ -949,7 +949,7 @@ opencomputers {
|
||||
|
||||
# This is a list of blacklisted domain names. If an HTTP request is made
|
||||
# or a socket connection is opened the target address will be compared
|
||||
# to the addresses / adress ranges in this list. It it is present in this
|
||||
# to the addresses / address ranges in this list. It it is present in this
|
||||
# list, the request will be denied.
|
||||
# Entries are either domain names (www.example.com) or IP addresses in
|
||||
# string format (10.0.0.3), optionally in CIDR notation to make it easier
|
||||
|
@ -556,7 +556,7 @@ getKeyBindHandler = function(code)
|
||||
if type(keybinds) == "table" and keyBindHandlers[command] then
|
||||
for _, keybind in ipairs(keybinds) do
|
||||
if type(keybind) == "table" then
|
||||
local alt, control, shift, key
|
||||
local alt, control, shift, key = false, false, false
|
||||
for _, value in ipairs(keybind) do
|
||||
if value == "alt" then alt = true
|
||||
elseif value == "control" then control = true
|
||||
@ -564,9 +564,9 @@ getKeyBindHandler = function(code)
|
||||
else key = value end
|
||||
end
|
||||
local keyboardAddress = term.keyboard()
|
||||
if (not alt or keyboard.isAltDown(keyboardAddress)) and
|
||||
(not control or keyboard.isControlDown(keyboardAddress)) and
|
||||
(not shift or keyboard.isShiftDown(keyboardAddress)) and
|
||||
if (alt == not not keyboard.isAltDown(keyboardAddress)) and
|
||||
(control == not not keyboard.isControlDown(keyboardAddress)) and
|
||||
(shift == not not keyboard.isShiftDown(keyboardAddress)) and
|
||||
code == keyboard.keys[key] and
|
||||
#keybind > resultWeight
|
||||
then
|
||||
|
@ -45,8 +45,15 @@ object ChunkloaderUpgradeHandler extends LoadingCallback {
|
||||
// so if the save is because the game is being quit the tickets aren't
|
||||
// actually being cleared. This will *usually* not be a problem, but it
|
||||
// has room for improvement.
|
||||
restoredTickets.values.foreach(ticket => try ForgeChunkManager.releaseTicket(ticket) catch {
|
||||
case _: Throwable => // Ignored.
|
||||
restoredTickets.values.foreach(ticket => {
|
||||
try{
|
||||
val data = ticket.getModData
|
||||
OpenComputers.log.warn(s"A chunk loader ticket has been orphaned! Address: ${data.getString("address")}, position: (${data.getInteger("x")}, ${data.getInteger("z")}). Removing...")
|
||||
ForgeChunkManager.releaseTicket(ticket)
|
||||
}
|
||||
catch {
|
||||
case _: Throwable => // Ignored.
|
||||
}
|
||||
})
|
||||
restoredTickets.clear()
|
||||
}
|
||||
@ -73,9 +80,6 @@ object ChunkloaderUpgradeHandler extends LoadingCallback {
|
||||
val robotChunks = (for (x <- -1 to 1; z <- -1 to 1) yield new ChunkPos(centerChunk.chunkXPos + x, centerChunk.chunkZPos + z)).toSet
|
||||
|
||||
loader.ticket.foreach(ticket => {
|
||||
if (ticket.getType() == ForgeChunkManager.Type.ENTITY && ticket.getEntity() == null && loader.host.isInstanceOf[Entity])
|
||||
ticket.bindEntity(loader.host.asInstanceOf[Entity])
|
||||
|
||||
ticket.getChunkList.collect {
|
||||
case chunk: ChunkPos if !robotChunks.contains(chunk) => ForgeChunkManager.unforceChunk(ticket, chunk)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import li.cil.oc.api.prefab.AbstractValue
|
||||
import li.cil.oc.common.EventHandler
|
||||
import li.cil.oc.integration.Mods
|
||||
import li.cil.oc.integration.ec.ECUtil
|
||||
import li.cil.oc.server.driver.Registry
|
||||
import li.cil.oc.util.DatabaseAccess
|
||||
import li.cil.oc.util.ExtendedArguments._
|
||||
import li.cil.oc.util.ExtendedNBT._
|
||||
@ -42,6 +43,41 @@ trait NetworkControl[AETile >: Null <: TileEntity with IActionHost] {
|
||||
|
||||
def node: Node
|
||||
|
||||
private def aeCraftItem(aeItem: IAEItemStack): IAEItemStack = {
|
||||
val patterns = AEUtil.getGridCrafting(tile.getGridNode(pos).getGrid).getCraftingFor(aeItem, null, 0, tile.getWorld)
|
||||
patterns.find(pattern => pattern.getOutputs.exists(_.isSameType(aeItem))) match {
|
||||
case Some(pattern) => pattern.getOutputs.find(_.isSameType(aeItem)).get
|
||||
case _ => aeItem.copy.setStackSize(0) // Should not be possible, but hey...
|
||||
}
|
||||
}
|
||||
|
||||
private def aePotentialItem(aeItem: IAEItemStack): IAEItemStack = {
|
||||
if (aeItem.getStackSize > 0 || !aeItem.isCraftable)
|
||||
aeItem
|
||||
else
|
||||
aeCraftItem(aeItem)
|
||||
}
|
||||
|
||||
private def allItems: Iterable[IAEItemStack] = AEUtil.getGridStorage(tile.getGridNode(pos).getGrid).getItemInventory.getStorageList
|
||||
private def allCraftables: Iterable[IAEItemStack] = allItems.collect{ case aeItem if aeItem.isCraftable => aeCraftItem(aeItem) }
|
||||
|
||||
private def convert(aeItem: IAEItemStack, overrideSize: Integer = null): java.util.HashMap[String, AnyRef] = {
|
||||
val result = Registry
|
||||
.convert(Array[AnyRef](aeItem.getItemStack))
|
||||
.collect { case hash: java.util.HashMap[String, AnyRef] => hash }
|
||||
if (result.length > 0) {
|
||||
val hash = result(0)
|
||||
if (overrideSize != null)
|
||||
hash.update("size", overrideSize)
|
||||
return hash
|
||||
}
|
||||
null
|
||||
}
|
||||
|
||||
private def convert(aeItem: IAEItemStack, overrideSize: Int): java.util.HashMap[String, AnyRef] = {
|
||||
convert(aeItem, Int.box(overrideSize))
|
||||
}
|
||||
|
||||
@Callback(doc = "function():table -- Get a list of tables representing the available CPUs in the network.")
|
||||
def getCpus(context: Context, args: Arguments): Array[AnyRef] =
|
||||
result(AEUtil.getGridCrafting(tile.getGridNode(pos).getGrid).getCpus.map(cpu => Map(
|
||||
@ -55,15 +91,10 @@ trait NetworkControl[AETile >: Null <: TileEntity with IActionHost] {
|
||||
val filter = args.optTable(0, Map.empty[AnyRef, AnyRef]).collect {
|
||||
case (key: String, value: AnyRef) => (key, value)
|
||||
}
|
||||
result(AEUtil.getGridStorage(tile.getGridNode(pos).getGrid).getItemInventory.getStorageList.
|
||||
filter(_.isCraftable).filter(stack => matches(stack, filter)).map(stack => {
|
||||
val patterns = AEUtil.getGridCrafting(tile.getGridNode(pos).getGrid).getCraftingFor(stack, null, 0, tile.getWorld)
|
||||
val result = patterns.find(pattern => pattern.getOutputs.exists(_.isSameType(stack))) match {
|
||||
case Some(pattern) => pattern.getOutputs.find(_.isSameType(stack)).get
|
||||
case _ => stack.copy.setStackSize(0) // Should not be possible, but hey...
|
||||
}
|
||||
new NetworkControl.Craftable(tile, pos, result)
|
||||
}).toArray)
|
||||
result(allCraftables
|
||||
.map(aeCraftItem => aeCraftItem -> convert(aeCraftItem))
|
||||
.collect{ case (aeCraftItem, hash: java.util.HashMap[String, AnyRef]) if matches(hash, filter) => new NetworkControl.Craftable(tile, pos, aeCraftItem) }
|
||||
.toArray)
|
||||
}
|
||||
|
||||
@Callback(doc = "function([filter:table]):table -- Get a list of the stored items in the network.")
|
||||
@ -71,7 +102,10 @@ trait NetworkControl[AETile >: Null <: TileEntity with IActionHost] {
|
||||
val filter = args.optTable(0, Map.empty[AnyRef, AnyRef]).collect {
|
||||
case (key: String, value: AnyRef) => (key, value)
|
||||
}
|
||||
result(AEUtil.getGridStorage(tile.getGridNode(pos).getGrid).getItemInventory.getStorageList.filter(stack => matches(stack, filter)).map(_.getItemStack).toArray)
|
||||
result(allItems
|
||||
.map(aeItem => convert(aePotentialItem(aeItem), aeItem.getStackSize.toInt))
|
||||
.filter(hash => matches(hash, filter))
|
||||
.toArray)
|
||||
}
|
||||
|
||||
@Callback(doc = "function(filter:table, dbAddress:string[, startSlot:number[, count:number]]): Boolean -- Store items in the network matching the specified filter in the database with the specified address.")
|
||||
@ -80,12 +114,14 @@ trait NetworkControl[AETile >: Null <: TileEntity with IActionHost] {
|
||||
case (key: String, value: AnyRef) => (key, value)
|
||||
}
|
||||
DatabaseAccess.withDatabase(node, args.checkString(1), database => {
|
||||
val stacks = AEUtil.getGridStorage(tile.getGridNode(pos).getGrid).getItemInventory.getStorageList.filter(stack => matches(stack, filter)).map(_.getItemStack).filter(_ != null).toArray
|
||||
val items = allItems
|
||||
.map(aeItem => aePotentialItem(aeItem) -> aeItem.getStackSize.toInt)
|
||||
.collect{ case (item, size) if matches(convert(item, size), filter) => item }.toArray
|
||||
val offset = args.optSlot(database.data, 2, 0)
|
||||
val count = args.optInteger(3, Int.MaxValue) min (database.size - offset) min stacks.length
|
||||
val count = args.optInteger(3, Int.MaxValue) min (database.size - offset) min items.length
|
||||
var slot = offset
|
||||
for (i <- 0 until count) {
|
||||
val stack = Option(stacks(i)).map(_.copy()).orNull
|
||||
val stack = Option(items(i)).map(_.getItemStack.copy()).orNull
|
||||
while (database.getStackInSlot(slot) != null && slot < database.size) slot += 1
|
||||
if (database.getStackInSlot(slot) == null) {
|
||||
database.setStackInSlot(slot, stack)
|
||||
@ -121,15 +157,20 @@ trait NetworkControl[AETile >: Null <: TileEntity with IActionHost] {
|
||||
def getStoredPower(context: Context, args: Arguments): Array[AnyRef] =
|
||||
result(AEUtil.getGridEnergy(tile.getGridNode(pos).getGrid).getStoredPower)
|
||||
|
||||
private def matches(stack: IAEItemStack, filter: scala.collection.mutable.Map[String, AnyRef]) = {
|
||||
stack != null &&
|
||||
filter.get("damage").forall(_.equals(stack.getItemDamage.toDouble)) &&
|
||||
filter.get("maxDamage").forall(_.equals(stack.getItemStack.getMaxDamage.toDouble)) &&
|
||||
filter.get("size").collect { case size: Number => size.intValue == stack.getStackSize || size.intValue == 0 }.getOrElse(true) &&
|
||||
filter.get("maxSize").forall(_.equals(stack.getItemStack.getMaxStackSize.toDouble)) &&
|
||||
filter.get("hasTag").forall(_.equals(stack.hasTagCompound)) &&
|
||||
filter.get("name").forall(_.equals(Item.REGISTRY.getNameForObject(stack.getItem))) &&
|
||||
filter.get("label").forall(_.equals(stack.getItemStack.getDisplayName))
|
||||
private def matches(stack: java.util.HashMap[String, AnyRef], filter: scala.collection.mutable.Map[String, AnyRef]): Boolean = {
|
||||
if (stack == null) return false
|
||||
filter.forall {
|
||||
case (key: String, value: AnyRef) => {
|
||||
val stack_value = stack.get(key)
|
||||
value match {
|
||||
case number: Number => stack_value match {
|
||||
case stack_number: Number => number.intValue == stack_number.intValue
|
||||
case any => number.toString.equals(any.toString)
|
||||
}
|
||||
case any => any.toString.equals(stack_value.toString)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ class UpgradeChunkloader(val host: EnvironmentHost) extends prefab.ManagedEnviro
|
||||
OpenComputers.log.info(s"Reclaiming chunk loader ticket at (${host.xPosition()}, ${host.yPosition()}, ${host.zPosition()}) in dimension ${host.world().provider.getDimension}.")
|
||||
}
|
||||
ticket = ChunkloaderUpgradeHandler.restoredTickets.remove(node.address).orElse(host match {
|
||||
case context: Context if context.isRunning => Option(ForgeChunkManager.requestTicket(OpenComputers, host.world, if (host.isInstanceOf[Entity]) ForgeChunkManager.Type.ENTITY else ForgeChunkManager.Type.NORMAL))
|
||||
case context: Context if context.isRunning => Option(ForgeChunkManager.requestTicket(OpenComputers, host.world, ForgeChunkManager.Type.NORMAL))
|
||||
case _ => None
|
||||
})
|
||||
ChunkloaderUpgradeHandler.updateLoadedChunk(this)
|
||||
@ -97,7 +97,7 @@ class UpgradeChunkloader(val host: EnvironmentHost) extends prefab.ManagedEnviro
|
||||
|
||||
private def setActive(enabled: Boolean) = {
|
||||
if (enabled && ticket.isEmpty) {
|
||||
ticket = Option(ForgeChunkManager.requestTicket(OpenComputers, host.world, if (host.isInstanceOf[Entity]) ForgeChunkManager.Type.ENTITY else ForgeChunkManager.Type.NORMAL))
|
||||
ticket = Option(ForgeChunkManager.requestTicket(OpenComputers, host.world, ForgeChunkManager.Type.NORMAL))
|
||||
ChunkloaderUpgradeHandler.updateLoadedChunk(this)
|
||||
}
|
||||
else if (!enabled && ticket.isDefined) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user