forked from MineClone5/MineClone5
Add fire explosions
This commit is contained in:
parent
00acbf8a2a
commit
bc740efafe
|
@ -14,6 +14,8 @@ mcl_explosions = {}
|
||||||
|
|
||||||
local creative_mode = minetest.settings:get_bool("creative_mode")
|
local creative_mode = minetest.settings:get_bool("creative_mode")
|
||||||
local mod_death_messages = minetest.get_modpath("mcl_death_messages") ~= nil
|
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")
|
local S = minetest.get_translator("mcl_explosions")
|
||||||
|
|
||||||
|
@ -134,12 +136,13 @@ end
|
||||||
-- raydirs - The directions for each ray
|
-- raydirs - The directions for each ray
|
||||||
-- radius - The maximum distance each ray will go
|
-- radius - The maximum distance each ray will go
|
||||||
-- drop_chance - The chance that destroyed nodes will drop their items
|
-- 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)
|
-- puncher - object that punches other objects (optional)
|
||||||
--
|
--
|
||||||
-- Note that this function has been optimized, it contains code which has been
|
-- Note that this function has been optimized, it contains code which has been
|
||||||
-- inlined to avoid function calls and unnecessary table creation. This was
|
-- inlined to avoid function calls and unnecessary table creation. This was
|
||||||
-- measured to give a significant performance increase.
|
-- 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 vm = minetest.get_voxel_manip()
|
||||||
|
|
||||||
local emin, emax = vm:read_from_map(vector.subtract(pos, radius),
|
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
|
||||||
end
|
end
|
||||||
if remove then
|
if remove then
|
||||||
|
if mod_fire and math.random(1, 3) == 1 then
|
||||||
|
data[idx] = CONTENT_FIRE
|
||||||
|
else
|
||||||
data[idx] = minetest.CONTENT_AIR
|
data[idx] = minetest.CONTENT_AIR
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Log explosion
|
-- Log explosion
|
||||||
minetest.log('action', 'Explosion at ' .. minetest.pos_to_string(pos) ..
|
minetest.log('action', 'Explosion at ' .. minetest.pos_to_string(pos) ..
|
||||||
|
@ -361,7 +368,7 @@ function mcl_explosions.explode(pos, strength, info, puncher)
|
||||||
end
|
end
|
||||||
shape = sphere_shapes[radius]
|
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
|
if not (info and info.no_sound) then
|
||||||
add_particles(pos, radius)
|
add_particles(pos, radius)
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
name = mcl_explosions
|
name = mcl_explosions
|
||||||
description = A common API to create explosions.
|
description = A common API to create explosions.
|
||||||
|
optional_depends = mcl_fire
|
||||||
|
|
|
@ -3824,7 +3824,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
-- no damage to nodes explosion
|
-- 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", {
|
minetest.sound_play(self.sounds and self.sounds.explode or "tnt_explode", {
|
||||||
pos = pos,
|
pos = pos,
|
||||||
gain = 1.0,
|
gain = 1.0,
|
||||||
|
@ -3837,13 +3837,13 @@ end
|
||||||
|
|
||||||
|
|
||||||
-- make explosion with protection and tnt mod check
|
-- 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 mod_explosions then
|
||||||
if mobs_griefing and not minetest.is_protected(pos, "") 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
|
else
|
||||||
mobs:safe_boom(self, pos, radius)
|
mobs:safe_boom(self, pos, strength)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
mobs:safe_boom(self, pos, radius)
|
mobs:safe_boom(self, pos, radius)
|
||||||
|
|
|
@ -79,13 +79,12 @@ mobs:register_arrow("mobs_mc:fireball", {
|
||||||
textures = {"mcl_fire_fire_charge.png"},
|
textures = {"mcl_fire_fire_charge.png"},
|
||||||
velocity = 15,
|
velocity = 15,
|
||||||
|
|
||||||
-- direct hit, no fire... just plenty of pain
|
|
||||||
hit_player = function(self, player)
|
hit_player = function(self, player)
|
||||||
player:punch(self.object, 1.0, {
|
player:punch(self.object, 1.0, {
|
||||||
full_punch_interval = 1.0,
|
full_punch_interval = 1.0,
|
||||||
damage_groups = {fleshy = 6},
|
damage_groups = {fleshy = 6},
|
||||||
}, nil)
|
}, nil)
|
||||||
mobs:boom(self, self.object:get_pos(), 3)
|
mobs:boom(self, self.object:get_pos(), 1, true)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
hit_mob = function(self, mob)
|
hit_mob = function(self, mob)
|
||||||
|
@ -93,12 +92,11 @@ mobs:register_arrow("mobs_mc:fireball", {
|
||||||
full_punch_interval = 1.0,
|
full_punch_interval = 1.0,
|
||||||
damage_groups = {fleshy = 6},
|
damage_groups = {fleshy = 6},
|
||||||
}, nil)
|
}, nil)
|
||||||
mobs:boom(self, self.object:get_pos(), 3)
|
mobs:boom(self, self.object:get_pos(), 1, true)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- node hit, explode
|
|
||||||
hit_node = function(self, pos, node)
|
hit_node = function(self, pos, node)
|
||||||
mobs:boom(self, pos, 3)
|
mobs:boom(self, pos, 1, true)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ mcl_sounds?
|
||||||
mcl_worlds?
|
mcl_worlds?
|
||||||
mcl_wool?
|
mcl_wool?
|
||||||
mcl_dye?
|
mcl_dye?
|
||||||
mcl_tnt?
|
mcl_explosions?
|
||||||
mcl_weather?
|
mcl_weather?
|
||||||
mcl_spawn?
|
mcl_spawn?
|
||||||
doc?
|
doc?
|
||||||
|
|
Loading…
Reference in New Issue