diff options
author | orwell96 <orwell@bleipb.de> | 2021-02-03 09:30:44 +0100 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2021-02-03 09:30:44 +0100 |
commit | 8ae405f00f7073bca8cb621612ab11bc730228a3 (patch) | |
tree | 8eb6d7b055df6cf2be0887cf7b3b85532e47ead2 /advtrains/helpers.lua | |
parent | d8d1d27ccb622dfc8e80eb5eb44e6020a1655389 (diff) | |
download | advtrains-8ae405f00f7073bca8cb621612ab11bc730228a3.tar.gz advtrains-8ae405f00f7073bca8cb621612ab11bc730228a3.tar.bz2 advtrains-8ae405f00f7073bca8cb621612ab11bc730228a3.zip |
Discard get_node_or_nil() for area-loaded check and use either a distance-based approach or minetest.is_block_active() if available
See also https://github.com/minetest/minetest/pull/10897
Diffstat (limited to 'advtrains/helpers.lua')
-rw-r--r-- | advtrains/helpers.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/advtrains/helpers.lua b/advtrains/helpers.lua index 3b0bedd..cf890ca 100644 --- a/advtrains/helpers.lua +++ b/advtrains/helpers.lua @@ -445,3 +445,28 @@ atdebug("pts",os.clock()-t1,"s") ]] +-- Function to check whether a position is near (within range of) any player +function advtrains.position_in_range(pos, range) + if not pos then + return true + end + for _,p in pairs(minetest.get_connected_players()) do + if vector.distance(p:get_pos(),pos)<=range then + return true + end + end + return false +end + +local active_node_range = tonumber(minetest.settings:get("active_block_range"))*16 + 16 +-- Function to check whether node at position(pos) is "loaded"/"active" +-- That is, whether it is within the active_block_range to a player +if minetest.is_block_active then -- define function differently whether minetest.is_block_active is available or not + advtrains.is_node_loaded = minetest.is_block_active +else + function advtrains.is_node_loaded(pos) + if advtrains.position_in_range(pos, active_node_range) then + return true + end + end +end |