From a87805a9445f280ca71da322c4b32cf357744511 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Tue, 23 Jun 2020 17:43:47 +0200 Subject: test --- builtin/client/chatcommands.lua | 2 +- builtin/client/cheats.lua | 160 + builtin/client/death_formspec.lua | 34 +- builtin/client/init.lua | 3 +- builtin/client/register.lua | 20 + builtin/client/spoof.lua | 4 - builtin/common/misc_helpers.lua | 10 + builtin/settingtypes.txt | 10 +- doc/client_lua_api.md | 1451 -- doc/client_lua_api.txt | 1451 ++ doc/fst_api.md | 171 - doc/fst_api.txt | 171 + doc/lua_api.md | 7828 -------- doc/lua_api.txt | 7828 ++++++++ .../default/.sounds/default_grass_footstep.1.ogg | Bin 0 -> 7014 bytes .../mods/default/sounds/default_break_glass.1.ogg | Bin 0 -> 11130 bytes .../mods/default/sounds/default_break_glass.2.ogg | Bin 0 -> 16058 bytes .../mods/default/sounds/default_break_glass.3.ogg | Bin 0 -> 12257 bytes .../mods/default/sounds/default_chest_close.ogg | Bin 0 -> 10768 bytes .../mods/default/sounds/default_chest_open.ogg | Bin 0 -> 11092 bytes .../mods/default/sounds/default_cool_lava.1.ogg | Bin 0 -> 9583 bytes .../mods/default/sounds/default_cool_lava.2.ogg | Bin 0 -> 7977 bytes .../mods/default/sounds/default_cool_lava.3.ogg | Bin 0 -> 6499 bytes .../mods/default/sounds/default_dig_choppy.ogg | Bin 0 -> 6794 bytes .../mods/default/sounds/default_dig_cracky.ogg | Bin 0 -> 6628 bytes .../mods/default/sounds/default_dig_crumbly.ogg | Bin 0 -> 7567 bytes .../default/sounds/default_dig_dig_immediate.ogg | Bin 0 -> 6714 bytes .../mods/default/sounds/default_dig_metal.ogg | Bin 0 -> 5245 bytes .../sounds/default_dig_oddly_breakable_by_hand.ogg | Bin 0 -> 6940 bytes .../mods/default/sounds/default_dig_snappy.ogg | Bin 0 -> 7258 bytes .../default/sounds/default_dirt_footstep.1.ogg | Bin 0 -> 9155 bytes .../default/sounds/default_dirt_footstep.2.ogg | Bin 0 -> 7553 bytes .../mods/default/sounds/default_dug_metal.1.ogg | Bin 0 -> 7076 bytes .../mods/default/sounds/default_dug_metal.2.ogg | Bin 0 -> 7260 bytes .../mods/default/sounds/default_dug_node.1.ogg | Bin 0 -> 6630 bytes .../mods/default/sounds/default_dug_node.2.ogg | Bin 0 -> 7863 bytes .../mods/default/sounds/default_glass_footstep.ogg | Bin 0 -> 7094 bytes .../default/sounds/default_grass_footstep.1.ogg | Bin 7014 -> 10019 bytes .../default/sounds/default_grass_footstep.2.ogg | Bin 0 -> 10164 bytes .../default/sounds/default_grass_footstep.3.ogg | Bin 0 -> 9989 bytes .../default/sounds/default_gravel_footstep.1.ogg | Bin 0 -> 7326 bytes .../default/sounds/default_gravel_footstep.2.ogg | Bin 0 -> 10136 bytes .../default/sounds/default_gravel_footstep.3.ogg | Bin 0 -> 8086 bytes .../default/sounds/default_gravel_footstep.4.ogg | Bin 0 -> 9017 bytes .../default/sounds/default_hard_footstep.1.ogg | Bin 0 -> 4915 bytes .../default/sounds/default_hard_footstep.2.ogg | Bin 0 -> 4922 bytes .../default/sounds/default_hard_footstep.3.ogg | Bin 0 -> 4919 bytes .../mods/default/sounds/default_item_smoke.ogg | Bin 0 -> 6651 bytes .../default/sounds/default_metal_footstep.1.ogg | Bin 0 -> 6847 bytes .../default/sounds/default_metal_footstep.2.ogg | Bin 0 -> 6926 bytes .../default/sounds/default_metal_footstep.3.ogg | Bin 0 -> 6970 bytes .../mods/default/sounds/default_place_node.1.ogg | Bin 0 -> 8584 bytes .../mods/default/sounds/default_place_node.2.ogg | Bin 0 -> 8644 bytes .../mods/default/sounds/default_place_node.3.ogg | Bin 0 -> 8846 bytes .../default/sounds/default_place_node_hard.1.ogg | Bin 0 -> 6578 bytes .../default/sounds/default_place_node_hard.2.ogg | Bin 0 -> 5623 bytes .../default/sounds/default_place_node_metal.1.ogg | Bin 0 -> 7518 bytes .../default/sounds/default_place_node_metal.2.ogg | Bin 0 -> 7854 bytes .../default/sounds/default_sand_footstep.1.ogg | Bin 0 -> 11897 bytes .../default/sounds/default_sand_footstep.2.ogg | Bin 0 -> 9228 bytes .../default/sounds/default_snow_footstep.1.ogg | Bin 0 -> 7159 bytes .../default/sounds/default_snow_footstep.2.ogg | Bin 0 -> 8726 bytes .../default/sounds/default_snow_footstep.3.ogg | Bin 0 -> 8722 bytes .../default/sounds/default_snow_footstep.4.ogg | Bin 0 -> 6795 bytes .../default/sounds/default_snow_footstep.5.ogg | Bin 0 -> 8126 bytes .../mods/default/sounds/default_tool_breaks.1.ogg | Bin 0 -> 6019 bytes .../mods/default/sounds/default_tool_breaks.2.ogg | Bin 0 -> 8440 bytes .../mods/default/sounds/default_tool_breaks.3.ogg | Bin 0 -> 6875 bytes .../default/sounds/default_water_footstep.1.ogg | Bin 0 -> 31719 bytes .../default/sounds/default_water_footstep.2.ogg | Bin 0 -> 29335 bytes .../default/sounds/default_water_footstep.3.ogg | Bin 0 -> 32107 bytes .../default/sounds/default_water_footstep.4.ogg | Bin 0 -> 3974 bytes .../default/sounds/default_wood_footstep.1.ogg | Bin 0 -> 5967 bytes .../default/sounds/default_wood_footstep.2.ogg | Bin 0 -> 5772 bytes .../minimal/mods/default/sounds/player_damage.ogg | Bin 0 -> 6176 bytes games/minimal/mods/player_api/README.txt | 29 + games/minimal/mods/player_api/api.lua | 144 + games/minimal/mods/player_api/init.lua | 34 + games/minimal/mods/player_api/license.txt | 53 + games/minimal/mods/player_api/mod.conf | 2 + games/minimal/mods/player_api/models/character.b3d | Bin 0 -> 73433 bytes .../minimal/mods/player_api/models/character.blend | Bin 0 -> 632188 bytes games/minimal/mods/player_api/models/character.png | Bin 0 -> 2754 bytes games/minimal/mods/player_api/textures/player.png | Bin 0 -> 142 bytes .../mods/player_api/textures/player_back.png | Bin 0 -> 140 bytes latex/doxygen.sty | 503 + latex/md_README.tex | 463 + latex/refman.log | 156 + latex/refman.tex | 155 + spoof.js | 63 - spoof.txt | 18748 ------------------- src/client/client.cpp | 46 +- src/client/client.h | 7 +- src/client/game.cpp | 887 +- src/client/game.h | 874 + src/defaultsettings.cpp | 9 +- src/gamedef.h | 3 + src/network/clientopcodes.cpp | 1 + src/network/clientpackethandler.cpp | 8 + src/network/networkprotocol.h | 14 +- src/network/serveropcodes.cpp | 1 + src/nodedef.cpp | 24 +- src/script/common/c_content.cpp | 12 +- src/script/cpp_api/s_base.h | 6 + src/script/cpp_api/s_security.cpp | 1 - src/script/lua_api/l_base.cpp | 5 + src/script/lua_api/l_base.h | 3 +- src/script/lua_api/l_client.cpp | 53 + src/script/lua_api/l_client.h | 13 +- src/script/lua_api/l_item.cpp | 21 +- src/script/lua_api/l_localplayer.cpp | 10 + src/script/lua_api/l_localplayer.h | 1 + src/script/lua_api/l_server.cpp | 19 + src/script/lua_api/l_server.h | 3 + src/script/lua_api/l_util.cpp | 5 +- src/script/scripting_client.cpp | 5 + src/server.cpp | 12 + src/server.h | 2 + src/unittest/test.cpp | 6 +- 119 files changed, 12358 insertions(+), 29186 deletions(-) create mode 100644 builtin/client/cheats.lua delete mode 100644 builtin/client/spoof.lua delete mode 100644 doc/client_lua_api.md create mode 100644 doc/client_lua_api.txt delete mode 100644 doc/fst_api.md create mode 100644 doc/fst_api.txt delete mode 100644 doc/lua_api.md create mode 100644 doc/lua_api.txt create mode 100644 games/minimal/mods/default/.sounds/default_grass_footstep.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_break_glass.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_break_glass.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_break_glass.3.ogg create mode 100644 games/minimal/mods/default/sounds/default_chest_close.ogg create mode 100644 games/minimal/mods/default/sounds/default_chest_open.ogg create mode 100644 games/minimal/mods/default/sounds/default_cool_lava.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_cool_lava.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_cool_lava.3.ogg create mode 100644 games/minimal/mods/default/sounds/default_dig_choppy.ogg create mode 100644 games/minimal/mods/default/sounds/default_dig_cracky.ogg create mode 100644 games/minimal/mods/default/sounds/default_dig_crumbly.ogg create mode 100644 games/minimal/mods/default/sounds/default_dig_dig_immediate.ogg create mode 100644 games/minimal/mods/default/sounds/default_dig_metal.ogg create mode 100644 games/minimal/mods/default/sounds/default_dig_oddly_breakable_by_hand.ogg create mode 100644 games/minimal/mods/default/sounds/default_dig_snappy.ogg create mode 100644 games/minimal/mods/default/sounds/default_dirt_footstep.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_dirt_footstep.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_dug_metal.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_dug_metal.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_dug_node.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_dug_node.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_glass_footstep.ogg create mode 100644 games/minimal/mods/default/sounds/default_grass_footstep.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_grass_footstep.3.ogg create mode 100644 games/minimal/mods/default/sounds/default_gravel_footstep.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_gravel_footstep.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_gravel_footstep.3.ogg create mode 100644 games/minimal/mods/default/sounds/default_gravel_footstep.4.ogg create mode 100644 games/minimal/mods/default/sounds/default_hard_footstep.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_hard_footstep.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_hard_footstep.3.ogg create mode 100644 games/minimal/mods/default/sounds/default_item_smoke.ogg create mode 100644 games/minimal/mods/default/sounds/default_metal_footstep.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_metal_footstep.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_metal_footstep.3.ogg create mode 100644 games/minimal/mods/default/sounds/default_place_node.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_place_node.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_place_node.3.ogg create mode 100644 games/minimal/mods/default/sounds/default_place_node_hard.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_place_node_hard.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_place_node_metal.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_place_node_metal.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_sand_footstep.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_sand_footstep.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_snow_footstep.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_snow_footstep.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_snow_footstep.3.ogg create mode 100644 games/minimal/mods/default/sounds/default_snow_footstep.4.ogg create mode 100644 games/minimal/mods/default/sounds/default_snow_footstep.5.ogg create mode 100644 games/minimal/mods/default/sounds/default_tool_breaks.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_tool_breaks.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_tool_breaks.3.ogg create mode 100644 games/minimal/mods/default/sounds/default_water_footstep.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_water_footstep.2.ogg create mode 100644 games/minimal/mods/default/sounds/default_water_footstep.3.ogg create mode 100644 games/minimal/mods/default/sounds/default_water_footstep.4.ogg create mode 100644 games/minimal/mods/default/sounds/default_wood_footstep.1.ogg create mode 100644 games/minimal/mods/default/sounds/default_wood_footstep.2.ogg create mode 100644 games/minimal/mods/default/sounds/player_damage.ogg create mode 100644 games/minimal/mods/player_api/README.txt create mode 100644 games/minimal/mods/player_api/api.lua create mode 100644 games/minimal/mods/player_api/init.lua create mode 100644 games/minimal/mods/player_api/license.txt create mode 100644 games/minimal/mods/player_api/mod.conf create mode 100644 games/minimal/mods/player_api/models/character.b3d create mode 100644 games/minimal/mods/player_api/models/character.blend create mode 100644 games/minimal/mods/player_api/models/character.png create mode 100644 games/minimal/mods/player_api/textures/player.png create mode 100644 games/minimal/mods/player_api/textures/player_back.png create mode 100644 latex/doxygen.sty create mode 100644 latex/md_README.tex create mode 100644 latex/refman.log create mode 100644 latex/refman.tex delete mode 100644 spoof.js delete mode 100644 spoof.txt diff --git a/builtin/client/chatcommands.lua b/builtin/client/chatcommands.lua index 5cb1b40bb..f514f754b 100644 --- a/builtin/client/chatcommands.lua +++ b/builtin/client/chatcommands.lua @@ -37,7 +37,7 @@ core.register_on_sending_chat_message(function(message) return true end) -core.register_chatcommand("list_players", { +core.register_chatcommand("players", { description = core.gettext("List online players"), func = function(param) local player_names = core.get_player_names() diff --git a/builtin/client/cheats.lua b/builtin/client/cheats.lua new file mode 100644 index 000000000..9d7fd932c --- /dev/null +++ b/builtin/client/cheats.lua @@ -0,0 +1,160 @@ +core.register_chatcommand("set", { + params = "([-n] ) | ", + description = "Set or read client configuration setting", + privs = {server=true}, + func = function(param) + local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)") + if arg and arg == "-n" and setname and setvalue then + core.settings:set(setname, setvalue) + return true, setname .. " = " .. setvalue + end + + setname, setvalue = string.match(param, "([^ ]+) (.+)") + if setname and setvalue then + if not core.settings:get(setname) then + return false, "Failed. Use '.set -n ' to create a new setting." + end + core.settings:set(setname, setvalue) + return true, setname .. " = " .. setvalue + end + + setname = string.match(param, "([^ ]+)") + if setname then + setvalue = core.settings:get(setname) + if not setvalue then + setvalue = "" + end + return true, setname .. " = " .. setvalue + end + + return false, "Invalid parameters (see .help set)." + end, +}) + +function core.parse_pos(param) + local p = {} + p.x, p.y, p.z = string.match(param, "^([~|%d.-]+)[, ] *([~|%d.-]+)[, ] *([~|%d.-]+)$") + for k, v in pairs(p) do + if p[k] == "~" then + p[k] = core.localplayer:get_pos()[k] + else + p[k] = tonumber(v) + end + end + if p.x and p.y and p.z then + local lm = 31000 + if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm or p.z < -lm or p.z > lm then + return false, "Position out of Map bounds." + end + return true, p + end + return false, "Invalid position (" .. param .. ")" +end + +core.register_chatcommand("teleport", { + params = ",,", + description = "Teleport to position", + func = function(param) + local success, pos = core.parse_pos(param) + if success then + core.localplayer:set_pos(pos) + return true, "Teleporting to " .. core.pos_to_string(pos) + end + return false, pos + end, +}) + +core.register_chatcommand("place", { + params = ",,", + description = "Place wielded item", + func = function(param) + local success, pos = core.parse_pos(param) + if success then + core.place_node(pos) + return true, "Node placed at " .. core.pos_to_string(pos) + end + return false, pos + end, +}) + +core.register_chatcommand("dig", { + params = ",,", + description = "Dig node", + func = function(param) + local success, pos = core.parse_pos(param) + if success then + core.dig_node(pos) + return true, "Node at " .. core.pos_to_string(pos) .. " dug" + end + return false, pos + end, +}) + +core.register_chatcommand("kill", { + description = "Kill yourself", + func = function(param) + core.send_damage(core.localplayer:get_hp()) + end, +}) + +core.register_chatcommand("scan", { + description = "Scan for one or multible nodes in a radius around you", + param = " node1[,node2...]", + func = function(param) + local radius = tonumber(param:split(" ")[1]) + local nodes = param:split(" ")[2]:split(",") + local pos = core.localplayer:get_pos() + local fpos = core.find_node_near(pos, radius, nodes, true) + if fpos then + return true, "Found " .. table.concat(nodes, " or ") .. " at " .. core.pos_to_string(fpos) + end + return false, "None of " .. table.concat(nodes, " or ") .. " found in a radius of " .. tostring(radius) + end, +}) + +core.register_chatcommand("digaround", { + description = "Scan for one or multible nodes in a radius around you", + param = " node1[,node2...]", + func = function(param) + local radius = tonumber(param:split(" ")[1]) + local nodes = param:split(" ")[2]:split(",") + local function loop() + local fpos = core.find_node_near(core.localplayer:get_pos(), radius, nodes, true) + if fpos then core.dig_node(fpos) end + core.after(0, loop) + end + loop() + end, +}) + +local keep_digging = false + +core.register_chatcommand("keepdigging", { + params = ",,", + description = "Dig node again and again", + func = function(param) + local success, pos = core.parse_pos(param) + if success then + keep_digging = true + local function loop() + core.dig_node(pos) + if keep_digging then + core.after(0.1, loop) + end + end + loop() + end + end, +}) + +core.register_chatcommand("stopdigging", { + description = "Stop diggin", + func = function() + keep_digging = false + end, +}) + +core.register_on_punchnode(function(pos) + --core.dig_node(pos) +end) + diff --git a/builtin/client/death_formspec.lua b/builtin/client/death_formspec.lua index 516a15efc..0a4a98ea3 100644 --- a/builtin/client/death_formspec.lua +++ b/builtin/client/death_formspec.lua @@ -1,29 +1,33 @@ -- CSM death formspec. Only used when clientside modding is enabled, otherwise -- handled by the engine. -local dead = false - core.register_on_death(function() - if not dead then - core.display_chat_message("You died.") - local formspec = "size[11,5.5]bgcolor[#320000b4;true]" .. - "label[4.85,1.35;" .. fgettext("You died") .. - "]button_exit[4,3;3,0.5;btn_respawn;".. fgettext("Respawn") .."]" - core.show_formspec("bultin:death", formspec) - dead = true - end + core.display_chat_message("You died.") + local formspec = "size[11,5.5]bgcolor[#320000b4;true]" .. + "label[4.85,1.35;" .. fgettext("You died") .. + "]button_exit[2,3;3,0.5;btn_respawn;".. fgettext("Respawn") .. + "]button_exit[6,3;3,0.5;btn_ghost_mode;".. fgettext("Ghost Mode") .."]" + core.show_formspec("bultin:death", formspec) end) core.register_on_formspec_input(function(formname, fields) - if formname == "bultin:death" and fields.btn_respawn then - core.send_respawn() - dead = false + if formname == "bultin:death" then + if fields.btn_ghost_mode then + core.display_chat_message("You are in ghost mode. Use .respawn to Respawn") + else + core.send_respawn() + end end end) core.register_chatcommand("respawn", { + description = core.gettext("Respawn when in ghost mode"), func = function() - core.send_respawn() - dead = false + if core.localplayer:get_hp() == 0 then + core.send_respawn() + core.display_chat_message("Respawned.") + else + core.display_chat_message("You are not in ghost mode.") + end end }) diff --git a/builtin/client/init.lua b/builtin/client/init.lua index bcaa5244e..6c024f02e 100644 --- a/builtin/client/init.lua +++ b/builtin/client/init.lua @@ -8,5 +8,6 @@ dofile(commonpath .. "after.lua") dofile(commonpath .. "chatcommands.lua") dofile(commonpath .. "vector.lua") dofile(clientpath .. "death_formspec.lua") -dofile(clientpath .. "spoof.lua") +dofile(clientpath .. "chatcommands.lua") +dofile(clientpath .. "cheats.lua") diff --git a/builtin/client/register.lua b/builtin/client/register.lua index c1b4965c1..071220a43 100644 --- a/builtin/client/register.lua +++ b/builtin/client/register.lua @@ -40,6 +40,26 @@ function core.run_callbacks(callbacks, mode, ...) return ret end +function core.override_item(name, redefinition) + if redefinition.name ~= nil then + error("Attempt to redefine name of "..name.." to "..dump(redefinition.name), 2) + end + if redefinition.type ~= nil then + error("Attempt to redefine type of "..name.." to "..dump(redefinition.type), 2) + end + local itemdef = core.get_item_def(name) + if not itemdef then + error("Attempt to override non-existent item "..name, 2) + end + local nodedef = core.get_node_def(name) + table.combine(itemdef, nodedef) + + for k, v in pairs(redefinition) do + rawset(itemdef, k, v) + end + core.register_item_raw(itemdef) +end + -- -- Callback registration -- diff --git a/builtin/client/spoof.lua b/builtin/client/spoof.lua deleted file mode 100644 index f053a8a08..000000000 --- a/builtin/client/spoof.lua +++ /dev/null @@ -1,4 +0,0 @@ -local file = io.open("spoof.txt", "a") -minetest.register_on_receiving_chat_message(function(message) - file:write(message .. "\n") -end) diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index 715f89bc4..c904bccfc 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -519,6 +519,16 @@ function table.shuffle(t, from, to, random) end end +function table.combine(t, other) + other = other or {} + for k, v in pairs(other) do + if type(v) == "table" and type(t[k]) == "table" then + table.combine(t[k], v) + else + t[k] = v + end + end +end -------------------------------------------------------------------------------- -- mainmenu only functions diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index ba0cf9610..698dcf57b 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -2146,8 +2146,16 @@ xray_texture (Texture to make transparent when xray is enabled) string default_s priv_bypass (Make the Client think it has all privs) bool false -instant_dig (Dig Nodes on punch) bool false +fastdig (Fast Dig) bool false prevent_natural_damage (Prevent Natural Damage e.g Fall Damage) bool false freecam (Move around freely) bool false + +killaura (Enable Killaura) bool false + +no_hurt_cam (No Hurt Cam) bool false + +increase_tool_range (Increase Tool Range) bool false + +killaura_fast (Enable fast Killaura) bool false diff --git a/doc/client_lua_api.md b/doc/client_lua_api.md deleted file mode 100644 index c24de8d85..000000000 --- a/doc/client_lua_api.md +++ /dev/null @@ -1,1451 +0,0 @@ -Minetest Lua Client Modding API Reference 5.2.0 -================================================ -* More information at -* Developer Wiki: - -Introduction ------------- - -** WARNING: The client API is currently unstable, and may break/change without warning. ** - -Content and functionality can be added to Minetest 0.4.15-dev+ by using Lua -scripting in run-time loaded mods. - -A mod is a self-contained bunch of scripts, textures and other related -things that is loaded by and interfaces with Minetest. - -Transferring client-sided mods from the server to the client is planned, but not implemented yet. - -If you see a deficiency in the API, feel free to attempt to add the -functionality in the engine and API. You can send such improvements as -source code patches on GitHub (https://github.com/minetest/minetest). - -Programming in Lua ------------------- -If you have any difficulty in understanding this, please read -[Programming in Lua](http://www.lua.org/pil/). - -Startup -------- -Mods are loaded during client startup from the mod load paths by running -the `init.lua` scripts in a shared environment. - -In order to load client-side mods, the following conditions need to be satisfied: - -1) `$path_user/minetest.conf` contains the setting `enable_client_modding = true` - -2) The client-side mod located in `$path_user/clientmods/` is added to - `$path_user/clientmods/mods.conf` as `load_mod_ = true`. - -Note: Depending on the remote server's settings, client-side mods might not -be loaded or have limited functionality. See setting `csm_restriction_flags` for reference. - -Paths ------ -* `RUN_IN_PLACE=1` (Windows release, local build) - * `$path_user`: `` - * `$path_share`: `` -* `RUN_IN_PLACE=0`: (Linux release) - * `$path_share`: - * Linux: `/usr/share/minetest` - * Windows: `/minetest-0.4.x` - * `$path_user`: - * Linux: `$HOME/.minetest` - * Windows: `C:/users//AppData/minetest` (maybe) - -Mod load path -------------- -Generic: - -* `$path_share/clientmods/` -* `$path_user/clientmods/` (User-installed mods) - -In a run-in-place version (e.g. the distributed windows version): - -* `minetest-0.4.x/clientmods/` (User-installed mods) - -On an installed version on Linux: - -* `/usr/share/minetest/clientmods/` -* `$HOME/.minetest/clientmods/` (User-installed mods) - -Modpack support ----------------- - -Mods can be put in a subdirectory, if the parent directory, which otherwise -should be a mod, contains a file named `modpack.conf`. -The file is a key-value store of modpack details. - -* `name`: The modpack name. -* `description`: Description of mod to be shown in the Mods tab of the main - menu. - -Mod directory structure ------------------------- - - clientmods - ├── modname - │   ├── mod.conf - │   ├── init.lua - └── another - -### modname - -The location of this directory. - -### mod.conf - -An (optional) settings file that provides meta information about the mod. - -* `name`: The mod name. Allows Minetest to determine the mod name even if the - folder is wrongly named. -* `description`: Description of mod to be shown in the Mods tab of the main - menu. -* `depends`: A comma separated list of dependencies. These are mods that must be - loaded before this mod. -* `optional_depends`: A comma separated list of optional dependencies. - Like a dependency, but no error if the mod doesn't exist. - -### `init.lua` - -The main Lua script. Running this script should register everything it -wants to register. Subsequent execution depends on minetest calling the -registered callbacks. - -**NOTE**: Client mods currently can't provide and textures, sounds or models by -themselves. Any media referenced in function calls must already be loaded -(provided by mods that exist on the server). - -Naming convention for registered textual names ----------------------------------------------- -Registered names should generally be in this format: - - "modname:" ( can have characters a-zA-Z0-9_) - -This is to prevent conflicting names from corrupting maps and is -enforced by the mod loader. - -### Example -In the mod `experimental`, there is the ideal item/node/entity name `tnt`. -So the name should be `experimental:tnt`. - -Enforcement can be overridden by prefixing the name with `:`. This can -be used for overriding the registrations of some other mod. - -Example: Any mod can redefine `experimental:tnt` by using the name - - :experimental:tnt - -when registering it. -(also that mod is required to have `experimental` as a dependency) - -The `:` prefix can also be used for maintaining backwards compatibility. - -Sounds ------- -**NOTE: Connecting sounds to objects is not implemented.** - -Only Ogg Vorbis files are supported. - -For positional playing of sounds, only single-channel (mono) files are -supported. Otherwise OpenAL will play them non-positionally. - -Mods should generally prefix their sounds with `modname_`, e.g. given -the mod name "`foomod`", a sound could be called: - - foomod_foosound.ogg - -Sounds are referred to by their name with a dot, a single digit and the -file extension stripped out. When a sound is played, the actual sound file -is chosen randomly from the matching sounds. - -When playing the sound `foomod_foosound`, the sound is chosen randomly -from the available ones of the following files: - -* `foomod_foosound.ogg` -* `foomod_foosound.0.ogg` -* `foomod_foosound.1.ogg` -* (...) -* `foomod_foosound.9.ogg` - -Examples of sound parameter tables: - - -- Play locationless - { - gain = 1.0, -- default - } - -- Play locationless, looped - { - gain = 1.0, -- default - loop = true, - } - -- Play in a location - { - pos = {x = 1, y = 2, z = 3}, - gain = 1.0, -- default - } - -- Play connected to an object, looped - { - object = , - gain = 1.0, -- default - loop = true, - } - -Looped sounds must either be connected to an object or played locationless. - -### SimpleSoundSpec -* e.g. `""` -* e.g. `"default_place_node"` -* e.g. `{}` -* e.g. `{name = "default_place_node"}` -* e.g. `{name = "default_place_node", gain = 1.0}` - -Representations of simple things --------------------------------- - -### Position/vector - - {x=num, y=num, z=num} - -For helper functions see "Vector helpers". - -### pointed_thing -* `{type="nothing"}` -* `{type="node", under=pos, above=pos}` -* `{type="object", id=ObjectID}` - -Flag Specifier Format ---------------------- -Flags using the standardized flag specifier format can be specified in either of -two ways, by string or table. - -The string format is a comma-delimited set of flag names; whitespace and -unrecognized flag fields are ignored. Specifying a flag in the string sets the -flag, and specifying a flag prefixed by the string `"no"` explicitly -clears the flag from whatever the default may be. - -In addition to the standard string flag format, the schematic flags field can -also be a table of flag names to boolean values representing whether or not the -flag is set. Additionally, if a field with the flag name prefixed with `"no"` -is present, mapped to a boolean of any value, the specified flag is unset. - -E.g. A flag field of value - - {place_center_x = true, place_center_y=false, place_center_z=true} - -is equivalent to - - {place_center_x = true, noplace_center_y=true, place_center_z=true} - -which is equivalent to - - "place_center_x, noplace_center_y, place_center_z" - -or even - - "place_center_x, place_center_z" - -since, by default, no schematic attributes are set. - -Formspec --------- -Formspec defines a menu. It is a string, with a somewhat strange format. - -Spaces and newlines can be inserted between the blocks, as is used in the -examples. - -### Examples - -#### Chest - - size[8,9] - list[context;main;0,0;8,4;] - list[current_player;main;0,5;8,4;] - -#### Furnace - - size[8,9] - list[context;fuel;2,3;1,1;] - list[context;src;2,1;1,1;] - list[context;dst;5,1;2,2;] - list[current_player;main;0,5;8,4;] - -#### Minecraft-like player inventory - - size[8,7.5] - image[1,0.6;1,2;player.png] - list[current_player;main;0,3.5;8,4;] - list[current_player;craft;3,0;3,3;] - list[current_player;craftpreview;7,1;1,1;] - -### Elements - -#### `size[,,]` -* Define the size of the menu in inventory slots -* `fixed_size`: `true`/`false` (optional) -* deprecated: `invsize[,;]` - -#### `container[,]` -* Start of a container block, moves all physical elements in the container by (X, Y) -* Must have matching container_end -* Containers can be nested, in which case the offsets are added - (child containers are relative to parent containers) - -#### `container_end[]` -* End of a container, following elements are no longer relative to this container - -#### `list[;;,;,;]` -* Show an inventory list - -#### `list[;;,;,;]` -* Show an inventory list - -#### `listring[;]` -* Allows to create a ring of inventory lists -* Shift-clicking on items in one element of the ring - will send them to the next inventory list inside the ring -* The first occurrence of an element inside the ring will - determine the inventory where items will be sent to - -#### `listring[]` -* Shorthand for doing `listring[;]` - for the last two inventory lists added by list[...] - -#### `listcolors[;]` -* Sets background color of slots as `ColorString` -* Sets background color of slots on mouse hovering - -#### `listcolors[;;]` -* Sets background color of slots as `ColorString` -* Sets background color of slots on mouse hovering -* Sets color of slots border - -#### `listcolors[;;;;]` -* Sets background color of slots as `ColorString` -* Sets background color of slots on mouse hovering -* Sets color of slots border -* Sets default background color of tooltips -* Sets default font color of tooltips - -#### `tooltip[;;,]` -* Adds tooltip for an element -* `` tooltip background color as `ColorString` (optional) -* `` tooltip font color as `ColorString` (optional) - -#### `image[,;,;]` -* Show an image -* Position and size units are inventory slots - -#### `item_image[,;,;]` -* Show an inventory image of registered item/node -* Position and size units are inventory slots - -#### `bgcolor[;]` -* Sets background color of formspec as `ColorString` -* If `true`, the background color is drawn fullscreen (does not effect the size of the formspec) - -#### `background[,;,;]` -* Use a background. Inventory rectangles are not drawn then. -* Position and size units are inventory slots -* Example for formspec 8x4 in 16x resolution: image shall be sized - 8 times 16px times 4 times 16px. - -#### `background[,;,;;]` -* Use a background. Inventory rectangles are not drawn then. -* Position and size units are inventory slots -* Example for formspec 8x4 in 16x resolution: - image shall be sized 8 times 16px times 4 times 16px -* If `true` the background is clipped to formspec size - (`x` and `y` are used as offset values, `w` and `h` are ignored) - -#### `pwdfield[,;,;;