Add fire explosions

This commit is contained in:
Wuzzy 2020-05-02 19:05:56 +02:00
parent 00acbf8a2a
commit bc740efafe
5 changed files with 19 additions and 13 deletions

@ -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,9 +328,13 @@ local function trace_explode(pos, strength, raydirs, radius, drop_chance, punche
end
end
if remove then
if mod_fire and math.random(1, 3) == 1 then
data[idx] = CONTENT_FIRE
else
data[idx] = minetest.CONTENT_AIR
end
end
end
-- Log explosion
minetest.log('action', 'Explosion at ' .. minetest.pos_to_string(pos) ..
@ -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)

@ -1,2 +1,3 @@
name = mcl_explosions
description = A common API to create explosions.
optional_depends = mcl_fire

@ -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)

@ -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
})

@ -3,7 +3,7 @@ mcl_sounds?
mcl_worlds?
mcl_wool?
mcl_dye?
mcl_tnt?
mcl_explosions?
mcl_weather?
mcl_spawn?
doc?