Node¶
Manipulate and get information’s about nodes.
Nodes are defined as dicts in the form
>>> {'param1': 15, 'name': 'air', 'param2': 0, 'x': -158.67400138786, 'y': 3.5000000521541, 'z': -16.144999935403}
The keys “param1” and “param2” are optional storage variables.
-
class
miney.
Node
(mt: miney.minetest.Minetest)[source]¶ Manipulate and get information’s about nodes.
Node manipulation is currently tested for up to 25.000 nodes, more optimization will come later
-
get
(position: dict, position2: dict = None, relative: bool = True, offset: dict = None) → Union[dict, list][source]¶ Get the node at given position. It returns a dict with the node definition. This contains the “x”, “y”, “z”, “param1”, “param2” and “name” keys, where “name” is the node type like “default:dirt”.
If also position2 is given, this function returns a list of dicts with node definitions. This list contains a cuboid of definitions with the diagonal between position and position2.
You can get a list of all available node types with
type
.- Parameters
position – A dict with x,y,z keys
position2 – Another point, to get multiple nodes as a list
relative – Return relative or absolute positions
offset – A dict with “x”, “y”, “z” keys. All node positions will be added with this values.
- Returns
The node type on this position
-
set
(nodes: Union[dict, list], name: str = None, offset: dict = None) → None[source]¶ Set a single or multiple nodes at given position to another node type (something like mt.node.type.default.apple). You can get a list of all available nodes with
type
- A node is defined as a dict with these keys:
“x”, “y”, and “z” keys to define the absolute position
“name” for a the node type like “default:dirt” (you can also get that from mt.node.type.default.dirt). Dicts without name will be set as “air”
some other optional minetest parameters
The nodes parameter can be a single dict with the above parameters or a list of these dicts for bulk spawning.
- Examples
Set a single node over :
>>> mt.node.set(mt.player[0].nodes, mt.node)
- Parameters
nodes – A dict or a list of dicts with node definitions
name – a type name like “default:dirt” as string or from
type
. This overrides
node names defined in the
nodes
dict :param offset: A dict with “x”, “y”, “z” keys. All node positions will be added with this values.
-
property
type
¶ All available node types in the game, sorted by categories. In the end it just returns the corresponding minetest type string, so mt.node.types.default.dirt returns the string ‘default:dirt’. It’s a nice shortcut in REPL, cause with auto completion you have only pressed 2-4 keys to get to your type.
- Examples
Directly access a type:
>>> mt.node.type.default.dirt 'default:dirt'
Iterate over all available types:
>>> for node_type in mt.node.type: >>> print(node_type) default:pine_tree default:dry_grass_5 farming:desert_sand_soil ... (there should be over 400 different types) >>> print(len(mt.node.type)) 421
Get a list of all types:
>>> list(mt.node.type) ['default:pine_tree', 'default:dry_grass_5', 'farming:desert_sand_soil', ...
Add 99 dirt to player “IloveDirt“‘s inventory:
>>> mt.player.IloveDirt.inventory.add(mt.node.type.default.dirt, 99)
- Return type
TypeIterable
- Returns
TypeIterable
object with categories. Look at the examples above for usage.
-