2017-01-16 16:59:16 +03:00
|
|
|
local function spawn_tnt(pos, entname)
|
2017-01-05 02:08:50 +03:00
|
|
|
minetest.sound_play("tnt_ignite", {pos = pos,gain = 1.0,max_hear_distance = 15,})
|
2017-01-11 20:21:46 +03:00
|
|
|
return minetest.add_entity(pos, entname)
|
2015-06-29 20:55:56 +03:00
|
|
|
end
|
|
|
|
|
2017-01-16 16:59:16 +03:00
|
|
|
local function activate_if_tnt(nname, np, tnt_np, tntr)
|
2015-06-29 20:55:56 +03:00
|
|
|
if nname == "tnt:tnt" then
|
|
|
|
local e = spawn_tnt(np, nname)
|
|
|
|
e:setvelocity({x=(np.x - tnt_np.x)*5+(tntr / 4), y=(np.y - tnt_np.y)*5+(tntr / 3), z=(np.z - tnt_np.z)*5+(tntr / 4)})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-16 16:59:16 +03:00
|
|
|
local function do_tnt_physics(tnt_np,tntr)
|
2017-01-11 20:21:46 +03:00
|
|
|
local objs = minetest.get_objects_inside_radius(tnt_np, tntr)
|
2015-06-29 20:55:56 +03:00
|
|
|
for k, obj in pairs(objs) do
|
|
|
|
local oname = obj:get_entity_name()
|
|
|
|
local v = obj:getvelocity()
|
|
|
|
local p = obj:getpos()
|
|
|
|
if oname == "tnt:tnt" then
|
|
|
|
obj:setvelocity({x=(p.x - tnt_np.x) + (tntr / 2) + v.x, y=(p.y - tnt_np.y) + tntr + v.y, z=(p.z - tnt_np.z) + (tntr / 2) + v.z})
|
|
|
|
else
|
|
|
|
if v ~= nil then
|
|
|
|
obj:setvelocity({x=(p.x - tnt_np.x) + (tntr / 4) + v.x, y=(p.y - tnt_np.y) + (tntr / 2) + v.y, z=(p.z - tnt_np.z) + (tntr / 4) + v.z})
|
|
|
|
else
|
|
|
|
if obj:get_player_name() ~= nil then
|
|
|
|
obj:set_hp(obj:get_hp() - 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-16 16:59:16 +03:00
|
|
|
tnt = {}
|
|
|
|
tnt.ignite = function(pos)
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
spawn_tnt(pos, "tnt:tnt")
|
|
|
|
nodeupdate(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-06-29 20:55:56 +03:00
|
|
|
minetest.register_node("tnt:tnt", {
|
2017-01-16 15:00:20 +03:00
|
|
|
tiles = {"default_tnt_top.png", "default_tnt_bottom.png",
|
2015-06-29 20:55:56 +03:00
|
|
|
"default_tnt_side.png", "default_tnt_side.png",
|
|
|
|
"default_tnt_side.png", "default_tnt_side.png"},
|
2017-01-16 15:00:20 +03:00
|
|
|
drop = '', -- Get nothing
|
2017-01-05 00:36:51 +03:00
|
|
|
is_ground_content = false,
|
2015-06-29 20:55:56 +03:00
|
|
|
stack_max = 64,
|
|
|
|
description = "TNT",
|
|
|
|
mesecons = {effector = {
|
2017-01-16 16:59:16 +03:00
|
|
|
action_on = tnt.ignite
|
2017-01-05 02:18:59 +03:00
|
|
|
}},
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2015-06-29 20:55:56 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
local TNT_RANGE = 3
|
|
|
|
local TNT = {
|
|
|
|
-- Static definition
|
|
|
|
physical = true, -- Collides with things
|
|
|
|
--weight = -100,
|
|
|
|
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
|
|
|
visual = "cube",
|
|
|
|
textures = {"default_tnt_top.png", "default_tnt_bottom.png",
|
|
|
|
"default_tnt_side.png", "default_tnt_side.png",
|
|
|
|
"default_tnt_side.png", "default_tnt_side.png"},
|
|
|
|
-- Initial value for our timer
|
|
|
|
timer = 0,
|
|
|
|
-- Number of punches required to defuse
|
|
|
|
health = 1,
|
|
|
|
blinktimer = 0,
|
|
|
|
blinkstatus = true,}
|
|
|
|
|
|
|
|
function TNT:on_activate(staticdata)
|
|
|
|
self.object:setvelocity({x=0, y=4, z=0})
|
|
|
|
self.object:setacceleration({x=0, y=-10, z=0})
|
|
|
|
self.object:settexturemod("^[brighten")
|
|
|
|
end
|
|
|
|
|
|
|
|
function TNT:on_step(dtime)
|
|
|
|
local pos = self.object:getpos()
|
|
|
|
minetest.add_particle({x=pos.x,y=pos.y+0.5,z=pos.z}, {x=math.random(-.1,.1),y=math.random(1,2),z=math.random(-.1,.1)}, {x=0,y=-0.1,z=0}, math.random(.5,1),math.random(1,2), false, "tnt_smoke.png")
|
|
|
|
self.timer = self.timer + dtime
|
|
|
|
self.blinktimer = self.blinktimer + dtime
|
|
|
|
if self.blinktimer > 0.5 then
|
|
|
|
self.blinktimer = self.blinktimer - 0.5
|
|
|
|
if self.blinkstatus then
|
|
|
|
self.object:settexturemod("")
|
|
|
|
else
|
|
|
|
self.object:settexturemod("^[brighten")
|
|
|
|
end
|
|
|
|
self.blinkstatus = not self.blinkstatus
|
|
|
|
end
|
2017-01-05 02:20:21 +03:00
|
|
|
if self.timer > 4 then
|
2015-06-29 20:55:56 +03:00
|
|
|
local pos = self.object:getpos()
|
|
|
|
pos.x = math.floor(pos.x+0.5)
|
|
|
|
pos.y = math.floor(pos.y+0.5)
|
|
|
|
pos.z = math.floor(pos.z+0.5)
|
|
|
|
do_tnt_physics(pos, TNT_RANGE)
|
2017-01-11 20:21:46 +03:00
|
|
|
local meta = minetest.get_meta(pos)
|
2015-06-29 20:55:56 +03:00
|
|
|
minetest.sound_play("tnt_explode", {pos = pos,gain = 1.0,max_hear_distance = 16,})
|
2017-01-11 20:21:46 +03:00
|
|
|
if minetest.get_node(pos).name == "default:water_source" or minetest.get_node(pos).name == "default:water_flowing" or minetest.get_node(pos).name == "default:bedrock" or minetest.get_node(pos).name == "protector:display" or minetest.is_protected(pos, "tnt") then
|
2015-06-29 20:55:56 +03:00
|
|
|
-- Cancel the Explosion
|
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
for x=-TNT_RANGE,TNT_RANGE do
|
|
|
|
for y=-TNT_RANGE,TNT_RANGE do
|
|
|
|
for z=-TNT_RANGE,TNT_RANGE do
|
|
|
|
if x*x+y*y+z*z <= TNT_RANGE * TNT_RANGE + TNT_RANGE then
|
|
|
|
local np={x=pos.x+x,y=pos.y+y,z=pos.z+z}
|
2017-01-11 20:21:46 +03:00
|
|
|
local n = minetest.get_node(np)
|
2015-06-29 20:55:56 +03:00
|
|
|
if n.name ~= "air" and n.name ~= "default:obsidian" and n.name ~= "default:bedrock" and n.name ~= "protector:protect" then
|
|
|
|
activate_if_tnt(n.name, np, pos, 3)
|
2017-01-11 20:21:46 +03:00
|
|
|
minetest.remove_node(np)
|
2015-06-29 20:55:56 +03:00
|
|
|
nodeupdate(np)
|
|
|
|
if n.name ~= "tnt:tnt" and math.random() > 0.9 then
|
|
|
|
local drop = minetest.get_node_drops(n.name, "")
|
|
|
|
for _,item in ipairs(drop) do
|
|
|
|
if type(item) == "string" then
|
|
|
|
if math.random(1,100) > 40 then
|
2017-01-11 20:21:46 +03:00
|
|
|
local obj = minetest.add_item(np, item)
|
2015-06-29 20:55:56 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_entity("tnt:tnt", TNT)
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "tnt:tnt",
|
|
|
|
recipe = {
|
2017-01-10 05:02:28 +03:00
|
|
|
{'default:gunpowder','group:sand','default:gunpowder'},
|
|
|
|
{'group:sand','default:gunpowder','group:sand'},
|
|
|
|
{'default:gunpowder','group:sand','default:gunpowder'}
|
2015-06-29 20:55:56 +03:00
|
|
|
}
|
2017-01-05 00:36:51 +03:00
|
|
|
})
|