-
Notifications
You must be signed in to change notification settings - Fork 2
Refined Storage
The Refined Storage API is available from version 1.0.0 of the mod, provided that Refined Storage is also installed. (Starting from 1.2.2, it is only an optional dependency of this mod.)
Craft a "Refined Storage Peripheral" block and place it either directly next to a computer or turtle, or connected via a Wired Modem to one. Also connect this block to your Refined Storage network, either via cable or by placing it next to an existing block.
Note that due to the flexibility and power of lua coding, each peripheral block and each computer connected to it will draw a hefty chunk of extra RF/t energy on your storage system. (If you want to rebalance this, there are settings available in the server config file.)
Within your lua program, simply call APIs from refinedstorage directly — this API automatically becomes available once you reboot a computer that has an RS peripheral connected. (If you break/replace the peripheral, reboot the computer again.)
You do not need to explicitly peripheral.wrap the peripheral when there’s only one attached to the computer. If you have more than one attached (e.g. for subnetworks) then you should explicitly wrap all of them to ensure that you’re accessing the right ones — the global refinedstorage could be either of them, and it could change over time.
(Note that this only applies to 1.1.0+; if you’re still using 1.0.0 then you do have to explicitly wrap.)
Almost all API methods will return either a single value on success (or partial success); on failure they return two values — the first is nil and the second is a string with a human-readable error message. You can ignore the second return value if you wish, but it may be useful to log it to help track down problems.
A few APIs may return nil (also with a nil error string) to indicate that no match was found (e.g. no crafting pattern exists for the specified item). Others may return an empty table in this case.
The most common error message is "not connected", which most methods will return if the peripheral block is not connected to an active Refined Storage network, or the network is out of power.
The descriptions of the APIs below will not explicitly call out that they can also return a nil error. Just remember that it’s always possible.
In addition, some APIs may throw an error if you attempt to call them with an item or fluid name that doesn’t exist in Minecraft at all (perhaps from a typo or due to a mod not being installed).
The bare minimum when supplying an item description as a parameter is the minecraft item id:
{name="minecraft:stone"}
In some cases you may need to also specify NBT values, e.g:
{name="computercraft:disk",nbt="543569198bcc713dabcbc4f9b5bf0715"}
It’s never necessary to provide any other values as a parameter, but more information is provided when receiving an item as a return value (either from a pattern or from storage). This can include the count of the item as well as decoding some properties from the NBT, such as damage and enchantments. It’s best to go look at specific items in your own storage system to figure out what values are returned.
Note that the NBT values are hashes of the actual data, and cannot be used to reconstruct the contents, to avoid breaking the progression systems of other mods that may rely on the actual values not being directly available to the player. These are the same values provided by ComputerCraft for regular inventories, so you can use them for comparison.
However on items with complex tags it’s possible for what is actually the same item with the same data to produce multiple different NBT hashes, so it can’t always be relied on. But then, Refined Storage can also have trouble dealing with items with these complex tags as well.
Some server config options are available that allow providing more reversible encodings of the data, which can sometimes help with these issues. But they have a higher risk of breaking mod progression and it’s not recommended to enable them. They might even be removed in a future mod version.
Fluid descriptions are essentially the same as item descriptions, except that instead of a count of items they have an amount of fluid (measured in milli-Buckets or mB as usual). It’s also a lot rarer for NBT values to be required, although not impossible.
A crafting pattern will tell you if it is a processing pattern or not.
Processing patterns may have inputs, fluidInputs, outputs, and fluidOutputs.
Non-processing patterns may have inputs, outputs, and byproducts (e.g. returning empty buckets).
The stack contains the item (and count) or fluid (and amount) that was requested to craft.
The pattern contains the crafting pattern being used.
For the APIs that accept a direction parameter, the following values are supported:
-
string: one of
"down"/"up"/"north"/"south"/"west"/"east" -
number: 0-5, where 0 is
"down"
If the direction is not specified, then "down" is the default.
(Note that the relative-to-computer/turtle directions left/right/front/back/top/bottom are not supported, since the peripheral block doesn’t face any particular direction.)
Whether the RS network is currently connected. This is the only API that will not return nil if the network is disconnected.
-
Returns: boolean true if the network is connected; false otherwise.
-
Since: 1.0.0
Gets the energy usage of this network.
-
Returns: number The RF/t energy usage of this network.
-
Since: 1.0.0
Gets the storage capacity and usage of this network.
-
Returns: table A table consisting of:
-
total: the totalitemandfluidstoragecapacityandusageof the network. -
devices: an array of each individual storage device’stype,capacity, andusage.
-
-
Since: 1.0.0
Gets information about all items stored in the network, or all items matching a specific item name.
|
Optional |
table |
The item description of an item (only the name is used). |
-
Returns: table An array of item descriptions.
-
Since: 1.0.0; 1.1.0 adds item parameter
Gets information about all fluids stored in the network, or all fluids matching a specific fluid name.
|
Optional |
table |
The fluid description of a fluid (only the name is used). |
-
Returns: table An array of fluid descriptions.
-
Since: 1.0.0; 1.1.0 adds fluid parameter
Gets information about a particular item stored in the network.
|
Required |
table |
The item description of the item. |
|
Optional |
boolean |
If false, tries to find any matching item regardless of NBT; if true or omitted, won’t find items with different NBT |
|
Optional |
boolean |
If true, returns item information (with zero count) when there is no such item instead |
-
Returns: table The item description of the first matching item found, or an empty table if there was no such item.
-
Since: 1.0.0; 1.1.0 adds evenIfZero parameter
Gets information about a particular fluid stored in the network.
|
Required |
table |
The fluid description of the fluid. |
|
Optional |
boolean |
If false, tries to find any matching fluid regardless of NBT; if true or omitted, won’t find fluids with different NBT |
|
Optional |
boolean |
If true, returns fluid information (with zero amount) when there is no such fluid instead |
-
Returns: table The fluid description of the first matching fluid found, or an empty table if there was no such fluid.
-
Since: 1.0.0; 1.1.0 adds evenIfZero parameter
Gets all known item crafting patterns, or all patterns with the specified output item.
|
Optional |
table |
The item description of an item (only the name is used). |
-
Returns: table An array of item crafting patterns.
-
Since: 1.0.0; 1.1.0 adds item parameter
Gets all known fluid crafting patterns, or all patterns with the specified output fluid.
|
Optional |
table |
The fluid description of a fluid (only the name is used). |
-
Returns: table An array of fluid crafting patterns.
-
Since: 1.0.0; 1.1.0 adds fluid parameter
Checks whether the system knows how to craft the specified item.
|
Required |
table |
The item description of the output item. |
-
Returns: boolean True if a pattern exists; false if it does not.
-
Since: 1.0.0
Checks whether the system knows how to craft the specified fluid.
|
Required |
table |
The fluid description of the output fluid. |
-
Returns: boolean True if a pattern exists; false if it does not.
-
Since: 1.0.0
Gets information about a particular item crafting pattern.
|
Required |
table |
The item description of the output item. |
-
Returns: table The crafting pattern for that item, or
nilif no such pattern could be found. -
Since: 1.0.0
Gets information about a particular fluid crafting pattern.
|
Required |
table |
The fluid description of the output fluid. |
-
Returns: table The crafting pattern for that fluid, or
nilif no such pattern could be found. -
Since: 1.0.0
Gets the current crafting tasks of this network.
-
Returns: table The list of crafting tasks (if any).
-
Since: 1.0.0
Schedules an item crafting task.
|
Required |
table |
The item description of the output item. |
|
Optional |
number |
The number of items to craft. If omitted, it will use the |
|
Optional |
boolean |
If false, it will report the crafting task but not actually start it; if true or omitted, it will be started. |
-
Returns: table The crafting task (even if not scheduled), or
nilif crafting is not possible (e.g. some inputs are missing) -
Since: 1.0.0
Schedules a fluid crafting task.
|
Required |
table |
The fluid description of the output fluid. |
|
Optional |
number |
The amount (in mB) to craft. If omitted, it will use the |
|
Optional |
boolean |
If false, it will report the crafting task but not actually start it; if true or omitted, it will be started. |
-
Returns: table The crafting task (even if not scheduled), or
nilif crafting is not possible (e.g. some inputs are missing) -
Since: 1.0.0
Cancels an item crafting task. Note that this doesn’t automatically cancel sub-tasks.
|
Required |
table |
The item description of the output item. |
-
Returns: number The number of pending crafting tasks successfully cancelled.
-
Since: 1.0.0
Cancels a fluid crafting task. Note that this doesn’t automatically cancel sub-tasks.
|
Required |
table |
The fluid description of the output fluid. |
-
Returns: number The number of pending crafting tasks successfully cancelled.
-
Since: 1.0.0
Extracts items from the storage network and inserts them into an inventory adjacent to the RS Peripheral block.
Note that it may extract fewer items than requested if the network is getting empty or the target inventory is getting full.
|
Required |
table |
The item description of item to be extracted. |
|
Optional |
number |
The number of items to transfer. If omitted, the |
|
Optional |
direction |
The direction of the target inventory from the peripheral. |
-
Returns: number The number of items successfully transferred (or 0 if no items could be transferred).
-
Since: 1.0.0
Extracts fluid from the storage network and inserts it into a tank adjacent to the RS Peripheral block.
Note that it may extract a smaller amount than requested if the network is getting empty or the target tank is getting full.
|
Required |
table |
The fluid description of fluid to be extracted. |
|
Optional |
number |
The amount of fluid to transfer (in mB). If omitted, the |
|
Optional |
direction |
The direction of the target tank from the peripheral. |
-
Returns: number The amount of fluid successfully transferred (or 0 if no fluid could be transferred).
-
Since: 1.0.0