From 0426b31c7e820a9b9af3c8175d5ffdbe8d1674ce Mon Sep 17 00:00:00 2001 From: Michieal Date: Sat, 2 Dec 2023 07:00:25 -0500 Subject: [PATCH] Initial Commit. --- mods/PLAYER/mcl_fovapi/api.md | 9 +++++ mods/PLAYER/mcl_fovapi/init.lua | 60 +++++++++++++++++++++++++++++++++ mods/PLAYER/mcl_fovapi/mod.conf | 4 +++ 3 files changed, 73 insertions(+) create mode 100644 mods/PLAYER/mcl_fovapi/api.md create mode 100644 mods/PLAYER/mcl_fovapi/init.lua create mode 100644 mods/PLAYER/mcl_fovapi/mod.conf diff --git a/mods/PLAYER/mcl_fovapi/api.md b/mods/PLAYER/mcl_fovapi/api.md new file mode 100644 index 000000000..39d6ee86d --- /dev/null +++ b/mods/PLAYER/mcl_fovapi/api.md @@ -0,0 +1,9 @@ + + + +mcl_fovapi = {} +mcl_fovapi.default_fov = {} +mcl_fovapi.registered_modifiers = {} +mcl_fovapi.applied_modifiers = {} +function mcl_fovapi.register_modifier(name, fov_factor, time, exclusive, on_start, on_end) +function mcl_fovapi.apply_modifier(player, modifier_name) diff --git a/mods/PLAYER/mcl_fovapi/init.lua b/mods/PLAYER/mcl_fovapi/init.lua new file mode 100644 index 000000000..17c0a9262 --- /dev/null +++ b/mods/PLAYER/mcl_fovapi/init.lua @@ -0,0 +1,60 @@ +--- +--- Copyright 2023, Michieal. +--- License: GPL3. (Default Mineclone2 License) +--- Created by michieal. +--- DateTime: 12/2/23 5:47 AM +--- + +mcl_fovapi = {} + +-- Handles default fov for players +mcl_fovapi.default_fov = {} +mcl_fovapi.registered_modifiers = {} +mcl_fovapi.applied_modifiers = {} + +-- set to blank on join (for 3rd party mods) +minetest.register_on_joinplayer(function(player) + local name = player:get_player_name() + -- Assign default FOV + mcl_fovapi.default_fov[name] = player:get_fov() +end) + +-- clear when player leaves +minetest.register_on_leaveplayer(function(player) + local name = player:get_player_name() + -- Remove default FOV + mcl_fovapi.default_fov[name] = nil +end) + +function mcl_fovapi.register_modifier(name, fov_factor, time, exclusive, on_start, on_end) + local def = { + modifer_name = name, + fov = fov_factor, + time = time, + exclusive = exclusive, + on_start = on_start, + on_end = on_end, + } + + mcl_fovapi.registered_modifiers[name] = def + +end + +function mcl_fovapi.apply_modifier(player, modifier_name) + + if modifier_name == nil then return end + if mcl_fovapi.registered_modifiers[modifier_name] == nil then return end + + local modifier = mcl_fovapi.registered_modifiers[modifier_name] + if modifier.on_start ~= nil then + modifier.on_start(player) + end + + mcl_fovapi.applied_modifiers[player][modifier_name] = true -- set the applied to be true. + + -- do modiifier apply code. + + + +end + diff --git a/mods/PLAYER/mcl_fovapi/mod.conf b/mods/PLAYER/mcl_fovapi/mod.conf new file mode 100644 index 000000000..b78c78596 --- /dev/null +++ b/mods/PLAYER/mcl_fovapi/mod.conf @@ -0,0 +1,4 @@ +name = mcl_fovapi +author = Michieal +description = An API for handling FOV changes. +depends = mcl_player \ No newline at end of file