Update helptext of obsidian
[MineClone/MineClone2.git] / mods / ITEMS / mcl_tnt / init.lua
blobef4fb33c22e40083b6341fa254d18547a208c051
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})
10 return tnt
11 end
13 tnt = {}
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)
18 return e
19 end
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"
33 end
35 tnt.BOOMTIMER = 4
36 tnt.BLINKTIMER = 0.25
38 local TNT_RANGE = 3
40 local sounds
41 if minetest.get_modpath("mcl_sounds") then
42 sounds = mcl_sounds.node_sound_wood_defaults()
43 end
44 local tnt_mesecons
45 if minetest.get_modpath("mesecons") then
46 tnt_mesecons = {effector = {
47 action_on = tnt.ignite,
48 rules = mesecon.rules.alldirs,
50 end
52 local longdesc
53 if tnt_griefing then
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)
55 else
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)
57 end
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,
64 stack_max = 64,
65 description = S("TNT"),
66 paramtype = "light",
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())
76 end,
77 _on_ignite = function(player, pointed_thing)
78 tnt.ignite(pointed_thing.under)
79 return true
80 end,
81 _on_burn = function(pos)
82 tnt.ignite(pos)
83 return true
84 end,
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()})
89 tnt.ignite(droppos)
90 end
91 end,
92 sounds = sounds,
95 local TNT = {
96 -- Static definition
97 physical = true, -- Collides with things
98 --weight = -100,
99 collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
100 visual = "cube",
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
105 timer = 0,
106 blinktimer = 0,
107 tnt_knockback = true,
108 blinkstatus = 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({
121 amount = 64,
122 time = 0.5,
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(),
129 minexptime = 1,
130 maxexptime = 2.5,
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
139 local most = 0
140 for name, stack in pairs(drops) do
141 local count = stack:get_count()
142 if count > most then
143 most = 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({
152 amount = 32,
153 time = 0.1,
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},
159 minexptime = 0.8,
160 maxexptime = 2.0,
161 minsize = radius * 0.66,
162 maxsize = radius * 2,
163 texture = texture,
164 collisiondetection = true,
168 function TNT:on_step(dtime)
169 local pos = self.object:get_pos()
170 tnt.smoke_step(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("")
177 else
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)
184 self.object:remove()
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",
193 recipe = {
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")