From f1072821f18f47c3d8b125e92f8d8cdffc1b21ce Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 9 Jul 2023 02:59:52 +0200 Subject: [PATCH] added register_on_reload; made interface_mobs_api.lua work again for mobs.lua --- init.lua | 29 +++++++++++++++++++++++++++++ interface_mobs_api.lua | 4 ++-- yl_local_server_config.lua | 3 --- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index 250ed04..ed02bac 100644 --- a/init.lua +++ b/init.lua @@ -5,6 +5,19 @@ yl_speak_up = {} -- this is a list of such functions yl_speak_up.inform_when_reloaded = {} +yl_speak_up.register_on_reload = function(fun, desc) + -- avoid double entries + for i, f in ipairs(yl_speak_up.inform_when_reloaded) do + if(f == fun) then + return + end + end + table.insert(yl_speak_up.inform_when_reloaded, fun) + minetest.log("action","[MOD] yl_speak_up Will execute function \""..tostring(desc).. + "\" on reload.") +end + + local modpath = minetest.get_modpath("yl_speak_up")..DIR_DELIM yl_speak_up.worldpath = minetest.get_worldpath()..DIR_DELIM yl_speak_up.modpath = modpath @@ -41,6 +54,22 @@ yl_speak_up.custom_server_functions = {} -- may store a table of registered mobs in the future; currently not really used yl_speak_up.mob_table = {} +-- the real implementation happens in interface_mobs_api.lua +-- mobs.lua may need this at an earlier point +yl_speak_up.mobs_on_rightclick = function(self, clicker) + if(not(yl_speak_up.do_mobs_on_rightclick)) then + return false + end + return yl_speak_up.do_mobs_on_rightclick(self, clicker) +end + +yl_speak_up.mobs_after_activate = function(self, staticdata, def, dtime) + if(not(yl_speak_up.do_mobs_after_activate)) then + return false + end + return yl_speak_up.do_mobs_after_activate(self, staticdata, def, dtime) +end + -- Some files may or may not exist on the server - they contain adjustments -- local to the server. -- Here you can override what you need for YOUR SERVER. diff --git a/interface_mobs_api.lua b/interface_mobs_api.lua index f409974..b01def2 100644 --- a/interface_mobs_api.lua +++ b/interface_mobs_api.lua @@ -27,7 +27,7 @@ end -- * if none of the above applies: actually talk to the mob -- This is so often needed (but also mobs_redo specific!) that we provide -- an extra easy-to-call function here. -function yl_speak_up.mobs_on_rightclick(self, clicker) +function yl_speak_up.do_mobs_on_rightclick(self, clicker) --local item = clicker:get_wielded_item() local name = clicker:get_player_name() @@ -51,7 +51,7 @@ function yl_speak_up.mobs_on_rightclick(self, clicker) end -function yl_speak_up.mobs_after_activate(self, staticdata, def, dtime) +function yl_speak_up.do_mobs_after_activate(self, staticdata, def, dtime) -- this scrolls far too much -- yl_speak_up.log_change("-", "n_"..self.yl_speak_up.id, -- "activated at "..minetest.pos_to_string(self.object:get_pos()), "action") diff --git a/yl_local_server_config.lua b/yl_local_server_config.lua index b802c1d..2a1f38e 100644 --- a/yl_local_server_config.lua +++ b/yl_local_server_config.lua @@ -3,9 +3,6 @@ -- Else ignore this file. -- --- do all the things that have to be done when yl_speak_up is initialized or reloaded -yl_npc.add_textures() - -- Tribe Miocene (Obsidian Flans) yl_speak_up.mesh_data["zmobs_lava_flan.x"] = { texture_index = 1, } yl_speak_up.mob_skins["yl_events:tribe_miocene"] = {"mobs_obsidian_flan.png"}