11 KiB
technic API
This file documents the functions within the technic modpack for use in mods.
Undocumented API may change at any time.
Tiers
Tier are network types. List of pre-registered tiers:
"LV"
, Low Voltage"MV"
, Medium Voltage"HV"
, High Voltage
Available functions:
technic.register_tier(tier, description)
- Registers a network type (tier)
tier
: string, short name (ex.LV
)description
: string, long name (ex.Low Voltage
)- See also
tiers
Cables
technic.register_cable(tier, size)
- Registers an existing node as cable
tier
: stringsize
: number, visual size of the wire
technic.get_cable_tier(nodename)
- Retrieves the tier assigned to the provided node name
nodename
: string, name of the node- Returns the tier (string) or
nil
technic.is_tier_cable(nodename, tier)
- Tells whether the node
nodename
is the cable of the tiertier
. - Short version of
technic.get_cable_tier(nodename) == tier
- Tells whether the node
technic.register_cable_tier(nodename, tier)
- Register user defined cable to list of known tier cables.
nodename
: string, name of the nodetier
: string, tier name
Machines
The machine type indicates the direction of power flow. List of pre-registered machine types:
technic.receiver = "RE"
: consumes energy. e.g. grindertechnic.producer = "PR"
: provides energy. e.g. solar paneltechnic.producer_receiver = "PR_RE"
supply convertertechnic.battery = "BA"
: stores energy. e.g. LV battery box
Available functions:
technic.register_base_machine(data)
- Registers a new node and defines the underlying machine behaviour.
data
fields: tier
: string, see #Tierstypename
: string, equivalent to the processing type registered bytechnic.register_recipe
. Examples:"cooking"
"alloy"
machine_name
: string, node namemachine_desc
: string, node descriptiondemand
: table, EU consumption values for each upgrade level. Up to three indices. Index 1 == no upgrade. Example:{3000, 2000, 1000}
.upgrade
: (boolean), whether to add upgrade slotsmodname
: (string), mod origintube
: (boolean), whether the machine has Pipeworks connectivitycan_insert
: (func), see Pipeworks documentation- Accepts all inputs by default, if
tube = 1
- See also:
technic.can_insert_unique_stack
- Accepts all inputs by default, if
insert_object
: (func), see Pipeworks documentation- Accepts all inputs by default, if
tube = 1
- See also:
technic.insert_object_unique_stack
- Accepts all inputs by default, if
connect_sides
: (table), see Lua API documentation. Defaults to all directions but front.
- Registers a new node and defines the underlying machine behaviour.
technic.register_machine(tier, nodename, machine_type)
- Register an existing node as machine, bound to the network tier
tier
: string, see #Tiersnodename
: string, node namemachine_type
: string, following options are possible:technic.receiver = "RE"
: Consumes energytechnic.producer = "PR"
: Provides energytechnic.battery = "BA"
: Energy storage
- See also
Machine types
Callbacks for pipeworks item transfer:
technic.can_insert_unique_stack(pos, node, stack, direction)
technic.insert_object_unique_stack(pos, node, stack, direction)
- Functions for the parameters
can_insert
andinsert_object
to avoid filling multiple inventory slots with same type of item.
- Functions for the parameters
Recipes
technic.register_recipe_type(typename, recipedef)
- Registers a new recipe type used for machine processing
typename
: string, name of the recipe type- Fields of
recipedef
:description
: string, descriptor of the recipe typeinput_size
: (numeric), count of input ItemStacks. default 1output_size
: (numeric), count of output ItemStacks. default 1
technic.register_recipe(recipe)
- Registers a individual input/output recipe. Fields of
recipe
: input
: table, integer-indexed list of input ItemStacks.output
: table/ItemStack, single output or list of output ItemStacks.time
: numeric, process time in seconds.
- Registers a individual input/output recipe. Fields of
technic.get_recipe(typename, items)
typename
: string, seetechnic.register_recipe_type
items
: table, integer-indexed list of input ItemStacks.- Returns:
recipe
table on success,nil
otherwise
The following functions can be used to register recipes for a specific machine type:
- Centrifuge
technic.register_separating_recipe(recipe)
- Compressor
technic.register_compressor_recipe(recipe)
- Furnaces (electric, normal)
minetest.register_recipe(recipe)
- Extractor
technic.register_extractor_recipe(recipe)
- Freezer
technic.register_freezer_recipe(recipe)
- Grinder
technic.register_grinder_recipe(recipe)
Tools
technic.register_power_tool(itemname, max_charge)
- Register or configure the maximal charge held by an existing item
craftitem
: string, item or node namemax_charge
: number, maximal EU capacity
Helper functions
Unsorted functions:
technic.EU_string(num)
- Converts num to a human-readable string (see
pretty_num
) and adds theEU
unit - Use this function when showing players energy values
- Converts num to a human-readable string (see
technic.pretty_num(num)
- Converts the number
num
to a human-readable string with SI prefixes
- Converts the number
technic.config:get(name)
- Some configuration function
technic.tube_inject_item(pos, start_pos, velocity, item)
- Same as
pipeworks.tube_inject_item
- Same as
Energy modifiers
technic.set_RE_wear(itemstack, item_load, max_charge)
- Modifies the power tool wear of the given itemstack
itemstack
: ItemStack to modifyitem_load
: number, used energy in EUmax_charge
: number, maximal EU capacity of the tool- The itemdef field
wear_represents
must be set to"technic_RE_charge"
, otherwise this function will do nothing. - Returns the modified itemstack
technic.refill_RE_charge(itemstack)
- This function fully recharges an RE chargeable item.
- If
technic.power_tools[itemstack:get_name()]
isnil
(orfalse
), this function does nothing, else that value is the maximum charge. - The itemstack metadata is changed to contain the charge.
technic.get_charge(itemstack)
- Returns the charge and max charge of the given itemstack.
- If the itemstack is not an RE chargeable item, both return values will be zero.
technic.set_charge(itemstack, charge)
- Modifies the charge of the given itemstack.
Node-specific
technic.get_or_load_node(pos)
- If the mapblock is loaded, it returns the node at pos,
else it loads the chunk and returns
nil
.
- If the mapblock is loaded, it returns the node at pos,
else it loads the chunk and returns
technic.swap_node(pos, nodename)
- Same as
mintest.swap_node
but it only changes the nodename. - It uses
minetest.get_node
before swapping to ensure the new nodename is not the same as the current one.
- Same as
technic.trace_node_ray(pos, dir, range)
- Returns an iteration function (usable in the for loop) to iterate over the node positions along the specified ray.
- The returned positions will not include the starting position
pos
.
technic.trace_node_ray_fat(pos, dir, range)
- Like
technic.trace_node_ray
but includes extra positions near the ray. - The node ray functions are used for mining lasers.
- Like
Item Definition fields
Groups:
technic_<tier> = 1
- Makes the node connect to the cables of the matching tier name
<tier>
: name of the tier, in lowercase (ex.lv
)
technic_machine = 1
- UNRELIABLE. Indicates whether the item or node belongs to technic
connect_sides = {"top", "left", ...}
- Extends the Minetest API. Indicates where the machine can be connected.
Additional definition fields:
<itemdef>.wear_represents = "string"
- Specifies how the tool wear level is handled. Available modes:
"mechanical_wear"
: represents physical damage"technic_RE_charge"
: represents electrical charge
- Specifies how the tool wear level is handled. Available modes:
<itemdef>.technic_run = function(pos, node) ...
- This callback is used to update the node. Modders have to manually change the information about supply etc. in the node metadata.
- Technic-registered machines use this callback by default.
<itemdef>.technic_disabled_machine_name = "string"
- Specifies the machine's node name to use when it's not connected connected to a network
<itemdef>.technic_on_disable = function(pos, node) ...
- This callback is run when the machine is no longer connected to a technic-powered network.
<itemdef>.technic_get_charge = function(itemstack) ...
- Optional callback to overwrite the default charge behaviour.
itemstack
: ItemStack, the tool to analyse- Return values:
charge
: Electrical charge of the toolmax_charge
: Upper charge limit
- Etc.
local charge, maxcharge = itemdef.technic_get_charge(itemstack)
<itemdef>.technic_set_charge = function(itemstack, charge) ...
- Optional callback to overwrite the default charge behaviour.
itemstack
: ItemStack, the tool to updatecharge
: numeric, value between0
andmax_charge
Node Metadata fields
Nodes connected to the network will have one or more of these parameters as meta data:
<tier>_EU_supply
- direction: output- For nodes registered as
PR
orBA
tier - This is the EU value supplied by the node.
- For nodes registered as
<tier>_EU_demand
- direction: output- For nodes registered as
RE
orBA
tier - This is the EU value the node requires to run.
- For nodes registered as
<tier>_EU_input
- direction: input- For nodes registered as
RE
orBA
tier - This is the actual EU value the network can give the node.
- For nodes registered as
<tier>
corresponds to the tier name registered using
technic.register_tier
(ex. LV
). It is possible for the machine to depend on
multiple tiers (or networks).
Manual: Network basics
The switching station is the center of all power distribution on an electric network. This node is used to calculate the power supply of the network and to distribute the power across nodes.
The switching station is the center of all electricity distribution. It collects power from sources (PR), distributes it to sinks (RE), and uses the excess/shortfall to charge and discharge batteries (BA).
As a thumb of rule, "EU" (energy unit) values are expressed in kW.
Network functionality:
- All PR, BA, RE nodes are indexed and tagged with one switching station. The tagging is a workaround to allow more stations to be built without allowing a cheat with duplicating power.
- All the RE nodes are queried for their current EU demand. If the total demand is less than the available power they are all updated with the demand number.
- BA nodes are evenly charged from energy surplus.
- Excess power draw will discharge batteries evenly.
- If the total demand is more than the available power all RE nodes will be shut down. We have a brown-out situation.
Deprecated functions
Following functions are either no longer used by technic, or are planned to be removed soon. Please update mods depending on technic accordingly.
technic.get_RE_item_load
- Scales the tool wear to a certain numeric range
technic.set_RE_item_load
- Scales a certain numeric range to the tool wear