Energy blocks
Any block that holds Forge Energy (FE), from the mods that add electricity to Create: how much it holds, and how much it can hold.
Minecraft and Create have no electricity, but many mods add it with the same unit, Forge Energy (FE): the batteries, motors, wires and machines of Create Crafts & Additions, Create: New Age and many others. Any block that holds FE is a peripheral of type energy. A program reads how much energy it holds and how much it can hold: enough for a charge gauge, an alarm before a battery runs flat, or a switch that starts a generator when the stock gets low.
local cell = peripheral.wrap("left")
print(cell.energy() .. " / " .. cell.energy_capacity() .. " FE")cell.energy() | The Forge Energy the block holds now, through the face that touches the computer or the cable. |
cell.energy_capacity() | How much Forge Energy the block can hold. With energy(), it gives how full the block is: |
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 energy@120,64,-35 when energy is all it does. Like inventories and tanks, a block is seen through the face that touches the computer or the cable: a block that only shows its energy on some faces has to touch through one of them.
A type that completes others. energy comes last, after the precise types: an Electric Motor of Crafts & Additions is an electric_motor first, then kinetic, then energy, and its object has the methods of all three. So peripheral.find("energy") may find a motor before the battery you meant: on a network with several energy blocks, wrap the one you want by its name. The methods are named energy and energy_capacity, so they never hide a method of a precise type (a kinetic block's capacity() is the stress capacity of its network).
Units. Energy is counted in FE. A machine's transfer rate is in FE per tick (20 ticks a second). Each mod sizes its blocks as it likes: an Accumulator of Crafts & Additions holds 2,000,000 FE per block by default, a creative block answers 2147483647 (the largest number FE can count). When the block is not an energy block any more (broken, replaced), the call stops the program with not an energy storage anymore.
Reading
cell.energy()
The Forge Energy the block holds now, through the face that touches the computer or the cable.
- number
- the energy the block holds, in FE
local cell = peripheral.wrap("left")
print(cell.energy() .. " FE")See also energy.energy_capacity()
cell.energy_capacity()
How much Forge Energy the block can hold. With energy(), it gives how full the block is:
- number
- the most energy the block holds, in FE
local cell = peripheral.wrap("left")
local cap = cell.energy_capacity()
if cap > 0 then
print(math.floor(cell.energy() / cap * 100) .. " %")
endSome blocks answer 0 (they pass energy on and keep none), or a huge number (a creative block, a whole wire network): test the capacity before dividing by it.
See also energy.energy()
Example: a generator that starts when the charge is low
A battery on the left of the computer; a generator that runs while redstone powers it, on top. Below 20 % the computer starts the generator, above 90 % it stops it: between the two, it leaves it as it is, so the generator does not flicker on and off.
local cell = peripheral.wrap("left")
local running = false
while true do
local share = cell.energy() / cell.energy_capacity()
if share < 0.2 then
running = true
elseif share > 0.9 then
running = false
end
rs.set("top", running)
print(string.format("%d %%, generator %s", math.floor(share * 100), running and "on" or "off"))
sleep(5)
end