Storage networks (AE2, Refined Storage)
The storage networks of Applied Energistics 2 and Refined Storage, through their controllers and interfaces: what they hold, items and fluids moved in and out, their storage and energy, and crafting with their patterns.
The blocks of this page come from Applied Energistics 2 (AE2) and Refined Storage. Without those mods, they do not exist, and peripheral.find("me_controller") returns nil.
AE2 and Refined Storage keep thousands of items in one network of drives and disks, and craft what is missing with their patterns. A computer connected to the network's controller or to one of its interfaces sees all of it: it counts any item, takes items and fluids out into a chest or a tank, puts in what a chest holds, watches the storage and the energy, and asks the network to craft. The same program works with both mods.
| Block (in game) | peripheral type | mod |
|---|---|---|
| ME Controller | me_controller | Applied Energistics 2 |
| ME Interface, the block or the part on a cable | me_interface | Applied Energistics 2 |
| Controller, Creative Controller | rs_controller | Refined Storage |
| Interface | rs_interface | Refined Storage |
local me = peripheral.find("me_controller")
print(me.count("minecraft:iron_ingot") .. " iron ingots")
me.push("left", "minecraft:iron_ingot", 16) -- 16 of them into the chest on the leftme.online() | true while the network has energy and the block works: for an ME Interface, it also has its channel; for Refined Storage, its redstone mode allows it. Offline, every other method sees an empty network. |
me.items([pattern]) | The items the network holds, one entry per kind: name its id, count how many, display its name in game. The largest stocks come first. |
me.fluids([pattern]) | The fluids the network holds, like storage_network.items(): amount is in mB (1000 for a bucket). |
me.count([pattern]) | How many items the pattern names, all kinds together. |
me.amount([pattern]) | How much fluid the pattern names, in mB. |
me.storage() | How full the storage is. AE2 counts the bytes of the cells in its drives and ME Chests (a 1k cell has 1024 bytes, and each kind of item takes some of them too), Refined Storage the items and mB of its disks and storage blocks. Storage the network reaches through a storage bus or an external storage, and creative storage with no limit, are not counted. With no fluid storage, fluids is {used = 0, total = 0}. |
me.push(target, item [, count]) | Takes items out of the network into an inventory: a chest, a machine, a Create depot. It stops when count items moved, the target is full or the network has no more. The items the target refuses at the last moment go back into the network, or on the ground, never lost. |
me.pull(source [, slot [, count]]) | Puts the items of an inventory into the network, like an import bus. What the network has no room for stays in the inventory. |
me.push_fluid(target, fluid [, amount]) | Takes fluid out of the network into a tank: a Create Fluid Tank, a basin, a boiler. |
me.pull_fluid(source [, amount]) | Puts the fluid of a tank into the network: the fluid the tank gives first, as a pipe would take it. |
me.power() | The energy the network keeps in its controller and energy cells. |
me.power_capacity() | lua local share = me.power() / me.power_capacity() print(math.floor(share * 100) .. "% charged") |
me.power_usage() | What the network uses per tick (20 ticks a second): with AE2, its average over the last seconds; with Refined Storage, what its working blocks draw. |
me.craftable([pattern]) | The items the network has a pattern for: with AE2, in its pattern providers; with Refined Storage, in its autocrafters. |
me.craft(item [, count]) | Asks the network to craft, like a player in a crafting terminal. The mod plans the job first, which takes a few ticks: the program waits for the plan (20 seconds at most), then the job starts and craft returns {ok = true}, while the crafting itself goes on. When it cannot start, ok is false and error tells why: |
me.crafting() | The jobs running: what each one makes, how many in all, and how far it is (from 0 to 1). A job leaves the list once its items are in the network. |
me.cancel(item) | Stops every job making what the pattern names, like the cancel button of a crafting status screen. The ingredients a job had taken go back into the network. |
me.cpus() | AE2 only: the crafting CPUs of the network. name is the name given to the CPU in game (else "CPU 1", "CPU 2"...), busy whether it runs a job, storage its bytes, coprocessors how many co-processing units it has. A job runs on a free CPU with enough bytes. Refined Storage has no CPUs: its interfaces and controllers have no cpus method. |
Setting up
Reaching it. Put the block against a face of the computer (peripheral.wrap("left")), or against a Data Cable of the computer's network, from the Minicomputer on: it is then named like me_controller@120,64,-35. The easiest is peripheral.find with the type of the table above. An ME Interface part counts when it is on the side of its cable that faces the computer (or the Data Cable): a cable with an interface on another side is not a peripheral. See Peripherals.
The same methods for both mods. The four types have the same methods, documented once below as storage_network; only storage_network.cpus() is AE2's alone. What differs is the mod's own rules: AE2 counts its storage in bytes and its energy in AE, Refined Storage in items, mB and FE. A program written for one network runs on the other by changing the type it looks for.
Naming items and fluids. An item or a fluid is named by its id, like everywhere in Brass: "minecraft:iron_ingot", "minecraft:water"; a plain name is a Minecraft one ("iron_ingot"). Where a method takes a pattern, * stands for any text and ? for one character: "*_ingot" names every ingot, "create:*" every item of Create. Items of the same id but with data of their own (an enchanted book, a damaged tool, a filled backpack) are listed apart, each with its display name; a pattern names them all.
Online or not. A network works while it has energy: AE2 also needs a channel for the ME Interface (a network without a controller has 8), Refined Storage needs its controller powered and the block's redstone mode to allow it. storage_network.online() tells. Offline, a network holds nothing for the computer, as its terminals show it: the lists are empty, the counts 0, nothing moves, and storage_network.craft() answers {ok = false, error = "offline"}.
What it costs. The computer acts as a machine of the network. With AE2, every item or mB moved costs AE energy, as for an import or export bus. A method that reads the whole network (lists, counts, push) costs the program one instruction per kind of item or fluid stored: on a network of 5,000 kinds, call it once and keep the result rather than in every loop.
When the network changes. Refined Storage shows a change at once. AE2 refreshes its list once per tick: what the computer moves itself is seen at once, but what another machine moved in the same tick shows at the next one, as in AE2's terminals.
Blocks with other jobs too. The ME Interface and Refined Storage's Interface keep items of their own, so they are also inventories, and a block that holds Forge Energy is also an Energy blocks block. The network's methods come first: on an interface, count() and push() work on the whole network, while list(), get() and size() read the interface's own slots.
Each call reads the block again, so a wrapped block never goes stale. When something is wrong, the call stops the program with an error you can catch with pcall:
| error | when |
|---|---|
ME controller removed | the block was broken or replaced since peripheral.wrap: also ME interface removed, controller removed, interface removed |
peripheral is not loaded | the chunk of the block is not loaded |
no inventory 'left', no tank 'left' | push, pull, push_fluid or pull_fluid was given a name that is not an inventory (a tank) of the computer |
bad argument #1 to 'craft' (...) | a wrong argument: the message says what was expected |
this version of Applied Energistics 2 has no ... | your version of the mod lacks what the method reads (also Refined Storage) |
Applied Energistics 2 error: ... | the mod itself failed while answering (also Refined Storage error: ...) |
What it holds
me.online()
true while the network has energy and the block works: for an ME Interface, it also has its channel; for Refined Storage, its redstone mode allows it. Offline, every other method sees an empty network.
- boolean
- true while the network works
local me = peripheral.find("me_controller")
while not me.online() do
print("Waiting for the ME network...")
sleep(5)
endSee also storage_network.power()
me.items([pattern])
The items the network holds, one entry per kind: name its id, count how many, display its name in game. The largest stocks come first.
patternstring optional- the items to list, an id with * and ? allowed; every item without it
- table
- a list of {name, count, display}, the most numerous first
for _, it in ipairs(me.items("*_ingot")) do
print(it.count, it.display)
endme.fluids([pattern])
The fluids the network holds, like storage_network.items(): amount is in mB (1000 for a bucket).
patternstring optional- the fluids to list, an id with * and ? allowed; every fluid without it
- table
- a list of {name, amount, display}, amount in mB, the largest first
for _, f in ipairs(me.fluids()) do
print(f.amount / 1000 .. " buckets of " .. f.display)
endme.count([pattern])
How many items the pattern names, all kinds together.
patternstring optional- the items to count, an id with * and ? allowed; every item without it
- number
- how many of them the network holds
if me.count("minecraft:coal") < 64 then
print("Low on coal")
end
print(me.count() .. " items in all")me.amount([pattern])
How much fluid the pattern names, in mB.
patternstring optional- the fluids to measure, an id with * and ? allowed; every fluid without it
- number
- how many mB of them the network holds
print(me.amount("minecraft:lava") / 1000 .. " buckets of lava")How full the storage is. AE2 counts the bytes of the cells in its drives and ME Chests (a 1k cell has 1024 bytes, and each kind of item takes some of them too), Refined Storage the items and mB of its disks and storage blocks. Storage the network reaches through a storage bus or an external storage, and creative storage with no limit, are not counted. With no fluid storage, fluids is {used = 0, total = 0}.
- table
- {items = {used, total}, fluids = {used, total}}
local s = me.storage().items
if s.total > 0 and s.used / s.total > 0.9 then
print("Storage 90% full: add a drive")
endSee also storage_network.count()
Moving items and fluids
me.push(target, item [, count])
Takes items out of the network into an inventory: a chest, a machine, a Create depot. It stops when count items moved, the target is full or the network has no more. The items the target refuses at the last moment go back into the network, or on the ground, never lost.
targetstring- the name of an inventory of the computer ("left", "inventory@12,64,-30"...)
itemstring- the items to move, an id with * and ? allowed
countnumber optional- how many at most, 64 by default
- number
- how many items moved
-- feed a furnace on the right with 8 iron ore
me.push("right", "minecraft:iron_ore", 8)See also storage_network.pull() inventory.push()
me.pull(source [, slot [, count]])
Puts the items of an inventory into the network, like an import bus. What the network has no room for stays in the inventory.
sourcestring- the name of an inventory of the computer
slotnumber optional- the only slot to take from, from 1; every slot without it
countnumber optional- how many at most, 64 by default
- number
- how many items moved
-- empty the chest on the left into the network
while me.pull("left") > 0 do endSee also storage_network.push() inventory.push()
me.push_fluid(target, fluid [, amount])
Takes fluid out of the network into a tank: a Create Fluid Tank, a basin, a boiler.
targetstring- the name of a tank of the computer
fluidstring- the fluids to move, an id with * and ? allowed
amountnumber optional- how many mB at most, 1000 by default
- number
- how many mB moved
me.push_fluid("back", "minecraft:water", 4000) -- 4 bucketsSee also storage_network.pull_fluid() tank.tanks()
me.pull_fluid(source [, amount])
Puts the fluid of a tank into the network: the fluid the tank gives first, as a pipe would take it.
sourcestring- the name of a tank of the computer
amountnumber optional- how many mB at most, 1000 by default
- number
- how many mB moved
local moved = me.pull_fluid("bottom", 8000)
print(moved .. " mB stored")See also storage_network.push_fluid()
Energy
me.power()
The energy the network keeps in its controller and energy cells.
- number
- the energy stored, in AE (AE2) or FE (Refined Storage)
print(me.power() .. " / " .. me.power_capacity())See also storage_network.power_capacity() storage_network.power_usage()
me.power_capacity()
- number
- the most energy the network stores
local share = me.power() / me.power_capacity()
print(math.floor(share * 100) .. "% charged")See also storage_network.power()
me.power_usage()
What the network uses per tick (20 ticks a second): with AE2, its average over the last seconds; with Refined Storage, what its working blocks draw.
- number
- the energy the network uses per tick
local ticks = me.power() / math.max(me.power_usage(), 1)
print("Energy for " .. math.floor(ticks / 20 / 60) .. " minutes")See also storage_network.power()
Crafting
me.craftable([pattern])
The items the network has a pattern for: with AE2, in its pattern providers; with Refined Storage, in its autocrafters.
patternstring optional- the items to list, an id with * and ? allowed; every item without it
- table
- a list of {name, display}, by id
for _, it in ipairs(me.craftable()) do
print(it.display)
endSee also storage_network.craft()
Asks the network to craft, like a player in a crafting terminal. The mod plans the job first, which takes a few ticks: the program waits for the plan (20 seconds at most), then the job starts and craft returns {ok = true}, while the crafting itself goes on. When it cannot start, ok is false and error tells why:
itemstring- the id of the item to craft
countnumber optional- how many, 1 by default, up to 1048576
- table
- {ok = true} once the job started, else {ok = false, error, missing}
| error | why |
|---|---|
offline | the network is offline |
not_craftable | no pattern makes that item |
missing_resources | the ingredients are not all there: missing lists what lacks, {name, count, display} each |
no_cpu | AE2: the network has no crafting CPU working |
cpu_busy | AE2: every crafting CPU big enough is busy |
cpu_too_small | AE2: no crafting CPU has the bytes for this job |
cycle | Refined Storage: the patterns make each other in a loop |
too_many | Refined Storage: the amounts are too large to plan |
timed_out | the plan took more than 20 seconds |
failed | the mod refused the job for another reason |
local r = me.craft("minecraft:piston", 16)
if r.ok then
print("Crafting 16 pistons")
elseif r.error == "missing_resources" then
for _, it in ipairs(r.missing) do
print("Missing " .. it.count .. " " .. it.display)
end
else
print("Cannot craft: " .. r.error)
endSee also storage_network.crafting() storage_network.cancel() storage_network.cpus()
me.crafting()
The jobs running: what each one makes, how many in all, and how far it is (from 0 to 1). A job leaves the list once its items are in the network.
- table
- a list of {name, count, progress, display}, progress from 0 to 1
for _, job in ipairs(me.crafting()) do
print(job.display .. ": " .. math.floor(job.progress * 100) .. "%")
endme.cancel(item)
Stops every job making what the pattern names, like the cancel button of a crafting status screen. The ingredients a job had taken go back into the network.
itemstring- the items whose jobs to stop, an id with * and ? allowed
- number
- how many jobs were stopped
me.cancel("minecraft:piston")See also storage_network.crafting()
me.cpus()
AE2 only: the crafting CPUs of the network. name is the name given to the CPU in game (else "CPU 1", "CPU 2"...), busy whether it runs a job, storage its bytes, coprocessors how many co-processing units it has. A job runs on a free CPU with enough bytes. Refined Storage has no CPUs: its interfaces and controllers have no cpus method.
- table
- a list of {name, busy, storage, coprocessors}
local free = 0
for _, cpu in ipairs(me.cpus()) do
if not cpu.busy then free = free + 1 end
end
print(free .. " crafting CPU(s) free")Example: keeping a stock
Every minute, the computer tops up a list of items to a level, crafting what is missing: a few lines that replace a row of level emitters and crafting cards.
local me = peripheral.find("me_controller")
local stock = {["minecraft:piston"] = 32, ["minecraft:torch"] = 256, ["create:andesite_alloy"] = 128}
while true do
for id, wanted in pairs(stock) do
local have = me.count(id)
if have < wanted and #me.crafting() < 4 then
local r = me.craft(id, wanted - have)
if not r.ok then print(id .. ": " .. r.error) end
end
end
sleep(60)
endExample: a dashboard of the network
On the computer's screen (and the monitors joined to it): the storage, the energy and the jobs running, refreshed every 5 seconds.
local me = peripheral.find("rs_controller")
while true do
local s = me.storage().items
local lines = {
"Items: " .. me.count() .. " (" .. math.floor(100 * s.used / math.max(s.total, 1)) .. "% full)",
"Energy: " .. math.floor(100 * me.power() / math.max(me.power_capacity(), 1)) .. "%",
}
for _, job in ipairs(me.crafting()) do
lines[#lines + 1] = job.display .. " x" .. job.count .. " " .. math.floor(job.progress * 100) .. "%"
end
term.clear()
for i, line in ipairs(lines) do
term.set_cursor(1, i)
term.write(line)
end
sleep(5)
end