From 21f3782439474e6f2ccb96da04166af6237dea17 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 4 Nov 2022 13:54:03 +0100 Subject: [PATCH 1/8] Fix lightning on_strike api + rename to on_lightning_strike --- mods/ENTITIES/mcl_mobs/api.lua | 1 + mods/ENVIRONMENT/lightning/init.lua | 22 +++------------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 42dad6a06..06a273a14 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -4939,6 +4939,7 @@ minetest.register_entity(name, { harmed_by_heal = def.harmed_by_heal, + on_lightning_strike = def.on_lightning_strike }) if minetest.get_modpath("doc_identifier") ~= nil then diff --git a/mods/ENVIRONMENT/lightning/init.lua b/mods/ENVIRONMENT/lightning/init.lua index e6973e1c6..b0bff5716 100644 --- a/mods/ENVIRONMENT/lightning/init.lua +++ b/mods/ENVIRONMENT/lightning/init.lua @@ -135,26 +135,10 @@ function lightning.strike_func(pos, pos2, objects) -- damage nearby objects, transform mobs for _, obj in pairs(objects) do local lua = obj:get_luaentity() - if lua and lua._on_strike then - lua._on_strike(lua, pos, pos2, objects) - end - -- remove this when mob API is done - if lua and lua.name == "mobs_mc:pig" then - mcl_util.replace_mob(obj, "mobs_mc:pigman") - elseif lua and lua.name == "mobs_mc:mooshroom" then - if lua.base_texture[1] == "mobs_mc_mooshroom.png" then - lua.base_texture = { "mobs_mc_mooshroom_brown.png", "mobs_mc_mushroom_brown.png" } - else - lua.base_texture = { "mobs_mc_mooshroom.png", "mobs_mc_mushroom_red.png" } + if lua and lua.is_mob then + if not lua.on_lightning_strike or ( lua.on_lightning_strike and lua.on_lightning_strike(lua, pos, pos2, objects) ) ~= true then + mcl_util.deal_damage(obj, 5, { type = "lightning_bolt" }) end - obj:set_properties({ textures = lua.base_texture }) - elseif lua and lua.name == "mobs_mc:villager" then - mcl_util.replace_mob(obj, "mobs_mc:witch") - elseif lua and lua.name == "mobs_mc:creeper" then - mcl_util.replace_mob(obj, "mobs_mc:creeper_charged") - else - -- WARNING: unsafe entity handling. object may be removed immediately - mcl_util.deal_damage(obj, 5, { type = "lightning_bolt" }) end end From 220b542cbfe843980d9e7fd4f67289fbbb6f6e83 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 4 Nov 2022 14:01:24 +0100 Subject: [PATCH 2/8] Mooshroom color change with on_lightning_strike --- mods/ENTITIES/mobs_mc/cow+mooshroom.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua index d0f7178bd..4a91e9196 100644 --- a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua +++ b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua @@ -153,6 +153,16 @@ mooshroom_def.on_rightclick = function(self, clicker) end mcl_mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) end + +mooshroom_def.on_lightning_strike = function(self, pos, pos2, objects) + if self.base_texture[1] == "mobs_mc_mooshroom_brown.png" then + self.base_texture = { "mobs_mc_mooshroom.png", "mobs_mc_mushroom_red.png" } + else + self.base_texture = { "mobs_mc_mooshroom_brown.png", "mobs_mc_mushroom_brown.png" } + end + self.object:set_properties({ textures = self.base_texture }) + return true +end mcl_mobs:register_mob("mobs_mc:mooshroom", mooshroom_def) From 97468cde0cb46544b7bcce38143442a9e0d7a099 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 4 Nov 2022 14:02:10 +0100 Subject: [PATCH 3/8] Add mcl_util to mobs_mc depends --- mods/ENTITIES/mobs_mc/mod.conf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/mod.conf b/mods/ENTITIES/mobs_mc/mod.conf index 3d6a6928d..89964c835 100644 --- a/mods/ENTITIES/mobs_mc/mod.conf +++ b/mods/ENTITIES/mobs_mc/mod.conf @@ -1,6 +1,5 @@ name = mobs_mc author = maikerumine description = Adds Minecraft-like monsters and animals. -depends = mcl_init, mcl_particles, mcl_mobs, mcl_wip, mcl_core +depends = mcl_init, mcl_particles, mcl_mobs, mcl_wip, mcl_core, mcl_util optional_depends = default, mcl_tnt, mcl_bows, mcl_throwing, mcl_fishing, bones, mesecons_materials, mobs_mc_gameconfig, doc_items - From 5cf2f488a8f8539f0d7d61782d478c8d54de2f3d Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 4 Nov 2022 14:02:24 +0100 Subject: [PATCH 4/8] Transform creeper with on_lightning_strike --- mods/ENTITIES/mobs_mc/creeper.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mods/ENTITIES/mobs_mc/creeper.lua b/mods/ENTITIES/mobs_mc/creeper.lua index 2ee943124..f50eb5326 100644 --- a/mods/ENTITIES/mobs_mc/creeper.lua +++ b/mods/ENTITIES/mobs_mc/creeper.lua @@ -219,6 +219,10 @@ mcl_mobs:register_mob("mobs_mc:creeper_charged", { end end end, + on_lightning_strike = function(self, pos, pos2, objects) + mcl_util.replace_mob(self.object, "mobs_mc:creeper_charged") + return true + end, maxdrops = 2, drops = { {name = "mcl_mobitems:gunpowder", From 95db6104e9eee870ea21060ce6043e894de4ef4b Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 4 Nov 2022 14:02:45 +0100 Subject: [PATCH 5/8] Transform pig with on_lightning_strike --- mods/ENTITIES/mobs_mc/pig.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mods/ENTITIES/mobs_mc/pig.lua b/mods/ENTITIES/mobs_mc/pig.lua index 98b1db805..f8ce4afbe 100644 --- a/mods/ENTITIES/mobs_mc/pig.lua +++ b/mods/ENTITIES/mobs_mc/pig.lua @@ -60,6 +60,10 @@ mcl_mobs:register_mob("mobs_mc:pig", { "mcl_mobitems:carrot_on_a_stick" }, view_range = 8, + on_lightning_strike = function(self, pos, pos2, objects) + mcl_util.replace_mob(self.object, "mobs_mc:zombified_piglin") + return true + end, do_custom = function(self, dtime) -- set needed values if not already present From 2c4a76868585c99543b844026827f634f5ac71de Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 4 Nov 2022 14:02:59 +0100 Subject: [PATCH 6/8] Transform villager with on_lightning_strike --- mods/ENTITIES/mobs_mc/villager.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 5e547c884..81a23756b 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -1885,6 +1885,10 @@ mcl_mobs:register_mob("mobs_mc:villager", { mcl_log("Died, so bye bye jobsite") end end, + on_lightning_strike = function(self, pos, pos2, objects) + mcl_util.replace_mob(self.object, "mobs_mc:witch") + return true + end, }) From fcba67b7e7a16d54937b00089b0675495c4590c8 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 4 Nov 2022 14:14:45 +0100 Subject: [PATCH 7/8] Make on_lightning_strike available to non-mob entities --- mods/ENVIRONMENT/lightning/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/lightning/init.lua b/mods/ENVIRONMENT/lightning/init.lua index b0bff5716..12c50ef29 100644 --- a/mods/ENVIRONMENT/lightning/init.lua +++ b/mods/ENVIRONMENT/lightning/init.lua @@ -135,7 +135,7 @@ function lightning.strike_func(pos, pos2, objects) -- damage nearby objects, transform mobs for _, obj in pairs(objects) do local lua = obj:get_luaentity() - if lua and lua.is_mob then + if lua then if not lua.on_lightning_strike or ( lua.on_lightning_strike and lua.on_lightning_strike(lua, pos, pos2, objects) ) ~= true then mcl_util.deal_damage(obj, 5, { type = "lightning_bolt" }) end From 15542d4878f2a2c70453376f40ed357e4365f6ce Mon Sep 17 00:00:00 2001 From: MysticTempest Date: Fri, 4 Nov 2022 22:35:01 +0100 Subject: [PATCH 8/8] Fix player not getting damage from lightning --- mods/ENVIRONMENT/lightning/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/lightning/init.lua b/mods/ENVIRONMENT/lightning/init.lua index 12c50ef29..59591b061 100644 --- a/mods/ENVIRONMENT/lightning/init.lua +++ b/mods/ENVIRONMENT/lightning/init.lua @@ -136,9 +136,11 @@ function lightning.strike_func(pos, pos2, objects) for _, obj in pairs(objects) do local lua = obj:get_luaentity() if lua then - if not lua.on_lightning_strike or ( lua.on_lightning_strike and lua.on_lightning_strike(lua, pos, pos2, objects) ) ~= true then + if not lua.on_lightning_strike or ( lua.on_lightning_strike and lua.on_lightning_strike(lua, pos, pos2, objects) ~= true ) then mcl_util.deal_damage(obj, 5, { type = "lightning_bolt" }) end + else + mcl_util.deal_damage(obj, 5, { type = "lightning_bolt" }) end end