1 local S
= minetest
.get_translator("mcl_tnt")
2 local tnt_griefing
= minetest
.settings
:get_bool("mcl_tnt_griefing", true)
4 local mod_death_messages
= minetest
.get_modpath("mcl_death_messages")
6 local function spawn_tnt(pos
, entname
)
7 minetest
.sound_play("tnt_ignite", {pos
= pos
,gain
= 1.0,max_hear_distance
= 15,}, true)
8 local tnt
= minetest
.add_entity(pos
, entname
)
9 tnt
:set_armor_groups({immortal
=1})
14 tnt
.ignite
= function(pos
)
15 minetest
.remove_node(pos
)
16 local e
= spawn_tnt(pos
, "mcl_tnt:tnt")
17 minetest
.check_for_falling(pos
)
21 -- Add smoke particle of entity at pos.
22 -- Intended to be called every step
23 tnt
.smoke_step
= function(pos
)
24 minetest
.add_particle({
25 pos
= {x
=pos
.x
,y
=pos
.y
+0.5,z
=pos
.z
},
26 velocity
= vector
.new(math
.random() * 0.2 - 0.1, 1.0 + math
.random(), math
.random() * 0.2 - 0.1),
27 acceleration
= vector
.new(0, -0.1, 0),
28 expirationtime
= 0.15 + math
.random() * 0.25,
29 size
= 1.0 + math
.random(),
30 collisiondetection
= false,
31 texture
= "mcl_particles_smoke.png"
41 if minetest
.get_modpath("mcl_sounds") then
42 sounds
= mcl_sounds
.node_sound_wood_defaults()
45 if minetest
.get_modpath("mesecons") then
46 tnt_mesecons
= {effector
= {
47 action_on
= tnt
.ignite
,
48 rules
= mesecon
.rules
.alldirs
,
54 longdesc
= S("An explosive device. When it explodes, it will hurt living beings and destroy blocks around it. TNT has an explosion radius of @1. With a small chance, blocks may drop as an item (as if being mined) rather than being destroyed. TNT can be ignited by tools, explosions, fire, lava and redstone signals.", TNT_RANGE
)
56 longdesc
= S("An explosive device. When it explodes, it will hurt living beings. TNT has an explosion radius of @1. TNT can be ignited by tools, explosions, fire, lava and redstone signals.", TNT_RANGE
)
59 minetest
.register_node("mcl_tnt:tnt", {
60 tiles
= {"default_tnt_top.png", "default_tnt_bottom.png",
61 "default_tnt_side.png", "default_tnt_side.png",
62 "default_tnt_side.png", "default_tnt_side.png"},
63 is_ground_content
= false,
65 description
= S("TNT"),
67 sunlight_propagates
= true,
68 _tt_help
= S("Ignited by tools, explosions, fire, lava, redstone power").."\n"..S("Explosion radius: @1", tostring(TNT_RANGE
)),
69 _doc_items_longdesc
= longdesc
,
70 _doc_items_usagehelp
= S("Place the TNT and ignite it with one of the methods above. Quickly get in safe distance. The TNT will start to be affected by gravity and explodes in 4 seconds."),
71 groups
= { dig_immediate
= 3, tnt
= 1, enderman_takable
=1, flammable
=-1 },
72 mesecons
= tnt_mesecons
,
73 on_blast
= function(pos
)
74 local e
= tnt
.ignite(pos
)
75 e
:get_luaentity().timer
= tnt
.BOOMTIMER
- (0.5 + math
.random())
77 _on_ignite
= function(player
, pointed_thing
)
78 tnt
.ignite(pointed_thing
.under
)
81 _on_burn
= function(pos
)
85 _on_dispense
= function(stack
, pos
, droppos
, dropnode
, dropdir
)
86 -- Place and ignite TNT
87 if minetest
.registered_nodes
[dropnode
.name
].buildable_to
then
88 minetest
.set_node(droppos
, {name
= stack
:get_name()})
97 physical
= true, -- Collides with things
99 collisionbox
= {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
101 textures
= {"default_tnt_top.png", "default_tnt_bottom.png",
102 "default_tnt_side.png", "default_tnt_side.png",
103 "default_tnt_side.png", "default_tnt_side.png"},
104 -- Initial value for our timer
107 tnt_knockback
= true,
110 function TNT
:on_activate(staticdata
)
111 local phi
= math
.random(0, 65535) / 65535 * 2*math
.pi
112 local hdir_x
= math
.cos(phi
) * 0.02
113 local hdir_z
= math
.sin(phi
) * 0.02
114 self
.object
:set_velocity({x
=hdir_x
, y
=2, z
=hdir_z
})
115 self
.object
:set_acceleration({x
=0, y
=-10, z
=0})
116 self
.object
:set_texture_mod("^mcl_tnt_blink.png")
119 local function add_effects(pos
, radius
, drops
)
120 minetest
.add_particlespawner({
123 minpos
= vector
.subtract(pos
, radius
/ 2),
124 maxpos
= vector
.add(pos
, radius
/ 2),
125 minvel
= {x
= -10, y
= -10, z
= -10},
126 maxvel
= {x
= 10, y
= 10, z
= 10},
127 minacc
= vector
.new(),
128 maxacc
= vector
.new(),
131 minsize
= radius
* 1,
132 maxsize
= radius
* 3,
133 texture
= "mcl_particles_smoke.png",
136 -- we just dropped some items. Look at the items entities and pick
137 -- one of them to use as texture
138 local texture
= "mcl_particles_smoke.png" --fallback texture
140 for name
, stack
in pairs(drops
) do
141 local count
= stack
:get_count()
144 local def
= minetest
.registered_nodes
[name
]
145 if def
and def
.tiles
and def
.tiles
[1] then
146 texture
= def
.tiles
[1]
151 minetest
.add_particlespawner({
154 minpos
= vector
.subtract(pos
, radius
/ 2),
155 maxpos
= vector
.add(pos
, radius
/ 2),
156 minvel
= {x
= -3, y
= 0, z
= -3},
157 maxvel
= {x
= 3, y
= 5, z
= 3},
158 minacc
= {x
= 0, y
= -10, z
= 0},
161 minsize
= radius
* 0.66,
162 maxsize
= radius
* 2,
164 collisiondetection
= true,
168 function TNT
:on_step(dtime
)
169 local pos
= self
.object
:get_pos()
171 self
.timer
= self
.timer
+ dtime
172 self
.blinktimer
= self
.blinktimer
+ dtime
173 if self
.blinktimer
> tnt
.BLINKTIMER
then
174 self
.blinktimer
= self
.blinktimer
- tnt
.BLINKTIMER
175 if self
.blinkstatus
then
176 self
.object
:set_texture_mod("")
178 self
.object
:set_texture_mod("^mcl_tnt_blink.png")
180 self
.blinkstatus
= not self
.blinkstatus
182 if self
.timer
> tnt
.BOOMTIMER
then
183 mcl_explosions
.explode(self
.object
:get_pos(), 4, { drop_chance
= 1.0 }, self
.object
)
188 minetest
.register_entity("mcl_tnt:tnt", TNT
)
190 if minetest
.get_modpath("mcl_mobitems") then
191 minetest
.register_craft({
192 output
= "mcl_tnt:tnt",
194 {'mcl_mobitems:gunpowder','group:sand','mcl_mobitems:gunpowder'},
195 {'group:sand','mcl_mobitems:gunpowder','group:sand'},
196 {'mcl_mobitems:gunpowder','group:sand','mcl_mobitems:gunpowder'}
201 if minetest
.get_modpath("doc_identifier") then
202 doc
.sub
.identifier
.register_object("mcl_tnt:tnt", "nodes", "mcl_tnt:tnt")