Support mob explosions again

This commit is contained in:
Wuzzy 2017-07-25 04:44:46 +02:00
parent b25254e516
commit 388b324fb1
3 changed files with 46 additions and 34 deletions

View File

@ -1694,7 +1694,7 @@ local do_states = function(self, dtime)
self.object:remove() self.object:remove()
if minetest.get_modpath("tnt") and tnt and tnt.boom if minetest.get_modpath("mcl_tnt") and tnt and tnt.boom
and not minetest.is_protected(pos, "") then and not minetest.is_protected(pos, "") then
tnt.boom(pos, { tnt.boom(pos, {

View File

@ -1,4 +1,5 @@
mcl_core mcl_core
mcl_tnt?
invisibility? invisibility?
intllib? intllib?
lucky_block? lucky_block?

View File

@ -158,38 +158,50 @@ function TNT:on_step(dtime)
self.blinkstatus = not self.blinkstatus self.blinkstatus = not self.blinkstatus
end end
if self.timer > 4 then if self.timer > 4 then
local pos = self.object:getpos() tnt.boom(self.object:getpos(), TNT_RANGE)
pos.x = math.floor(pos.x+0.5) self.object:remove()
pos.y = math.floor(pos.y+0.5) end
pos.z = math.floor(pos.z+0.5) end
do_tnt_physics(pos, TNT_RANGE)
local meta = minetest.get_meta(pos) tnt.boom = function(pos, info)
minetest.sound_play("tnt_explode", {pos = pos,gain = 1.0,max_hear_distance = 16,}) local range = info.radius
if minetest.get_node(pos).name == "mcl_core:water_source" or minetest.get_node(pos).name == "mcl_core:water_flowing" or minetest.get_node(pos).name == "mcl_core:bedrock" or minetest.get_node(pos).name == "protector:display" or minetest.is_protected(pos, "tnt") then local damage_range = info.damage_radius
-- Cancel the Explosion
self.object:remove() pos.x = math.floor(pos.x+0.5)
return pos.y = math.floor(pos.y+0.5)
pos.z = math.floor(pos.z+0.5)
do_tnt_physics(pos, range)
local meta = minetest.get_meta(pos)
local sound
if not info.sound then
sound = "tnt_explode"
else
sound = info.sound
end
minetest.sound_play(sound, {pos = pos,gain = 1.0,max_hear_distance = 16,})
if minetest.get_node(pos).name == "mcl_core:water_source" or minetest.get_node(pos).name == "mcl_core:water_flowing" or minetest.get_node(pos).name == "mcl_core:bedrock" or minetest.get_node(pos).name == "protector:display" or minetest.is_protected(pos, "tnt") then
-- Cancel the Explosion
return
end end
for x=-TNT_RANGE,TNT_RANGE do for x=-range,range do
for y=-TNT_RANGE,TNT_RANGE do for y=-range,range do
for z=-TNT_RANGE,TNT_RANGE do for z=-range,range do
if x*x+y*y+z*z <= TNT_RANGE * TNT_RANGE + TNT_RANGE then if x*x+y*y+z*z <= range * range + range then
local np={x=pos.x+x,y=pos.y+y,z=pos.z+z} local np={x=pos.x+x,y=pos.y+y,z=pos.z+z}
local n = minetest.get_node(np) local n = minetest.get_node(np)
local def = minetest.registered_nodes[n.name] local def = minetest.registered_nodes[n.name]
-- Simple blast resistance check (for now). This keeps the important blocks like bedrock, command block, etc. intact. -- Simple blast resistance check (for now). This keeps the important blocks like bedrock, command block, etc. intact.
-- TODO: Implement the real blast resistance algorithm -- TODO: Implement the real blast resistance algorithm
if def and n.name ~= "air" and n.name ~= "ignore" and (def._mcl_blast_resistance == nil or def._mcl_blast_resistance < 1000) then if def and n.name ~= "air" and n.name ~= "ignore" and (def._mcl_blast_resistance == nil or def._mcl_blast_resistance < 1000) then
activate_if_tnt(n.name, np, pos, 3) activate_if_tnt(n.name, np, pos, 3)
minetest.remove_node(np) minetest.remove_node(np)
core.check_for_falling(np) core.check_for_falling(np)
if n.name ~= "mcl_tnt:tnt" and math.random() > 0.9 then if n.name ~= "mcl_tnt:tnt" and math.random() > 0.9 then
local drop = minetest.get_node_drops(n.name, "") local drop = minetest.get_node_drops(n.name, "")
for _,item in ipairs(drop) do for _,item in ipairs(drop) do
if type(item) == "string" then if type(item) == "string" then
if math.random(1,100) > 40 then if math.random(1,100) > 40 then
local obj = minetest.add_item(np, item) local obj = minetest.add_item(np, item)
end
end end
end end
end end
@ -197,9 +209,8 @@ function TNT:on_step(dtime)
end end
end end
end end
self.object:remove()
add_effects(pos, TNT_RANGE, {})
end end
add_effects(pos, range, {})
end end
end end