X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=doc%2Flua_api.txt;h=25653dd0f55de8d8596d16d642540976744d4e3e;hb=5608f12f9b4e77936436048abf01b4d7edc74871;hp=c09a5815faa5e0bf16ca5b75442f2f23aeca4302;hpb=440e9cdbef19d154f134a85c7e2601f0aff63459;p=dragonfireclient.git diff --git a/doc/lua_api.txt b/doc/lua_api.txt index c09a5815f..25653dd0f 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -464,6 +464,12 @@ dump2(obj, name="_", dumped={}) ^ Return object serialized as a string, handles reference loops dump(obj, dumped={}) ^ Return object serialized as a string +string:split(separator) +^ eg. string:split("a,b", ",") == {"a","b"} +string:trim() +^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar" +minetest.pos_to_string({x=X,y=Y,z=Z}) -> "(X,Y,Z)" +^ Convert position to a printable string minetest namespace reference ----------------------------- @@ -480,6 +486,7 @@ minetest.log(line) minetest.log(loglevel, line) ^ loglevel one of "error", "action", "info", "verbose" +Registration functions: (Call these only at load time) minetest.register_entity(name, prototype table) minetest.register_abm(abm definition) minetest.register_node(name, node definition) @@ -487,7 +494,6 @@ minetest.register_tool(name, item definition) minetest.register_craftitem(name, item definition) minetest.register_alias(name, convert_to) minetest.register_craft(recipe) - minetest.register_globalstep(func(dtime)) minetest.register_on_placenode(func(pos, newnode, placer)) minetest.register_on_dignode(func(pos, oldnode, digger)) @@ -499,27 +505,97 @@ minetest.register_on_respawnplayer(func(ObjectRef)) ^ return true in func to disable regular player placement ^ currently called _before_ repositioning of player occurs minetest.register_on_chat_message(func(name, message)) - -minetest.add_to_creative_inventory(itemstring) +minetest.register_chatcommand(cmd, chatcommand definition) +minetest.register_privilege(name, definition) +^ definition: "description text" +^ definition: { + description = "description text", + give_to_singleplayer = boolean, -- default: true + } +minetest.register_authentication_handler(handler) +^ See minetest.builtin_auth_handler in builtin.lua for reference + +Setting-related: +minetest.setting_set(name, value) minetest.setting_get(name) -> string or nil minetest.setting_getbool(name) -> boolean value or nil +minetest.add_to_creative_inventory(itemstring) +Authentication: +minetest.notify_authentication_modified(name) +^ Should be called by the authentication handler if privileges change. +^ To report everybody, set name=nil. +minetest.get_password_hash(name, raw_password) +^ Convert a name-password pair to a password hash that minetest can use +minetest.string_to_privs(str) -> {priv1=true,...} +minetest.privs_to_string(privs) -> "priv1,priv2,..." +^ Convert between two privilege representations +minetest.set_player_password(name, password_hash) +minetest.set_player_privs(name, {priv1=true,...}) +minetest.get_player_privs(name) -> {priv1=true,...} +minetest.auth_reload() +^ These call the authentication handler +minetest.check_player_privs(name, {priv1=true,...}) -> bool, missing_privs +^ A quickhand for checking privileges + +Chat: minetest.chat_send_all(text) minetest.chat_send_player(name, text) -minetest.get_player_privs(name) -> set of privs + +Inventory: minetest.get_inventory(location) -> InvRef ^ location = eg. {type="player", name="celeron55"} {type="node", pos={x=, y=, z=}} +Item handling: +minetest.inventorycube(img1, img2, img3) +^ Returns a string for making an image of a cube (useful as an item image) +minetest.get_pointed_thing_position(pointed_thing, above) +^ Get position of a pointed_thing (that you can get from somewhere) +minetest.dir_to_facedir(dir) +^ Convert a vector to a facedir value, used in param2 for paramtype2="facedir" +minetest.dir_to_wallmounted(dir) +^ Convert a vector to a wallmounted value, used for paramtype2="wallmounted" +minetest.get_node_drops(nodename, toolname) +^ Returns list of item names. +^ Note: This will be removed or modified in a future version. + +Defaults for the on_* item definition functions: +(These return the leftover itemstack) +minetest.item_place_node(itemstack, placer, pointed_thing) +^ Place item as a node +minetest.item_place_object(itemstack, placer, pointed_thing) +^ Place item as-is +minetest.item_place(itemstack, placer, pointed_thing) +^ Use one of the above based on what the item is. +minetest.item_drop(itemstack, dropper, pos) +^ Drop the item +minetest.item_eat(hp_change, replace_with_item) +^ Eat the item. replace_with_item can be nil. + +Defaults for the on_punch and on_dig node definition callbacks: +minetest.node_punch(pos, node, puncher) +^ Calls functions registered by minetest.register_on_punchnode() +minetest.node_dig(pos, node, digger) +^ Checks if node can be dug, puts item into inventory, removes node +^ Calls functions registered by minetest.registered_on_dignodes() + +Sounds: minetest.sound_play(spec, parameters) -> handle ^ spec = SimpleSoundSpec ^ parameters = sound parameter table minetest.sound_stop(handle) +Timing: minetest.after(time, func, param) ^ Call function after time seconds ^ param is optional; to pass multiple parameters, pass a table. +Random: +minetest.get_connected_players() -> list of ObjectRefs +minetest.hash_node_position({x=,y=,z=}) -> 48-bit integer +^ Gives a unique hash number for a node position (16+16+16=48bit) + Global objects: minetest.env - environment reference @@ -561,15 +637,22 @@ methods: ^ Returns nil for unloaded area - get_node_light(pos, timeofday) -> 0...15 or nil ^ timeofday: nil = current time, 0 = night, 0.5 = day -- add_entity(pos, name): Returns ObjectRef or nil if failed -- add_item(pos, itemstring) -- add_rat(pos) -- add_firefly(pos) +- add_entity(pos, name): Spawn Lua-defined entity at position + ^ Returns ObjectRef, or nil if failed +- add_item(pos, itemstring): Spawn item + ^ Returns ObjectRef, or nil if failed - get_meta(pos) -- Get a NodeMetaRef at that position - get_player_by_name(name) -- Get an ObjectRef to a player - get_objects_inside_radius(pos, radius) - set_timeofday(val): val: 0...1; 0 = midnight, 0.5 = midday - get_timeofday() +- find_node_near(pos, radius, nodenames) -> pos or nil + ^ nodenames: eg. {"ignore", "group:tree"} or "default:dirt" +- get_perlin(seeddiff, octaves, persistence, scale) + ^ Return world-specific perlin noise (int(worldseed)+seeddiff) +Deprecated: +- add_rat(pos): Add C++ rat object (no-op) +- add_firefly(pos): Add C++ firefly object (no-op) NodeMetaRef (this stuff is subject to change in a future version) methods: @@ -611,6 +694,8 @@ methods: - get_wield_index(): returns the index of the wielded item - get_wielded_item() -> ItemStack - set_wielded_item(item): replaces the wielded item, returns true if successful +- set_armor_groups({group1=rating, group2=rating, ...}) +- set_properties(object property table) LuaEntitySAO-only: (no-op for other objects) - setvelocity({x=num, y=num, z=num}) - getvelocity() -> {x=num, y=num, z=num} @@ -623,7 +708,6 @@ LuaEntitySAO-only: (no-op for other objects) - select_horiz_by_yawpitch=false) - ^ Select sprite from spritesheet with optional animation and DM-style - texture selection based on yaw relative to camera -- set_armor_groups({group1=rating, group2=rating, ...}) - get_entity_name() (DEPRECATED: Will be removed in a future version) - get_luaentity() Player-only: (no-op for other objects) @@ -686,6 +770,13 @@ methods: (max - min) must be 32767 or <= 6553 due to the simple implementation making bad distribution otherwise. +PerlinNoise: A perlin noise generator +- Can be created via PerlinNoise(seed, octaves, persistence, scale) +- Also minetest.env:get_perlin(seeddiff, octaves, persistence, scale) +methods: +- get2d(pos) -> 2d noise value at pos={x=,y=} +- get3d(pos) -> 3d noise value at pos={x=,y=,z=} + Registered entities -------------------- - Functions receive a "luaentity" as self: @@ -714,26 +805,40 @@ Registered entities Definition tables ------------------ -Entity definition (register_entity) +Object Properties { physical = true, collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, - visual = "cube"/"sprite", + visual = "cube"/"sprite"/"upright_sprite", visual_size = {x=1, y=1}, - textures = {texture,texture,texture,texture,texture,texture}, + textures = {}, -- number of required textures depends on visual spritediv = {x=1, y=1}, initial_sprite_basepos = {x=0, y=0}, + is_visible = true, + makes_footstep_sound = false, +} + +Entity definition (register_entity) +{ + (Deprecated: Everything in object properties is read directly from here) + + initial_properties = , + on_activate = function(self, staticdata), on_step = function(self, dtime), on_punch = function(self, hitter), on_rightclick = function(self, clicker), get_staticdata = function(self), + ^ Called sometimes; the string returned is passed to on_activate when + the entity is re-activated from static state + # Also you can define arbitrary member variables here myvariable = whatever, } ABM (ActiveBlockModifier) definition (register_abm) { + -- In the following two fields, also group:groupname will work. nodenames = {"default:lava_source"}, neighbors = {"default:water_source", "default:water_flowing"}, -- (any of these) ^ If left out or empty, any neighbor will do @@ -766,9 +871,14 @@ Item definition (register_node, register_craftitem, register_tool) choppy={times={[3]=0.90}, maxwear=0.05, maxlevel=0} } } - on_drop = func(item, dropper, pos), - on_place = func(item, placer, pointed_thing), - on_use = func(item, user, pointed_thing), + on_drop = func(itemstack, dropper, pos), + on_place = func(itemstack, placer, pointed_thing), + on_use = func(itemstack, user, pointed_thing), + ^ Function must return either nil if no item shall be removed from + inventory, or an itemstack to replace the original itemstack. + eg. itemstack:take_item(); return itemstack + ^ Otherwise, the function is free to do what it wants. + ^ The default functions handle regular use cases. } Node definition (register_node) @@ -858,4 +968,11 @@ Recipe (furnace fuel): burntime = 1, } +Chatcommand definition (register_chatcommand) +{ + params = " ", -- short parameter description + description = "Remove privilege from player", -- full description + privs = {privs=true}, -- require the "privs" privilege to run + func = function(name, param), -- called when command is run +}