mirror of
https://github.com/mt-mods/xcompat.git
synced 2024-12-22 09:00:17 +01:00
add functions api + documentation (#23)
This commit is contained in:
parent
5b4b19a184
commit
788217bb8e
@ -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`
|
||||
|
13
doc/functions.md
Normal file
13
doc/functions.md
Normal 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
|
1
init.lua
1
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
|
||||
|
2
mod.conf
2
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
|
||||
|
19
src/functions.lua
Normal file
19
src/functions.lua
Normal 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
|
Loading…
Reference in New Issue
Block a user