]> git.lizzy.rs Git - minetest.git/blobdiff - doc/client_lua_api.md
Add function to get server info.
[minetest.git] / doc / client_lua_api.md
index d68f90deca62fd52ef64cf921c7a2f7408142e12..b76a406eaf594568c32bb74581dca072f5ce3330 100644 (file)
@@ -667,6 +667,8 @@ Call these functions only at load time!
     * Called when the local player punches a node
     * Newest functions are called first
     * If any function returns true, the punch is ignored
+* `minetest.register_on_placenode(function(pointed_thing, node))`    
+    * Called when a node has been placed
 ### Sounds
 * `minetest.sound_play(spec, parameters)`: returns a handle
     * `spec` is a `SimpleSoundSpec`
@@ -691,6 +693,8 @@ Call these functions only at load time!
 ### Player
 * `minetest.get_wielded_item()`
     * Returns the itemstack the local player is holding
+* `minetest.localplayer`
+    * Reference to the LocalPlayer object. See `LocalPlayer` class reference for methods.
 
 ### Client Environment
 * `minetest.get_player_names()`
@@ -698,9 +702,10 @@ Call these functions only at load time!
 * `minetest.disconnect()`
     * Disconnect from the server and exit to main menu.
     * Returns `false` if the client is already disconnecting otherwise returns `true`.
-* `minetest.get_protocol_version()`
-    * Returns the protocol version of the server.
-    * Might not be accurate at start up as the client might not be connected to the server yet, in that case it will return 0.
+* `minetest.take_screenshot()`
+    * Take a screenshot.
+* `minetest.get_server_info()`
+    * Returns [server info](#server-info).
 
 ### Misc.
 * `minetest.parse_json(string[, nullvalue])`: returns something
@@ -777,7 +782,120 @@ An interface to manipulate minimap on client UI
 * `get_angle()`: returns the current minimap angle in degrees
 * `set_mode(mode)`: sets the minimap mode (0 to 6)
 * `get_mode()`: returns the current minimap mode
-* `toggle_shape()`: toggles minimap shape to round or square.
+* `set_shape(shape)`: Sets the minimap shape. (0 = square, 1 = round)
+* `get_shape()`: Gets the minimap shape. (0 = square, 1 = round)
+
+### LocalPlayer
+An interface to retrieve information about the player. The player is
+not accessible until the client is fully done loading and therefore
+not at module init time.
+
+To get the localplayer handle correctly, use `on_connect()` as follows:
+
+```lua
+local localplayer
+minetest.register_on_connect(function()
+        localplayer = minetest.localplayer
+end)
+```
+
+Methods:
+
+* `get_pos()`
+    * returns current player current position
+* `get_velocity()`
+    * returns player speed vector
+* `get_hp()`
+    * returns player HP
+* `get_name()`
+    * returns player name
+* `is_attached()`
+    * returns true if player is attached
+* `is_touching_ground()`
+    * returns true if player touching ground
+* `is_in_liquid()`
+    * returns true if player is in a liquid (This oscillates so that the player jumps a bit above the surface)
+* `is_in_liquid_stable()`
+    * returns true if player is in a stable liquid (This is more stable and defines the maximum speed of the player)
+* `get_liquid_viscosity()`
+    * returns liquid viscosity (Gets the viscosity of liquid to calculate friction)
+* `is_climbing()`
+    * returns true if player is climbing
+* `swimming_vertical()`
+    * returns true if player is swimming in vertical
+* `get_physics_override()`
+    * returns:
+
+```lua
+    {
+        speed = float,
+        jump = float,
+        gravity = float,
+        sneak = boolean,
+        sneak_glitch = boolean
+    }
+```
+
+* `get_override_pos()`
+    * returns override position
+* `get_last_pos()`
+    * returns last player position before the current client step
+* `get_last_velocity()`
+    * returns last player speed
+* `get_breath()`
+    * returns the player's breath
+* `get_look_dir()`
+    * returns look direction vector
+* `get_look_horizontal()`
+    * returns look horizontal angle
+* `get_look_vertical()`
+    * returns look vertical angle
+* `get_eye_pos()`
+    * returns the player's eye position
+* `get_eye_offset()`
+    * returns the player's eye shift vector
+* `get_movement_acceleration()`
+    * returns acceleration of the player in different environments:
+
+```lua
+    {
+       fast = float,
+       air = float,
+       default = float,
+    }
+```
+
+* `get_movement_speed()`
+    * returns player's speed in different environments:
+
+```lua
+    {
+       walk = float,
+       jump = float,
+       crouch = float,
+       fast = float,
+       climb = float,
+    }
+```
+
+* `get_movement()`
+    * returns player's movement in different environments:
+
+```lua
+    {
+       liquid_fluidity = float,
+       liquid_sink = float,
+       liquid_fluidity_smooth = float,
+       gravity = float,
+    }
+```
+
+* `get_last_look_horizontal()`:
+    * returns last look horizontal angle
+* `get_last_look_vertical()`:
+    * returns last look vertical angle
+* `get_key_pressed()`:
+    * returns last key typed by the player
 
 ### Settings
 An interface to read config files in the format of `minetest.conf`.
@@ -813,9 +931,18 @@ Can be obtained via `minetest.get_meta(pos)`.
     {
         params = "<name> <privilege>", -- Short parameter description
         description = "Remove privilege from player", -- Full description
-        func = function(param), -- Called when command is run.
-                                      -- Returns boolean success and text output.
+        func = function(param),        -- Called when command is run.
+                                       -- Returns boolean success and text output.
     }
+### Server info
+```lua
+{
+       address = "minetest.example.org", -- The domain name/IP address of a remote server or "" for a local server.
+       ip = "203.0.113.156",             -- The IP address of the server.
+       port = 30000,                     -- The port the client is connected to.
+       protocol_version = 30             -- Will not be accurate at start up as the client might not be connected to the server yet, in that case it will be 0.
+}
+```
 
 Escape sequences
 ----------------