Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComputers into master-MC1.8

This commit is contained in:
Florian Nücke 2015-06-07 13:52:04 +02:00
commit db7e23c03e
8 changed files with 48 additions and 9 deletions

View File

@ -12,7 +12,7 @@ import li.cil.oc.api.detail.*;
*/
public class API {
public static final String ID_OWNER = "OpenComputers|Core";
public static final String VERSION = "5.5.1";
public static final String VERSION = "5.5.2";
public static DriverAPI driver = null;
public static FileSystemAPI fileSystem = null;

View File

@ -34,6 +34,16 @@ public interface Database {
*/
ItemStack getStackInSlot(int slot);
/**
* Set the contents of a slot in the database upgrade.
* <p/>
* Use this to change the configuration of a database upgrade.
*
* @param slot the slot to configure.
* @param stack the stack to configure the slot to, <tt>null</tt> to clear.
*/
void setStackInSlot(int slot, ItemStack stack);
/**
* Get an item stack with the specified hash stored in this database.
* <p/>

View File

@ -5,8 +5,11 @@ import li.cil.oc.OpenComputers
import li.cil.oc.api.machine.Arguments
import li.cil.oc.api.machine.Callback
import li.cil.oc.api.machine.Context
import li.cil.oc.api.network.Node
import li.cil.oc.api.prefab.AbstractValue
import li.cil.oc.common.EventHandler
import li.cil.oc.util.DatabaseAccess
import li.cil.oc.util.ExtendedArguments._
import li.cil.oc.util.ExtendedNBT._
import li.cil.oc.util.ResultWrapper._
import net.minecraft.item.Item
@ -25,6 +28,8 @@ import scala.language.existentials
trait NetworkControl[AETile >: Null <: TileEntity with IGridProxyable with IActionHost] {
def tile: AETile
def node: Node
@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(tile.getProxy.getCrafting.getCpus.map(cpu => Map(
@ -57,6 +62,27 @@ trait NetworkControl[AETile >: Null <: TileEntity with IGridProxyable with IActi
result(tile.getProxy.getStorage.getItemInventory.getStorageList.filter(stack => matches(stack, filter)).map(_.getItemStack).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.")
def store(context: Context, args: Arguments): Array[AnyRef] = {
val filter = args.checkTable(0).collect {
case (key: String, value: AnyRef) => (key, value)
}
DatabaseAccess.withDatabase(node, args.checkString(1), database => {
val stacks = tile.getProxy.getStorage.getItemInventory.getStorageList.filter(stack => matches(stack, filter)).map(_.getItemStack).filter(_ != null).toArray
val offset = args.optSlot(database.data, 2, 0)
val count = args.optInteger(3, Int.MaxValue) min (database.size - offset) min stacks.length
var slot = offset
for (i <- 0 until count) {
val stack = Option(stacks(i)).map(_.copy()).orNull
while (database.getStackInSlot(slot) != null && slot < database.size) slot += 1
if (database.getStackInSlot(slot) == null) {
database.setStackInSlot(slot, stack)
}
}
result(true)
})
}
@Callback(doc = "function():table -- Get a list of the stored fluids in the network.")
def getFluidsInNetwork(context: Context, args: Arguments): Array[AnyRef] =
result(tile.getProxy.getStorage.getFluidInventory.getStorageList.map(_.getFluidStack).toArray)

View File

@ -93,8 +93,8 @@ class Geolyzer(val host: EnvironmentHost) extends prefab.ManagedEnvironment {
val stack = new ItemStack(item, 1, damage)
DatabaseAccess.withDatabase(node, args.checkString(1), database => {
val toSlot = args.checkSlot(database.data, 2)
val nonEmpty = database.data.getStackInSlot(toSlot) != null
database.data.setInventorySlotContents(toSlot, stack)
val nonEmpty = database.getStackInSlot(toSlot) != null
database.setStackInSlot(toSlot, stack)
result(nonEmpty)
})
}

View File

@ -23,6 +23,8 @@ class UpgradeDatabase(val data: IInventory) extends prefab.ManagedEnvironment wi
override def getStackInSlot(slot: Int) = Option(data.getStackInSlot(slot)).map(_.copy()).orNull
override def setStackInSlot(slot: Int, stack: ItemStack) = data.setInventorySlotContents(slot, stack)
override def findStackWithHash(needle: String) = indexOf(needle)
@Callback(doc = "function(slot:number):table -- Get the representation of the item stack stored in the specified slot.")

View File

@ -23,8 +23,8 @@ trait InventoryAnalytics extends InventoryAware with NetworkAware {
val localStack = inventory.getStackInSlot(localSlot)
DatabaseAccess.withDatabase(node, dbAddress, database => {
val dbSlot = args.checkSlot(database.data, 2)
val nonEmpty = database.data.getStackInSlot(dbSlot) != null
database.data.setInventorySlotContents(dbSlot, localStack.copy())
val nonEmpty = database.getStackInSlot(dbSlot) != null
database.setStackInSlot(dbSlot, localStack.copy())
result(nonEmpty)
})
}
@ -36,7 +36,7 @@ trait InventoryAnalytics extends InventoryAware with NetworkAware {
val localStack = inventory.getStackInSlot(localSlot)
DatabaseAccess.withDatabase(node, dbAddress, database => {
val dbSlot = args.checkSlot(database.data, 2)
val dbStack = database.data.getStackInSlot(dbSlot)
val dbStack = database.getStackInSlot(dbSlot)
result(haveSameItemType(localStack, dbStack))
})
}

View File

@ -57,8 +57,8 @@ trait WorldInventoryAnalytics extends WorldAware with SideRestricted with Networ
val dbAddress = args.checkString(2)
def store(stack: ItemStack) = DatabaseAccess.withDatabase(node, dbAddress, database => {
val dbSlot = args.checkSlot(database.data, 3)
val nonEmpty = database.data.getStackInSlot(dbSlot) != null
database.data.setInventorySlotContents(dbSlot, stack.copy())
val nonEmpty = database.getStackInSlot(dbSlot) != null
database.setStackInSlot(dbSlot, stack.copy())
result(nonEmpty)
})
withInventory(facing, inventory => store(inventory.getStackInSlot(args.checkSlot(inventory, 1))))

View File

@ -22,7 +22,8 @@ object UpdateCheck {
}
private def initialize(): Option[Release] = {
if (Settings.get.updateCheck && OpenComputers.Version != "@VERSION@") {
// Keep the version template split up so it's not replaced with the actual version...
if (Settings.get.updateCheck && OpenComputers.Version != ("@" + "VERSION" + "@")) {
try {
OpenComputers.log.info("Starting OpenComputers version check.")
val reader = new JsonReader(new InputStreamReader(releasesUrl.openStream()))