From bc740efafea50cc497a22a11401c343e5ceb8faf Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 2 May 2020 19:05:56 +0200 Subject: [PATCH] Add fire explosions --- mods/CORE/mcl_explosions/init.lua | 13 ++++++++++--- mods/CORE/mcl_explosions/mod.conf | 1 + mods/ENTITIES/mcl_mobs/api.lua | 8 ++++---- mods/ENTITIES/mobs_mc/ghast.lua | 8 +++----- mods/ITEMS/mcl_beds/depends.txt | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/mods/CORE/mcl_explosions/init.lua b/mods/CORE/mcl_explosions/init.lua index de8768ca..eb1b21f6 100644 --- a/mods/CORE/mcl_explosions/init.lua +++ b/mods/CORE/mcl_explosions/init.lua @@ -14,6 +14,8 @@ mcl_explosions = {} local creative_mode = minetest.settings:get_bool("creative_mode") local mod_death_messages = minetest.get_modpath("mcl_death_messages") ~= nil +local mod_fire = minetest.get_modpath("mcl_fire") ~= nil +local CONTENT_FIRE = minetest.get_content_id("mcl_fire:fire") local S = minetest.get_translator("mcl_explosions") @@ -134,12 +136,13 @@ end -- raydirs - The directions for each ray -- radius - The maximum distance each ray will go -- drop_chance - The chance that destroyed nodes will drop their items +-- fire - If true, 1/3 of destroyed nodes become fire -- puncher - object that punches other objects (optional) -- -- Note that this function has been optimized, it contains code which has been -- inlined to avoid function calls and unnecessary table creation. This was -- measured to give a significant performance increase. -local function trace_explode(pos, strength, raydirs, radius, drop_chance, puncher) +local function trace_explode(pos, strength, raydirs, radius, drop_chance, fire, puncher) local vm = minetest.get_voxel_manip() local emin, emax = vm:read_from_map(vector.subtract(pos, radius), @@ -325,7 +328,11 @@ local function trace_explode(pos, strength, raydirs, radius, drop_chance, punche end end if remove then - data[idx] = minetest.CONTENT_AIR + if mod_fire and math.random(1, 3) == 1 then + data[idx] = CONTENT_FIRE + else + data[idx] = minetest.CONTENT_AIR + end end end @@ -361,7 +368,7 @@ function mcl_explosions.explode(pos, strength, info, puncher) end shape = sphere_shapes[radius] - trace_explode(pos, strength, shape, radius, (info and info.drop_chance) or 1 / strength, puncher) + trace_explode(pos, strength, shape, radius, (info and info.drop_chance) or 1 / strength, info.fire == true, puncher) if not (info and info.no_sound) then add_particles(pos, radius) diff --git a/mods/CORE/mcl_explosions/mod.conf b/mods/CORE/mcl_explosions/mod.conf index 382ece9a..7ce4b678 100644 --- a/mods/CORE/mcl_explosions/mod.conf +++ b/mods/CORE/mcl_explosions/mod.conf @@ -1,2 +1,3 @@ name = mcl_explosions description = A common API to create explosions. +optional_depends = mcl_fire diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index dd0d2e5d..425355f7 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3824,7 +3824,7 @@ end -- no damage to nodes explosion -function mobs:safe_boom(self, pos, radius) +function mobs:safe_boom(self, pos, strength) minetest.sound_play(self.sounds and self.sounds.explode or "tnt_explode", { pos = pos, gain = 1.0, @@ -3837,13 +3837,13 @@ end -- make explosion with protection and tnt mod check -function mobs:boom(self, pos, radius) +function mobs:boom(self, pos, strength, fire) if mod_explosions then if mobs_griefing and not minetest.is_protected(pos, "") then - mcl_explosions.explode(pos, self.explosion_strength, { drop_chance = 1.0 }, self.object) + mcl_explosions.explode(pos, strength, { drop_chance = 1.0, fire = fire }, self.object) else - mobs:safe_boom(self, pos, radius) + mobs:safe_boom(self, pos, strength) end else mobs:safe_boom(self, pos, radius) diff --git a/mods/ENTITIES/mobs_mc/ghast.lua b/mods/ENTITIES/mobs_mc/ghast.lua index 08fbb99f..2efe56af 100644 --- a/mods/ENTITIES/mobs_mc/ghast.lua +++ b/mods/ENTITIES/mobs_mc/ghast.lua @@ -79,13 +79,12 @@ mobs:register_arrow("mobs_mc:fireball", { textures = {"mcl_fire_fire_charge.png"}, velocity = 15, - -- direct hit, no fire... just plenty of pain hit_player = function(self, player) player:punch(self.object, 1.0, { full_punch_interval = 1.0, damage_groups = {fleshy = 6}, }, nil) - mobs:boom(self, self.object:get_pos(), 3) + mobs:boom(self, self.object:get_pos(), 1, true) end, hit_mob = function(self, mob) @@ -93,12 +92,11 @@ mobs:register_arrow("mobs_mc:fireball", { full_punch_interval = 1.0, damage_groups = {fleshy = 6}, }, nil) - mobs:boom(self, self.object:get_pos(), 3) + mobs:boom(self, self.object:get_pos(), 1, true) end, - -- node hit, explode hit_node = function(self, pos, node) - mobs:boom(self, pos, 3) + mobs:boom(self, pos, 1, true) end }) diff --git a/mods/ITEMS/mcl_beds/depends.txt b/mods/ITEMS/mcl_beds/depends.txt index 34e12adc..c7c874fd 100644 --- a/mods/ITEMS/mcl_beds/depends.txt +++ b/mods/ITEMS/mcl_beds/depends.txt @@ -3,7 +3,7 @@ mcl_sounds? mcl_worlds? mcl_wool? mcl_dye? -mcl_tnt? +mcl_explosions? mcl_weather? mcl_spawn? doc?