From 788217bb8e9e09900cd6c937db430e824ab86960 Mon Sep 17 00:00:00 2001 From: wsor4035 <24964441+wsor4035@users.noreply.github.com> Date: Sun, 26 May 2024 12:31:52 -0400 Subject: [PATCH] add functions api + documentation (#23) --- README.md | 2 ++ doc/functions.md | 13 +++++++++++++ init.lua | 1 + mod.conf | 2 +- src/functions.lua | 19 +++++++++++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 doc/functions.md create mode 100644 src/functions.lua diff --git a/README.md b/README.md index 59e8efb..5661b77 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ See the respective sub apis doc file in /doc for detailed documentation. | Exile | x | | | | KSurvive 2 | x | | | +For functions see /doc/functions.md for the specifics relating to the function + **Mods** * `basic_materials` * `mesecons_materials` diff --git a/doc/functions.md b/doc/functions.md new file mode 100644 index 0000000..fd4541a --- /dev/null +++ b/doc/functions.md @@ -0,0 +1,13 @@ +# Functions API + +## `can_interact_with_node(player, pos)` +returns `bool` + +checks for the ability to interact with a node via: +* if a player +* owner metadata key +* protection_bypass + +supports +* minetest game default if present +* else polyfill \ No newline at end of file diff --git a/init.lua b/init.lua index 7530949..2013a94 100644 --- a/init.lua +++ b/init.lua @@ -10,6 +10,7 @@ xcompat.utilities = dofile(modpath .. "/src/utilities.lua") xcompat.sounds = dofile(modpath .. "/src/sounds.lua") xcompat.materials = dofile(modpath .. "/src/materials.lua") xcompat.textures = dofile(modpath .. "/src/textures.lua") +xcompat.functions = dofile(modpath .. "/src/functions.lua") local function validate_sound(key) if key and xcompat.sounds[key] then diff --git a/mod.conf b/mod.conf index f7568a6..5dc21e6 100644 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,3 @@ name = xcompat description = Provides cross compatibility between mods and games for sounds and crafting materials. -optional_depends = default, fl_stone, fl_trees, mcl_sounds, hades_sounds, ks_sounds, nodes_nature, fl_topsoil, fl_trees, mcl_core +optional_depends = default, fl_stone, fl_trees, mcl_sounds, hades_sounds, ks_sounds, nodes_nature, fl_topsoil, fl_trees, mcl_core, farming, x_farming diff --git a/src/functions.lua b/src/functions.lua new file mode 100644 index 0000000..52a1b16 --- /dev/null +++ b/src/functions.lua @@ -0,0 +1,19 @@ +local functions = {} + +function functions.can_interact_with_node(player, pos) + --if we have default, use it + if default then return default.can_interact_with_node(player, pos) end + + local owner = minetest.get_meta(pos):get_string("owner") or "" + + --check that we have a valid player + if not player or not player:is_player() then return false end + --check there privs for compat with areas + if minetest.check_player_privs(player, "protection_bypass") then return true end + --if a normal player, check if they are the owner + if owner == "" or owner == player:get_player_name() then return true end + + return false +end + +return functions \ No newline at end of file