Create: Computing AgesBrass Docs
Devices

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.

Needs Applied Energistics 2 or Refined Storage

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 typemod
ME Controllerme_controllerApplied Energistics 2
ME Interface, the block or the part on a cableme_interfaceApplied Energistics 2
Controller, Creative Controllerrs_controllerRefined Storage
Interfacers_interfaceRefined Storage
Brass
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 left
Methods
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.
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:

errorwhen
ME controller removedthe block was broken or replaced since peripheral.wrap: also ME interface removed, controller removed, interface removed
peripheral is not loadedthe 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()

→ boolean

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.

Returns
boolean
true while the network works
Brass
local me = peripheral.find("me_controller")
while not me.online() do
  print("Waiting for the ME network...")
  sleep(5)
end

See 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.

Parameters
pattern string optional
the items to list, an id with * and ? allowed; every item without it
Returns
table
a list of {name, count, display}, the most numerous first
Brass
for _, it in ipairs(me.items("*_ingot")) do
  print(it.count, it.display)
end

See also storage_network.count() storage_network.fluids()

#

me.fluids([pattern])

The fluids the network holds, like storage_network.items(): amount is in mB (1000 for a bucket).

Parameters
pattern string optional
the fluids to list, an id with * and ? allowed; every fluid without it
Returns
table
a list of {name, amount, display}, amount in mB, the largest first
Brass
for _, f in ipairs(me.fluids()) do
  print(f.amount / 1000 .. " buckets of " .. f.display)
end

See also storage_network.amount() storage_network.items()

#

me.count([pattern])

How many items the pattern names, all kinds together.

Parameters
pattern string optional
the items to count, an id with * and ? allowed; every item without it
Returns
number
how many of them the network holds
Brass
if me.count("minecraft:coal") < 64 then
  print("Low on coal")
end
print(me.count() .. " items in all")

See also storage_network.items() storage_network.amount()

#

me.amount([pattern])

How much fluid the pattern names, in mB.

Parameters
pattern string optional
the fluids to measure, an id with * and ? allowed; every fluid without it
Returns
number
how many mB of them the network holds
Brass
print(me.amount("minecraft:lava") / 1000 .. " buckets of lava")

See also storage_network.fluids() storage_network.count()

#

me.storage()

→ table⚙ cost 8

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}.

Returns
table
{items = {used, total}, fluids = {used, total}}
Brass
local s = me.storage().items
if s.total > 0 and s.used / s.total > 0.9 then
  print("Storage 90% full: add a drive")
end

See also storage_network.count()

Moving items and fluids

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.

Parameters
target string
the name of an inventory of the computer ("left", "inventory@12,64,-30"...)
item string
the items to move, an id with * and ? allowed
count number optional
how many at most, 64 by default
Returns
number
how many items moved
Brass
-- 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.

Parameters
source string
the name of an inventory of the computer
slot number optional
the only slot to take from, from 1; every slot without it
count number optional
how many at most, 64 by default
Returns
number
how many items moved
Brass
-- empty the chest on the left into the network
while me.pull("left") > 0 do end

See 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.

Parameters
target string
the name of a tank of the computer
fluid string
the fluids to move, an id with * and ? allowed
amount number optional
how many mB at most, 1000 by default
Returns
number
how many mB moved
Brass
me.push_fluid("back", "minecraft:water", 4000) -- 4 buckets

See also storage_network.pull_fluid() tank.tanks()

#

me.pull_fluid(source [, amount])

→ number

Puts the fluid of a tank into the network: the fluid the tank gives first, as a pipe would take it.

Parameters
source string
the name of a tank of the computer
amount number optional
how many mB at most, 1000 by default
Returns
number
how many mB moved
Brass
local moved = me.pull_fluid("bottom", 8000)
print(moved .. " mB stored")

See also storage_network.push_fluid()

Energy

#

me.power()

→ number

The energy the network keeps in its controller and energy cells.

Returns
number
the energy stored, in AE (AE2) or FE (Refined Storage)
Brass
print(me.power() .. " / " .. me.power_capacity())

See also storage_network.power_capacity() storage_network.power_usage()

#

me.power_capacity()

→ number
Returns
number
the most energy the network stores
Brass
local share = me.power() / me.power_capacity()
print(math.floor(share * 100) .. "% charged")

See also storage_network.power()

#

me.power_usage()

→ number

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.

Returns
number
the energy the network uses per tick
Brass
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.

Parameters
pattern string optional
the items to list, an id with * and ? allowed; every item without it
Returns
table
a list of {name, display}, by id
Brass
for _, it in ipairs(me.craftable()) do
  print(it.display)
end

See also storage_network.craft()

#

me.craft(item [, count])

→ table⏸ Waits⚙ cost 32

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:

Parameters
item string
the id of the item to craft
count number optional
how many, 1 by default, up to 1048576
Returns
table
{ok = true} once the job started, else {ok = false, error, missing}
errorwhy
offlinethe network is offline
not_craftableno pattern makes that item
missing_resourcesthe ingredients are not all there: missing lists what lacks, {name, count, display} each
no_cpuAE2: the network has no crafting CPU working
cpu_busyAE2: every crafting CPU big enough is busy
cpu_too_smallAE2: no crafting CPU has the bytes for this job
cycleRefined Storage: the patterns make each other in a loop
too_manyRefined Storage: the amounts are too large to plan
timed_outthe plan took more than 20 seconds
failedthe mod refused the job for another reason
Brass
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)
end

See also storage_network.crafting() storage_network.cancel() storage_network.cpus()

#

me.crafting()

→ table

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.

Returns
table
a list of {name, count, progress, display}, progress from 0 to 1
Brass
for _, job in ipairs(me.crafting()) do
  print(job.display .. ": " .. math.floor(job.progress * 100) .. "%")
end

See also storage_network.craft() storage_network.cancel()

#

me.cancel(item)

→ number

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.

Parameters
item string
the items whose jobs to stop, an id with * and ? allowed
Returns
number
how many jobs were stopped
Brass
me.cancel("minecraft:piston")

See also storage_network.crafting()

#

me.cpus()

→ table

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.

Returns
table
a list of {name, busy, storage, coprocessors}
Brass
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")

See also storage_network.craft() storage_network.crafting()

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.

Brass
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)
end

Example: 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.

Brass
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