Minetest¶
This is the starting point for this library. With creating a Minetest object you also connect to minetest.
In this object are all functions that targets minetest itself. There is also some properties inside, to get other objects like players or nodes.
- Example
>>> from miney import Minetest >>> >>> mt = Minetest() >>> >>> # We set the time to midday. >>> mt.time_of_day = 0.5 >>> >>> # Write to the servers log >>> mt.log("Time is set to midday ...")
-
class
miney.
Minetest
([server, playername, password[, port]])[source]¶ The Minetest server object. All other objects are accessable from here. By creating an object you connect to Minetest.
Parameters aren’t required, if you run miney and minetest on the same computer.
If you connect over LAN or Internet to a Minetest server with installed mineysocket, you have to provide a valid playername with a password:
>>> mt = Minetest("192.168.0.2", "MyNick", "secret_password")
Account creation is done by starting Minetest and connect to a server with a username and password. https://wiki.minetest.net/Getting_Started#Play_Online
- Parameters
-
property
chat
¶ Object with chat functions.
- Example
>>> mt.chat.send_to_all("My chat message")
- Returns
miney.Chat
: chat object
-
log
(line: str)[source]¶ Write a line in the servers logfile.
- Parameters
line – The log line
- Returns
None
-
property
nodes
¶ Manipulate and get information’s about node.
- Returns
miney.Nodes
: Nodes manipulation functions
-
on_event
(name: str, run: callable) → None[source]¶ Sets a callback function for specific events.
- Parameters
name – The name of the event
run – A callback function
- Returns
None
-
property
player
¶ Get a single players object.
- Examples
Make a player 5 times faster:
>>> mt.player.MyPlayername.speed = 5
Use a playername from a variable:
>>> player = "MyPlayername" >>> mt.player[player].speed = 5
Get a list of all players
>>> list(mt.player) [<minetest player "MineyPlayer">, <minetest player "SecondPlayer">, ...]
- Returns
miney.Player
: Player related functions
-
receive
(result_id: str = None, timeout: float = None) → Union[str, bool][source]¶ Receive data and events from minetest.
With an optional result_id this function waits for a result with that id by call itself until the right result was received. If lua.run() was used this is not necessary, cause miney already takes care of it.
With the optional timeout the blocking waiting time for data can be changed.
- Example to receive and print all events
>>> while True: >>> print("Event received:", mt.receive())
- Parameters
- Return type
- Returns
Data from mineysocket
-
property
settings
¶ Receive all server settings defined in “minetest.conf”.
- Returns
A dict with all non-default settings.
-
property
time_of_day
¶ Get and set the time of the day between 0 and 1, where 0 stands for midnight, 0.5 for midday.
- Returns
time of day as float.
-
property
tool
¶ All available tools in the game, sorted by categories. In the end it just returns the corresponding minetest tool string, so mt.tool.default.axe_stone returns the string ‘default:axe_stone’. 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 tool:
>>> mt.tool.default.pick_mese 'default:pick_mese'
Iterate over all available types:
>>> for tool_type in mt.tool: >>> print(tool_type) default:shovel_diamond default:sword_wood default:shovel_wood ... (there should be around 34 different tools) >>> print(len(mt.tool)) 34
Get a list of all types:
>>> list(mt.tool) ['default:pine_tree', 'default:dry_grass_5', 'farming:desert_sand_soil', ...
Add a diamond pick axe to the first player’s inventory:
>>> mt.player[0].inventory.add(mt.tool.default.pick_diamond, 1)
- Return type
ToolIterable
- Returns
ToolIterable
object with categories. Look at the examples above for usage.
Objects
Indices and tables