]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - doc/lua_api.txt
Update Lua API documentation to include minetest.get_modnames()
[dragonfireclient.git] / doc / lua_api.txt
index 61bc8e1c22b98a01d5babe4f72dad54aef42c63b..d5797d17193a4936c632c8221b1d1a6ef89df566 100644 (file)
@@ -1,4 +1,4 @@
-Minetest Lua Modding API Reference 0.4.dev
+Minetest Lua Modding API Reference 0.4.0
 ==========================================
 More information at http://c55.me/minetest/
 
@@ -280,6 +280,61 @@ param2 is reserved for the engine when any of these are used:
 
 Nodes can also contain extra data. See "Node Metadata".
 
+Node drawtypes
+---------------
+There are a bunch of different looking node types. These are mostly just
+copied from Minetest 0.3; more may be made in the future.
+
+Look for examples in games/minimal or games/minetest_game.
+
+- normal
+- airlike
+- liquid
+- flowingliquid
+- glasslike
+- allfaces
+- allfaces_optional
+- torchlike
+- signlike
+- plantlike
+- fencelike
+- raillike
+- nodebox -- See below. EXPERIMENTAL
+
+Node boxes
+-----------
+Node selection boxes are defined using "node boxes"
+
+The "nodebox" node drawtype allows defining visual of nodes consisting of
+arbitrary number of boxes. It allows defining stuff like stairs. Only the
+"fixed" box type is supported for these.
+^ Please note that this is still experimental, and may be incompatibly
+  changed in the future.
+
+A nodebox is defined as any of:
+{
+    -- A normal cube; the default in most things
+    type = "regular"
+}
+{
+    -- A fixed box (facedir param2 is used, if applicable)
+    type = "fixed",
+    fixed = box OR {box1, box2, ...}
+}
+{
+    -- A box like the selection box for torches
+    -- (wallmounted param2 is used, if applicable)
+    type = "wallmounted",
+    wall_top = box,
+    wall_bottom = box,
+    wall_side = box
+}
+
+A box is defined as:
+  {x1, y1, z1, x2, y2, z2}
+A box of a regular node would look like:
+  {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
+
 Representations of simple things
 --------------------------------
 Position/vector:
@@ -287,6 +342,11 @@ Position/vector:
 Currently the API does not provide any helper functions for addition,
 subtraction and whatever; you can define those that you need yourself.
 
+pointed_thing:
+  {type="nothing"}
+  {type="node", under=pos, above=pos}
+  {type="object", ref=ObjectRef}
+
 Items
 ------
 Node (register_node):
@@ -658,6 +718,8 @@ minetest namespace reference
 minetest.get_current_modname() -> string
 minetest.get_modpath(modname) -> eg. "/home/user/.minetest/usermods/modname"
 ^ Useful for loading additional .lua modules or static data from mod
+minetest.get_modnames() -> list of installed mods
+^ Return a list of installed mods, sorted alphabetically
 minetest.get_worldpath() -> eg. "/home/user/.minetest/world"
 ^ Useful for storing custom data
 minetest.is_singleplayer()
@@ -699,6 +761,10 @@ minetest.register_on_respawnplayer(func(ObjectRef))
 ^ Called when player is to be respawned
 ^ Called _before_ repositioning of player occurs
 ^ return true in func to disable regular player placement
+minetest.register_on_joinplayer(func(ObjectRef))
+^ Called when a player joins the game
+minetest.register_on_leaveplayer(func(ObjectRef))
+^ Called when a player leaves the game
 minetest.register_on_chat_message(func(name, message))
 
 Other registration functions:
@@ -765,6 +831,13 @@ minetest.get_craft_result(input) -> output, decremented_input
 ^ output.item = ItemStack, if unsuccessful: empty ItemStack
 ^ output.time = number, if unsuccessful: 0
 ^ decremented_input = like input
+minetest.get_craft_recipe(output) -> input
+^ output is a node or item type such as 'default:torch'
+^ input.method = 'normal' or 'cooking' or 'fuel'
+^ input.width = for example 3
+^ input.items = for example { stack 1, stack 2, stack 3, stack 4,
+                              stack 5, stack 6, stack 7, stack 8, stack 9 }
+^ input.items = nil if no recipe found
 
 Defaults for the on_* item definition functions:
 (These return the leftover itemstack)
@@ -933,8 +1006,8 @@ LuaEntitySAO-only: (no-op for other objects)
 - settexturemod(mod)
 - setsprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
 -           select_horiz_by_yawpitch=false)
