-Minetest Lua Modding API Reference 0.4.dev
+Minetest Lua Modding API Reference 0.4.0
==========================================
More information at http://c55.me/minetest/
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:
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):
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()
^ 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:
^ 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)
- 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)
- 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:
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
^ 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",
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 = {