mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-23 12:30:56 -04:00
AE2: feat: Added a faster method to filter items from ME network
This commit is contained in:
parent
2c0252556c
commit
a0393127f5
@ -31,6 +31,7 @@ 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
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraftforge.common.DimensionManager
|
||||
@ -92,6 +93,24 @@ trait NetworkControl[AETile >: Null <: TileEntity with IGridProxyable with IActi
|
||||
.toArray)
|
||||
}
|
||||
|
||||
@Callback(doc = "function(filter:table):table -- Get a list of the stored items in the network matching the filter. Filter is an Array of Item IDs")
|
||||
def getItemsInNetworkById(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val table = args.checkTable(0)
|
||||
|
||||
val itemFilterSet = mutable.LinkedHashSet.empty[Item]
|
||||
for (i <- 0 until table.size()) {
|
||||
table.get(i + 1) match {
|
||||
case itemNumberId: Number => itemFilterSet += Item.itemRegistry.getObjectById(itemNumberId.intValue()).asInstanceOf[Item]
|
||||
case itemStringId: String => itemFilterSet += Item.itemRegistry.getObject(itemStringId).asInstanceOf[Item]
|
||||
case other: Any => throw new IllegalArgumentException(s"bad argument in filter table at index ${i + 1} (number or string expected)")
|
||||
}
|
||||
}
|
||||
result(allItems
|
||||
.filter(item => itemFilterSet.contains(item.getItem))
|
||||
.map(item => convert(item, tile))
|
||||
.toArray)
|
||||
}
|
||||
|
||||
@Callback(doc = "function():userdata -- Get an iterator object for the list of the items in the network.")
|
||||
def allItems(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
result(new NetworkContents(tile))
|
||||
|
Loading…
x
Reference in New Issue
Block a user