From 0872a9161fe911e72b4f9873967058c0d479940d Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Thu, 11 Apr 2024 06:41:29 +0200 Subject: [PATCH] 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