Skip to content

Commit

Permalink
Merge remote-tracking branch 'Georggi/addFasterAENetworkAccess' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed Jun 28, 2024
2 parents 1b5aea5 + a039312 commit 4296277
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 4296277

Please sign in to comment.