-- ^ Select sprite from spritesheet with optional animation and DM-style
--   texture selection based on yaw relative to camera
+  ^ Select sprite from spritesheet with optional animation and DM-style
+    texture selection based on yaw relative to camera
 - get_entity_name() (DEPRECATED: Will be removed in a future version)
 - get_luaentity()
 Player-only: (no-op for other objects)
@@ -943,6 +1016,10 @@ Player-only: (no-op for other objects)
 - get_look_dir(): get camera direction as a unit vector
 - get_look_pitch(): pitch in radians
 - get_look_yaw(): yaw in radians (wraps around pretty randomly as of now)
+- set_inventory_formspec(formspec)
+  ^ Redefine player's inventory form
+  ^ Should usually be called in on_joinplayer
+- get_inventory_formspec() -> formspec string
 
 InvRef: Reference to an inventory
 methods:
@@ -1036,7 +1113,9 @@ Definition tables
 
 Object Properties
 {
+    hp_max = 1,
     physical = true,
+    weight = 5,
     collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
     visual = "cube"/"sprite"/"upright_sprite",
     visual_size = {x=1, y=1},
@@ -1045,6 +1124,7 @@ Object Properties
     initial_sprite_basepos = {x=0, y=0},
     is_visible = true,
     makes_footstep_sound = false,
+    automatic_rotate = false,
 }
 
 Entity definition (register_entity)
@@ -1100,10 +1180,19 @@ Item definition (register_node, register_craftitem, register_tool)
             choppy={times={[3]=0.90}, maxwear=0.05, maxlevel=0}
         }
     }
+    node_placement_prediction = nil,
+    ^ If nil and item is node, prediction is made automatically
+    ^ If nil and item is not a node, no prediction is made
+    ^ If "" and item is anything, no prediction is made
+    ^ Otherwise should be name of node which the client immediately places
+      on ground when the player places the item. Server will always update
+      actual result to client in a short moment.
 
     on_place = func(itemstack, placer, pointed_thing),
+    ^ Shall place item and return the leftover itemstack
     ^ default: minetest.item_place
     on_drop = func(itemstack, dropper, pos),
+    ^ Shall drop item and return the leftover itemstack
     ^ default: minetest.item_drop
     on_use = func(itemstack, user, pointed_thing),
     ^  default: nil
@@ -1114,17 +1203,29 @@ Item definition (register_node, register_craftitem, register_tool)
     ^ The default functions handle regular use cases.
 }
 
+Tile definition:
+- "image.png"
+- {name="image.png", animation={Tile Animation definition}}
+- {name="image.png", backface_culling=bool}
+  ^ backface culling only supported in special tiles
+- deprecated still supported field names:
+  - image -> name
+
+Tile animation definition:
+- {type="vertical_frames", aspect_w=16, aspect_h=16, length=3.0}
+
 Node definition (register_node)
 {
     <all fields allowed in item definitions>,
 
-    drawtype = "normal",
+    drawtype = "normal", -- See "Node drawtypes"
     visual_scale = 1.0,
-    tile_images = {"default_unknown_block.png"},
-    special_materials = {
-        {image="", backface_culling=true},
-        {image="", backface_culling=true},
-    },
+    tiles = {tile definition 1, def2, def3, def4, def5, def6},
+    ^ List can be shortened to needed length
+    ^ Old field name: tile_images
+    special_tiles = {tile definition 1, Tile definition 2},
+    ^ List can be shortened to needed length
+    ^ Old field name: special_materials
     alpha = 255,
     post_effect_color = {a=0, r=0, g=0, b=0},
     paramtype = "none",
@@ -1144,7 +1245,8 @@ Node definition (register_node)
     liquid_viscosity = 0,
     light_source = 0,
     damage_per_second = 0,
-    selection_box = {type="regular"},
+    node_box = {type="regular"}, -- See "Node boxes"
+    selection_box = {type="regular"}, -- See "Node boxes"
     legacy_facedir_simple = false, -- Support maps made in and before January 2012
     legacy_wallmounted = false, -- Support maps made in and before January 2012
     sounds = {