From 0872a9161fe911e72b4f9873967058c0d479940d Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Thu, 11 Apr 2024 06:41:29 +0200 Subject: [PATCH 1/4] add hook for other mods provide a way for other mods to decide where gliders are permited --- init.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/init.lua b/init.lua index 3953e5d..250527e 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,4 @@ +hangglider = {} local has_player_monoids = minetest.get_modpath("player_monoids") local has_areas = minetest.get_modpath("areas") @@ -73,6 +74,16 @@ local function remove_physics_overrides(player) end end +-- expose so other mods can override/hook-into +-- to disallow flying in certain areas or materials +-- such as on the moon or without priv in certain area +-- pos: (vector) position of player +-- name: (string) player's name +-- in_flight: (bool) is already airborne +function hangglider.allowed_to_fly(pos, name, in_flight) --luacheck: no unused args + return true +end + local function can_fly(pos, name) if not enable_flak then return true @@ -156,6 +167,8 @@ local function hangglider_step(self, dtime) shoot_flak_sound(pos) gliding = false end + elseif not hangglider.allowed_to_fly(pos, name, true) then + gliding = false end if not gliding then remove_physics_overrides(player) @@ -177,6 +190,9 @@ local function hangglider_use(stack, player) local pos = player:get_pos() local name = player:get_player_name() if not hanggliding_players[name] then + if not hangglider.allowed_to_fly(pos, name, false) + return + end minetest.sound_play("hanggliger_equip", {pos = pos, max_hear_distance = 8, gain = 1.0}, true) local entity = minetest.add_entity(pos, "hangglider:glider") if entity then From 10d082c3bbea70bd719c20860b4a66b00697d815 Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Thu, 11 Apr 2024 06:47:13 +0200 Subject: [PATCH 2/4] rename can_fly() to friendly_airspace() The name confused me over and over again. The function doesn't check flight-ability at all, it rather checks permission / friendlyness of area. safe_node_below() does more of what 'can_fly' implies. --- init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 250527e..c7ddf7e 100644 --- a/init.lua +++ b/init.lua @@ -84,7 +84,7 @@ function hangglider.allowed_to_fly(pos, name, in_flight) --luacheck: no unused a return true end -local function can_fly(pos, name) +local function friendly_airspace(pos, name) if not enable_flak then return true end @@ -153,7 +153,7 @@ local function hangglider_step(self, dtime) }) end end - if not can_fly(pos, name) then + if not friendly_airspace(pos, name) then if not self.flak_timer then self.flak_timer = 0 shoot_flak_sound(pos) From dcabbd6a5ef73bbf9d1a8c97c1f895026f308d19 Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Thu, 11 Apr 2024 06:53:08 +0200 Subject: [PATCH 3/4] oops --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index c7ddf7e..bf9a1d1 100644 --- a/init.lua +++ b/init.lua @@ -190,7 +190,7 @@ local function hangglider_use(stack, player) local pos = player:get_pos() local name = player:get_player_name() if not hanggliding_players[name] then - if not hangglider.allowed_to_fly(pos, name, false) + if not hangglider.allowed_to_fly(pos, name, false) then return end minetest.sound_play("hanggliger_equip", {pos = pos, max_hear_distance = 8, gain = 1.0}, true) From 40754ee74caf3bbbd0db6cd4c0a879f2fb3103bc Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Thu, 11 Apr 2024 06:57:28 +0200 Subject: [PATCH 4/4] Update .luacheckrc --- .luacheckrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.luacheckrc b/.luacheckrc index 1502aa3..74dfefb 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,5 +1,6 @@ globals = { "areas", + "hangglider", } read_globals = {