mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-26 22:43:40 -04:00
Merge pull request #45 from repo-alt/master
Allow debug card to insert huge amounts of items, e.g. to fill infinity chest
This commit is contained in:
commit
b30c1bf743
2
gradlew
vendored
2
gradlew
vendored
@ -44,7 +44,7 @@ APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
DEFAULT_JVM_OPTS='"-Xmx2G" "-Xms128m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
2
gradlew.bat
vendored
2
gradlew.bat
vendored
@ -30,7 +30,7 @@ set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
set DEFAULT_JVM_OPTS="-Xmx2G" "-Xms128m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
@ -619,7 +619,7 @@ object DebugCard {
|
||||
if (item == null) {
|
||||
throw new IllegalArgumentException("invalid item id")
|
||||
}
|
||||
val count = args.checkInteger(1)
|
||||
var count = args.checkInteger(1)
|
||||
val damage = args.checkInteger(2)
|
||||
val tagJson = args.optString(3, "")
|
||||
val tag = if (Strings.isNullOrEmpty(tagJson)) null else JsonToNBT.func_150315_a(tagJson).asInstanceOf[NBTTagCompound]
|
||||
@ -629,7 +629,22 @@ object DebugCard {
|
||||
case Some(inventory) =>
|
||||
val stack = new ItemStack(item, count, damage)
|
||||
stack.setTagCompound(tag)
|
||||
result(InventoryUtils.insertIntoInventory(stack, inventory, Option(side)))
|
||||
val res = InventoryUtils.insertIntoInventory(stack, inventory, Option(side), count)
|
||||
if (!res)
|
||||
result(res)
|
||||
else {
|
||||
var stored = count - stack.stackSize
|
||||
while (stored > 0 && stack.stackSize > 0) {
|
||||
count = stack.stackSize
|
||||
// InventoryUtils.insertIntoInventory honors max stack size for the stack,
|
||||
// but debug card may ignore that e.g. for infinity chest
|
||||
// so we try to insert the rest until we fail
|
||||
if (!InventoryUtils.insertIntoInventory(stack, inventory, Option(side), count))
|
||||
return result(true)
|
||||
stored = count - stack.stackSize
|
||||
}
|
||||
result(true)
|
||||
}
|
||||
case _ => result(Unit, "no inventory")
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package li.cil.oc.server.component
|
||||
|
||||
import java.util
|
||||
|
||||
import com.google.common.base.Strings
|
||||
import com.google.common.hash.Hashing
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute
|
||||
@ -12,19 +13,19 @@ import li.cil.oc.api.internal
|
||||
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.Visibility
|
||||
import li.cil.oc.api.network.{Node, Visibility}
|
||||
import li.cil.oc.api.prefab
|
||||
import li.cil.oc.util.DatabaseAccess
|
||||
import li.cil.oc.util.ExtendedArguments._
|
||||
import li.cil.oc.util.ExtendedNBT._
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.CompressedStreamTools
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.nbt.{CompressedStreamTools, JsonToNBT, NBTTagCompound}
|
||||
|
||||
import scala.collection.convert.WrapAsJava._
|
||||
|
||||
class UpgradeDatabase(val data: IInventory) extends prefab.ManagedEnvironment with internal.Database with DeviceInfo {
|
||||
override val node = Network.newNode(this, Visibility.Network).
|
||||
override val node: Node = Network.newNode(this, Visibility.Network).
|
||||
withComponent("database").
|
||||
create()
|
||||
|
||||
@ -38,17 +39,19 @@ class UpgradeDatabase(val data: IInventory) extends prefab.ManagedEnvironment wi
|
||||
|
||||
override def getDeviceInfo: util.Map[String, String] = deviceInfo
|
||||
|
||||
override def size = data.getSizeInventory
|
||||
override def size: Int = data.getSizeInventory
|
||||
|
||||
override def getStackInSlot(slot: Int) = Option(data.getStackInSlot(slot)).map(_.copy()).orNull
|
||||
override def getStackInSlot(slot: Int): ItemStack = Option(data.getStackInSlot(slot)).map(_.copy()).orNull
|
||||
|
||||
override def setStackInSlot(slot: Int, stack: ItemStack) = data.setInventorySlotContents(slot, stack)
|
||||
override def setStackInSlot(slot: Int, stack: ItemStack): Unit = data.setInventorySlotContents(slot, stack)
|
||||
|
||||
override def findStackWithHash(needle: String) = indexOf(needle)
|
||||
override def findStackWithHash(needle: String): Int = indexOf(needle)
|
||||
|
||||
//noinspection ScalaUnusedSymbol
|
||||
@Callback(doc = "function(slot:number):table -- Get the representation of the item stack stored in the specified slot.")
|
||||
def get(context: Context, args: Arguments): Array[AnyRef] = result(data.getStackInSlot(args.checkSlot(data, 0)))
|
||||
|
||||
//noinspection ScalaUnusedSymbol
|
||||
@Callback(doc = "function(slot:number):string -- Computes a hash value for the item stack in the specified slot.")
|
||||
def computeHash(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
data.getStackInSlot(args.checkSlot(data, 0)) match {
|
||||
@ -59,9 +62,11 @@ class UpgradeDatabase(val data: IInventory) extends prefab.ManagedEnvironment wi
|
||||
}
|
||||
}
|
||||
|
||||
//noinspection ScalaUnusedSymbol
|
||||
@Callback(doc = "function(hash:string):number -- Get the index of an item stack with the specified hash. Returns a negative value if no such stack was found.")
|
||||
def indexOf(context: Context, args: Arguments): Array[AnyRef] = result(indexOf(args.checkString(0), 1))
|
||||
|
||||
//noinspection ScalaUnusedSymbol
|
||||
@Callback(doc = "function(slot:number):boolean -- Clears the specified slot. Returns true if there was something in the slot before.")
|
||||
def clear(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val slot = args.checkSlot(data, 0)
|
||||
@ -70,6 +75,7 @@ class UpgradeDatabase(val data: IInventory) extends prefab.ManagedEnvironment wi
|
||||
result(nonEmpty)
|
||||
}
|
||||
|
||||
//noinspection ScalaUnusedSymbol
|
||||
@Callback(doc = "function(fromSlot:number, toSlot:number[, address:string]):boolean -- Copies an entry to another slot, optionally to another database. Returns true if something was overwritten.")
|
||||
def copy(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val fromSlot = args.checkSlot(data, 0)
|
||||
@ -84,6 +90,7 @@ class UpgradeDatabase(val data: IInventory) extends prefab.ManagedEnvironment wi
|
||||
else set(data)
|
||||
}
|
||||
|
||||
//noinspection ScalaUnusedSymbol
|
||||
@Callback(doc = "function(address:string):number -- Copies the data stored in this database to another database with the specified address.")
|
||||
def clone(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
DatabaseAccess.withDatabase(node, args.checkString(0), database => {
|
||||
@ -96,6 +103,22 @@ class UpgradeDatabase(val data: IInventory) extends prefab.ManagedEnvironment wi
|
||||
})
|
||||
}
|
||||
|
||||
//noinspection ScalaUnusedSymbol
|
||||
@Callback(doc = """function(slot:number, id:string, damage:number, nbt:string):boolean - Set an item into the specified database slot. NBT tag is expected in JSON format.""")
|
||||
def set(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val slot = args.checkSlot(data, 0)
|
||||
val item = Item.itemRegistry.getObject(args.checkString(1)).asInstanceOf[Item]
|
||||
if (item == null)
|
||||
return result(false, "invalid item id")
|
||||
val damage = args.checkInteger(2)
|
||||
val tagJson = args.optString(3, "")
|
||||
val tag = if (Strings.isNullOrEmpty(tagJson)) null else JsonToNBT.func_150315_a(tagJson).asInstanceOf[NBTTagCompound]
|
||||
val stack = new ItemStack(item, 1, damage)
|
||||
stack.setTagCompound(tag)
|
||||
data.setInventorySlotContents(slot, stack)
|
||||
result(true)
|
||||
}
|
||||
|
||||
private def indexOf(needle: String, offset: Int = 0): Int = {
|
||||
for (slot <- 0 until data.getSizeInventory) data.getStackInSlot(slot) match {
|
||||
case stack: ItemStack =>
|
||||
|
Loading…
x
Reference in New Issue
Block a user