Method | Description |
---|---|
getItemDetail(slot) | Gets detailed information about an item in the payment inventory's given slot |
getStockItemDetail(index) | Gets detailed information about an item in the stock's given index |
list() | Lists all items in the payment inventory |
requestFiltered(address, [filter1], [filter2], ...) | Requests a package from the network |
stock([detailed]) | Lists all items in the network |
getItemDetail(slot)
Get detailed information about an item in the payment inventory.
The returned information contains the same information as each item in list
, as well as additional details like the display name (displayName
), and item durability (damage
, maxDamage
, durability
).
Some items include more information (such as enchantments) - it is recommended to print it out using textutils.serialize
or in the Lua REPL, to explore what is available.
Parameters
- slot:
number
The slot to get information about.
Throws
- If the slot is out of range.
Returns
table
Information about the item in this slot, ornil
if it is empty, like:
{
name = "minecraft:apple",
itemGroups = {},
tags = {},
count = 1,
maxCount = 64,
displayName = "Apple",
}
getStockItemDetail(slot)
Get detailed information about an item in the network stock.
The returned information contains the same information as each item in list
, as well as additional details like the display name (displayName
), and item durability (damage
, maxDamage
, durability
).
Some items include more information (such as enchantments) - it is recommended to print it out using textutils.serialize
or in the Lua REPL, to explore what is available.
Hint
The order of indexes changes whenever the network gets reloaded, make sure to use stock
to check what item to look for.
You can also avoid using this function by using stock(true)
, which already includes the detailed information of all items.
Parameters
- index:
number
The index to get information from.
Throws
- If the slot is out of range.
Returns
table
Information about the item in this slot, ornil
if it is empty, like:
{
name = "minecraft:apple",
itemGroups = {},
tags = {},
count = 1,
maxCount = 64,
displayName = "Apple",
}
list()
List all items in the payment inventory. This returns a table, with an entry for each slot.
Each item in the inventory is represented by a table containing some basic information. More information can be fetched with getItemDetail
. The table contains the item name
, the count
and a (potentially nil
) hash of the item's nbt
. This NBT data doesn't contain anything useful, but allows you to distinguish identical items.
The returned table is sparse, so empty slots will be nil
- it is recommended to loop over using pairs
rather than ipairs
.
Returns
table
with basic item information like:
{
{
name = "minecraft:apple",
count = 1,
},
{
name = "minecraft:stick",
count = 1,
},
[ 10 ] = {
nbt = "ce5c752cf2df5cf4ffb17d7b7bfacad7",
count = 1,
name = "minecraft:enchanted_book",
},
}
requestFiltered(address, [filter1], [filter2], ...)
Requests for a package in the network with the given address
attached.
The request is made of any number of filter
arguments, which are tables used to match against detailed item data, like stock(true)
or .getStockItemDetail
.
Each filter
follows these rules: for all items in the network (or until it has matched items equal to _requestCount = number
at the base of the table):
- It will compare all keys in the
filter
given to theitemDetail
of the item. IfitemDetail
has all the keys present infilter
, and the values match, it's added to the request.- If the table has
_mode = "exact"
, it will instead make sure that the key and value pairs between both theitemDetail
andfilter
match 1:1 on this level. This is not recursive and for each nested table_mode
needs to be assigned again. - If the table has
_mode = "contained"
, it will instead compare all theitemDetail
keys against things infilter
. the opposite of the default mode. Just like_mode = "exact"
this is not recursive. _mode = "contains"
does nothing as it is the default.- If the
filter
value is a table with_op = operator
set to anything butnil
, it'll instead run the rest of the logic with thatoperator
in mind on this table'svalue
key._op = ">"
checks if thevalue
is greater than the number given byitemDetail
_op = ">="
checks if thevalue
is greater than or equal to the one given byitemDetail
._op = "<"
checks if thevalue
is less than the one given byitemDetail
._op = "<="
checks if thevalue
is less than or equal to the one given byitemDetail
._op = "=="
checks if thevalue
is equal to the one given byitemDetail
._op = "~="
checks if thevalue
is not equal to the one given byitemDetail
._op = "type"
checks the type ofitemDetail
. Thevalue
must be one of:"nil"
matches if the value isnil
"number"
matches if the value is anumber
"string"
matches if the value is astring
"boolean"
matches if the value is aboolean
"table"
matches if the value is atable
"list"
matches if it's a numbered non-sparsetable
"map"
matches if it's a (possibly) sparsetable
"object"
matches if the value is an object, like thepackage
object
_op = "not"
inverts the result of the comparison onvalue
._op = "any"
checks if any of the values invalue
match the value initemDetail
.value
must be a non-sparsetable
._op = "all"
checks if all of the values invalue
match the value initemDetail
.value
must be a non-sparsetable
._op = "regex"
checks if theitemDetail
string matches the regex pattern provided invalue
._op = "glob"
checks if theitemDetail
string matches the glob pattern provided invalue
.
- If
both
the values are tables, it'll go inside the table and run this check again on the values inside, checking for_mode
and_op
.
- If the table has
The candidates that pass the filter(s) are then passed on to be requested by the network, like if you opened the Stock Keeper's ui and requested something with it.
Parameters
- address:
string
Address given to the requested package(s). - filter:
table
Table of values to filter items by, similar to that of.getStockItemDetail
. The request can be made of any number offilter
args.
Returnse
number
Number of items requested with the given filter.
Usage
Understanding how a filter
works
This is by far the most complicated feature provided with create's cc compatiblity. Consider looking at the examples below to get a better idea of how this is used.
Or, just stick to the basics. A simple filter like this:
.requestfiltered("address", {name = "apple", _requestCount = 10})
will get you up to 10 apples just fine.
stockTicker = peripheral.find("Create_StockTicker")
stockTicker.requestFiltered("givenAddress", {
-- Get up to 5 items
_requestCount = 5,
-- whose names are either:
-- - a crushing wheel
-- - from minecraft
-- - don't contain an "e"
name = { _op = "any", value =
{
"create:crushing_wheel",
{_op = "glob", value = "minecraft:*"},
{_op = "not", value =
{_op = "glob", value = "*e*"}
},
}
},
-- Those items must also, in the stock network, have a count between 2 and 100 to be included
count = { _op = "all", value =
{
{ _op = ">", value = 2 },
{ _op = "<", value = 100 }
}
},
},
-- , as the second filter for this same order, request the following:
{
-- any number of items (no _requestCount) present
-- that has the `tags` key. Note that **all** items have a `tags` key, even if it's empty.
tags = {
[ "forge:rods/wooden" ] = true,
[ "forge:rods" ] = true,
[ "forge:tools" ] = true,
-- that can't have any tags other than forge:rods, forge:rods/wooden or forge:tools
_mode = "contained",
},
-- that have an `nbt` key, which doesn't appear unless the item has nbt data.
nbt = {},
}
)
the given function will request up to 5 items with the first filter, then any number of items with the second filter. If the items from both filters are present in the same inventory and can fit into the same pacakged, they will be packaged together as one request.
While:
stockTicker.request("givenAddress", {})
Would request all items in the network, because all items would pass the empty filter.
stock([detailed])
List all items in the stock. This returns a table, with an entry for each item.
Each item in the inventory is represented by a table containing some basic information (or detailed information if detailed = true
).
The returned table is never sparse, so you can iterate over it with ipairs
just fine.
Parameters
- detailed:
boolean = false
Whether the item information should be detailed.
Returns
table
with basic item information like:
{
{
name = "minecraft:apple",
count = 1,
},
{
nbt = "ce5c752cf2df5cf4ffb17d7b7bfacad7",
count = 1,
name = "minecraft:enchanted_book",
},
}
or, with detailed = true
:
{
{
name = "minecraft:stick",
itemGroups = {},
tags = {
[ "forge:rods/wooden" ] = true,
[ "forge:rods" ] = true,
},
count = 1,
maxCount = 64,
displayName = "Stick",
},
{
enchantments = {
{
level = 1,
name = "minecraft:unbreaking",
displayName = "Unbreaking I",
},
},
tags = {
[ "minecraft:bookshelf_books" ] = true,
},
name = "minecraft:enchanted_book",
itemGroups = {},
maxCount = 1,
count = 1,
nbt = "ce5c752cf2df5cf4ffb17d7b7bfacad7",
displayName = "Enchanted Book",
},
}