add functions api + documentation (#23)

This commit is contained in:
wsor4035 2024-05-26 12:31:52 -04:00 committed by GitHub
parent 5b4b19a184
commit 788217bb8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 1 deletions

View File

@ -25,6 +25,8 @@ See the respective sub apis doc file in /doc for detailed documentation.
| Exile | x | | | | Exile | x | | |
| KSurvive 2 | x | | | | KSurvive 2 | x | | |
For functions see /doc/functions.md for the specifics relating to the function
**Mods** **Mods**
* `basic_materials` * `basic_materials`
* `mesecons_materials` * `mesecons_materials`

13
doc/functions.md Normal file
View File

@ -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

View File

@ -10,6 +10,7 @@ xcompat.utilities = dofile(modpath .. "/src/utilities.lua")
xcompat.sounds = dofile(modpath .. "/src/sounds.lua") xcompat.sounds = dofile(modpath .. "/src/sounds.lua")
xcompat.materials = dofile(modpath .. "/src/materials.lua") xcompat.materials = dofile(modpath .. "/src/materials.lua")
xcompat.textures = dofile(modpath .. "/src/textures.lua") xcompat.textures = dofile(modpath .. "/src/textures.lua")
xcompat.functions = dofile(modpath .. "/src/functions.lua")
local function validate_sound(key) local function validate_sound(key)
if key and xcompat.sounds[key] then if key and xcompat.sounds[key] then

View File

@ -1,3 +1,3 @@
name = xcompat name = xcompat
description = Provides cross compatibility between mods and games for sounds and crafting materials. 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

19
src/functions.lua Normal file
View File

@ -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