The Minetest Lua API, sfinv and cmsg functions are not listed here.
table.copy(tbl)
Copies table, needed for editing it. The table cannot store userdata, e.g. ItemStacks or NodeMetaRefs.table.count(tbl)
table.filter(tbl, func(value, key))
Returns table with fields that return true when func is called with them. Fields keys are unchanged, as is the given table.func
is called with value as a first argument and key as the second. Has the same restrictions astable.copy
.table.exists(tbl, func(value, key))
Returns true if table has a field that returns true when func is called. Table iteration is stopped when such element is found.table.every(tbl, func(value, key))
Returns true if all table fields return true when func is called. Table iteration is stopped when element returning false is found.table.walk(tbl, func(value, key), condition())
Runs func on all table elements. If condition returns true, iteration stops. Condition argument is optional.table.map(tbl, func(value, key))
Replaces each element of table with function result and returns resulting table. Given table is unchanged. Has the same restrictions astable.copy
.table.remap(tbl)
If tbl is a table with integer keys, some of which are shifted, this function returns a list with same values. Given table is unchanged. All non-integer keys are ignored.table.keys(tbl)
Returns list of keys of table. Given one is unchanged.table.asort(tbl, func(a, b))
Returns iterator going through all table elements in order their values are sorted with func. Useful with associative tables. If func is not given, sorts a table normally.table.sum(tbl)
table.tail(tbl)
Returns table with first element stripped. Given table is unchanged.table.mtail(tbl, multiplier)
Returns table with firstmultiplier
elements stripped.trinium.sort_by_param(x)
Returns sorting function comparing elements' fields with keyx
.trinium.weighted_avg(table)
Table is composed like this: {{a1, b1}, {a2, b2}, ...} Then, this function returns weighted average ofa_i
where weights areb_i
. Example: trinium.weighted_avg({{5, 2}, {8, 1}}) => 6vector.stringify(vec)
Returnsx,y,z
string which can be used in nodemeta ans as more compact storage of coordinates.vector.destringify(str)
Reverse of previous one.trinium.recipe_stringify(arr)
Stringifies recipe. The same format is used in recipes' inputs_string field. Can be used if item order matters.trinium.initialize_inventory(inv, arr)
Initializes inventory: for all (K,V) pairs from arr inventory list K size is set to V.trinium.weighted_random(mas, func)
- func ismath.random
by default
trinium.adequate_text(str)
Returns string capitalized as it was a sentence.trinium.adequate_text2(str)
The same but all underscores are also replaced by spaces.trinium.formspec_restore(str)
Reverse ofminetest.formspec_escape
.trinium.get_item_identifier(stack)
Stack is of type ItemStack. Similar tostack:to_string()
, but also cuts item amount.trinium.roman_number(num)
trinium.register_recipe(type, inputs, outputs, data)
trinium.register_recipe_handler(id, def)
Registers new recipe method (see Recipe Methods).trinium.can_perform(player_knowledge_crystal, id, method)
Basically a wrapper to method'scan_perform
.id
is obtained from recipe registry.trinium.valid_recipe(pattern, method, data)
Checks whether the recipe with given pattern exists. Returns its ID on success and false on failure.trinium.has_inputs_for_recipe(pattern, inv, list)
Checks whether all items needed for recipe are in the given inventory list.trinium.draw_inputs_for_recipe(pattern, inv, list, id)
Takes inputs from given inventory list and returns output list concatenated by semicolon.trinium.register_multiblock(id, def)
Registers new multiblock (see Multiblocks).trinium.mbcr(node_id, multiblock_map)
Changes node_id description to have multiblock components there.trinium.recolor_facedir(pos, n)
trinium.get_color_facedir(pos)
trinium.try_craft(player)
- sets output for player's detached workbenchtrinium.absolute_draw_recipe(table, num)
- drawsnum
th recipe fromtable
Returnsformspec_str
,width
,height
,amount_of_recipes
,current_id
trinium.draw_recipe(item, player, id, tbl, method)
Draws recipe available to player. Returns the same as function above.tbl
is usuallytrinium.recipes.recipes
ortrinium.recipes.usages
.method
can be abscent.trinium.draw_research_recipe(item, num)
- draws recipe for research book
trinium.materials.register_mattype(name, callable(def))
Registers a material type.callable
should register the needed items.def
is a table with following fields:id
name
- the material descriptioncolor
- color formatted as'#RRGGBBAA'
(hex string)color_tbl
- color formatted as{R, G, B}
(R, G, B are numbers)formula
- line wrap followed by formula string colored to grayformula_tbl
- formula formatted as{{'compound1', count1}, ...}
data
types
- list of types material has. No need to check this most time.
trinium.materials.register_interaction(name, def)
Register an interaction between material types, can be used for e.g. setting up recipes.def
is a table with following fields:requirements
- list of material typesapply(name, data)
- function which is fired when all requirements are satisfied.name
is material id anddata
is its data
trinium.materials.new_material(name, def)
- registers materialdef
is a table with following fields:formula
- formula formatted as{{'compound1', count1}, ...}
types
- list of material typescolor
- color formatted as{R, G, B}
(R, G, B are numbers)- If abscent, automatically generates from compounds' colors
description
data
- optional material data Returns object with following methods:generate_data(id)
- generates data (seemat.add_data_generator
)generate_recipe(id)
- generates recipes (seemat.add_recipe_generator
)get(id)
- shortcut for writing"trinium:materials_"..id.."_"..name
All methods return object so they can be chained
trinium.materials.register_element(name, def)
- registers elementary materialdef
is a table with following fields:formula
- string like"Si"
,"H"
(not"H2"
) or"Nq"
color
- color formatted as{R, G, B}
(R, G, B are numbers)- Other data fields include:
melting_point
- melting point in Kelvins, -1 where not applicable
trinium.materials.add_data_generator(name, callback(material_name))
Whenobject:generate_data(name)
is called on material object, generatesname
data field usingcallback
return valuetrinium.materials.add_recipe_generator(name, callback(material_name))
Same as above, except that callback returns nothing andname
can not be recipe method ID
trinium.research.register_chapter(name, def)
Registers research chapter.def
is a table with following fields:texture
- itemstringx
- horizontal coordinate, from 0 to 7y
- vertical coordinate, from 0 to 7name
tier
- integer from 1 to 4create_map
- optional, if present creates a map to use in Enlightener
trinium.research.register_research(name, def)
Registers research.def
is a table with following fields:pre_unlock
- eithertrue
or not present/false
. If true research is unlocked from beginning.texture
- itemstringx
- horizontal coordinate, from 0 to 7y
- vertical coordinate, any integername
text
- Following fields are required when
pre_unlock
isfalse
or not present:color
- either{R, G, B}
or'#RRGGBB'
map
- table of objects with following keys:x
andy
- coordinates of the aspect from 1 to 7aspect
requires_lens
- table with following keys:requirement
- if lens is required, false by defaultcore
- if lens is required, this shows its core materialband_material
- same with band materialcore
andband_material
can be abscent, in that case any material can be usedband_tier
- minimal lens tier, 1 by defaultband_shape
- needed lens shape, any shape can be used by default
trinium.research.grant(pn, name)
- gives player research if all requirements are satisfiedtrinium.research.grant_force(pn, name)
- gives player research and all its requirementstrinium.research.register_aspect(name, def)
Registers an aspect.def
is a table with following fields:texture
- not an itemstring, but a texture!name
req1
- one of the requirements, aspect is basic if this is not presentreq2
- same as above
trinium.tool_system.register_tool_material(name, def)
Registers a tool head material.def
is a table with following fields:name
durability
- note that durability decrease is calculated as 1/(d * 3^l)level
time_mult
- material speed, tools made from stone and sticks only havetime_mult
value of 10, speed scales linearly with thisname
is an itemstring.
trinium.tool_system.register_tool_rod(name, def)
Similar to the method above, except for following:- This item can be used as a tool rod, not a tool head material
- Final item properties are calculated as material_stats * rod_stats
trinium.tool_system.register_template(name, def)
Registers a tool template.name
is a alphanumeric string. Item texture istool_<name>.png
.def
is a table with following fields:name(inputs)
-inputs
is some list of given materialsschematic
- string describing tool scheme:- This is a string which has spaces inside it, 1 word = 1 crafting line.
- All non-space symbols can be either
_
,R
orM
. _
means that no item should be put there.R
is for Rod andM
is for Material.
apply(stack, capabilities)
- function which sets tool capabilitiesstack
is a ItemStack.capabilities
is a table with following fields:time_mult
durability
level
trinium.S(string, ...)
- a general translatortrinium.dump(...)
- logs all inputs, which can be tables but without Userdatatrinium.modulate(num, mod)
This function is close tonum % mod
, with the only difference being this function returningmod
whennum
is fully divisible bymod
.trinium.setting_get(name, default)
trinium.lograndom(min, max)
Should return normal-distributed number between min and max, both sides included. Not well tested though.trinium.get_data_pointer(player_name, file)
- per-world per-player storagetrinium.register_fluid(source_name, flowing_name, source_desc, flowing_desc, color, def)
Registers a fluid.source_name
andflowing_name
are IDs of source and flowing variants;source_desc
andflowing_desc
are their descriptions;def
can have any of the fieldsminetest.register_node
can get, however some of them will be overridden.trinium.register_vein(name, params)
Registers an ore vein.name
is an ID which is not used for now,params
is a table with following fields:ore_list
- list of nodenames to generateore_chances
- list of relative chances of the nodesdensity
- percentage to change a stone node to oreweight
- relative weight of node. Generally 1-3 for very rare, 10 for rare, 50 for common, 100 for very commonmin_height
max_height
trinium.pulsenet.import_to_controller(pos)
- puts controller internal item to network.trinium.advanced_search(begin, serialize(item), vertex(current_item))
Performs BFS on graph whose vertices connected to vertice A are in listvertex(A)
.serialize
is a function that returns item in string/etc form. Returns list of{element, step}
, wherestep >= 2
- distance from begin. Beginning element is not in the list.trinium.search(begin, serialize(item), vertex(item))
Same as previous function, but returns list ofelement
instead of pairs.
Recipe Method is a table with following keys:
input_amount
output_amount
get_input_coords(n)
- should return coords of nth input.get_output_coords(n)
formspec_width
formspec_height
formspec_name
formspec_begin(data)
Can be used to set background/show data/etc. Should return string, returns empty one by default.can_perform(player_name, data)
Returns true if player can perform the recipe. Always is true if abscent. Usually used for checking player's research.test(recipe_data, actual_data)
Returns true if non-input requirements - pressure, temperature, catalyst, time of day, phase of moon, etc. - are satisfied.callback(inputs, outputs, data)
With this key, the recipe can be redirected to other method. Should return string if method changes and any other value in the other case.process_inputs(inputs)
- used by wizards, returns actual inputs table. Can also return -1 to stop recipe registration.process_outputs(outputs)
- can also return -1process_data(data)
- can also return -1recipe_correct(data)
- called during init phase
Multiblock Definition is a table with following keys:
controller
map
A table with values withx
,y
,z
, andname
fields.x
is offset to the right,y
is to the top, andz
is to the back.name
is needed name of the node. These can be any nodes except air/ignore. The multiblock will be tested having these nodes around if field is present. Also multiblock recipes will be generated in this case.activator(region)
Called in casemap
isn't present. Region is a table of objects with following keys:x
- offset relative to controllery
z
name
actual_pos
height_d
- bottom offset to checkheight_u
- top offset to checkwidth
- this is both to the right and leftdepth_b
- backwards offsetdepth_f
- front offsetafter_construct(pos, is_constructed, region)
This function is called when multiblock checking tick is done.is_constructed
is a boolean which is true if map is checked.region
format is the same as with activator.
DataMesh is a table that can have chained methods. The possible methods are:
new()
data()
- gets datadata(smth)
- sets datafilter(func(v, k))
map(func(v, k))
forEach(func(v, k))
exists(func(v, k))
serialize()
copy()
push(element)