-
Notifications
You must be signed in to change notification settings - Fork 2
/
molotov.lua
379 lines (363 loc) · 12.4 KB
/
molotov.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
--Molotov Cocktail_[rev002]
--base code is from throwing enhanced and potions mods
local MOD_NAME = minetest.get_current_modname()
local MOD_PATH = minetest.get_modpath(MOD_NAME)
local Vec3 = dofile(MOD_PATH..'/lib/Vec3_1-0.lua')
minetest.register_craftitem('more_fire:molotov_cocktail', {
description = 'Molotov Cocktail',
inventory_image = 'more_fire_molotov_cocktail.png',
on_place = function(itemstack, user, pointed_thing)
itemstack:take_item()
minetest.sound_play('more_fire_shatter', {gain = 1.0})
n = minetest.get_node(pointed_thing)
if pointed_thing.type == 'node' then
minetest.add_node(pointed_thing.above, {name='more_fire:napalm'})
minetest.sound_play('more_fire_ignite', {pos,pos})
end
--Shattered glass Particles
minetest.add_particlespawner({
amount = 40,
time = 0.1,
minpos = pointed_thing.above,
maxpos = pointed_thing.above,
minvel = {x=2, y=0.2, z=2},
maxvel = {x=-2, y=0.5, z=-2},
minacc = {x=0, y=-6, z=0},
maxacc = {x=0, y=-10, z=0},
minexptim = 0.5,
maxexptime = 2,
minsize = 0.2,
maxsize = 5,
collisiondetection = true,
texture = 'more_fire_shatter.png'})
--fire ember particles
minetest.add_particlespawner({
amount = 100,
time = 0.1,
minpos = pointed_thing.above,
maxpos = pointed_thing.above,
minvel = {x=-2, y=0.5, z=-2},
maxvel = {x=2, y=0.5, z=2},
minacc = {x=0, y=-10, z=0},
maxacc = {x=0, y=-6, z=0},
minexptime = 2,
maxexptime = 3,
minsize = 0.25,
maxsize = 0.5,
collisiondetection = true,
texture = 'more_fire_spark.png'})
local dir = Vec3(user:get_look_dir()) *20
minetest.add_particle(
{x=user:getpos().x, y=user:getpos().y+1.5, z=user:getpos().z}, {x=dir.x, y=dir.y, z=dir.z}, {x=0, y=-10, z=0}, 0.2,
6, false, 'more_fire_molotov_cocktail.png')
return itemstack
end,
})
local function throw_cocktail(item, player)
local playerpos = player:getpos()
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.625,z=playerpos.z}, 'more_fire:molotov_entity')
local dir = player:get_look_dir()
obj:setvelocity({x=dir.x*30, y=dir.y*30, z=dir.z*30})
obj:setacceleration({x=dir.x*-3, y=-dir.y^8*80-10, z=dir.z*-3})
if not minetest.settings:get_bool('creative_mode') then
item:take_item()
end
return item
end
local radius = 5.0
local function add_effects(pos, radius)
minetest.add_particlespawner({
amount = 10,
time = 0.2,
minpos = vector.subtract(pos, radius / 2),
maxpos = vector.add(pos, radius / 2),
minvel = {x=-2, y=-2, z=-2},
maxvel = {x=2, y=-4, z=2},
minacc = {x=0, y=-4, z=0},
--~ maxacc = {x=-20, y=-50, z=-50},
minexptime = 1,
maxexptime = 1.5,
minsize = 1,
maxsize = 2,
texture = 'more_fire_spark.png',
})
minetest.add_particlespawner({
amount = 10,
time = 0.2,
minpos = vector.subtract(pos, radius / 2),
maxpos = vector.add(pos, radius / 2),
minvel = {x=-1.25, y=-1.25, z=-1.25},
maxvel = {x=0.5, y=-4, z=0.5},
minacc = {x=1.25, y=-1.25, z=1.25},
--~ maxacc = {x=-20, y=-50, z=-50},
minexptime =1,
maxexptime = 1.5,
minsize = 1,
maxsize = 2,
texture = 'more_fire_spark.png',
})
end
local function napalm(pos)
minetest.sound_play('more_fire_ignite', {pos=pos, gain=1})
minetest.set_node(pos, {name='more_fire:napalm'})
minetest.get_node_timer(pos):start(5.0)
add_effects(pos, radius)
end
local MORE_FIRE_MOLOTOV_ENTITY = {
timer=0,
collisionbox = {0,0,0,0,0,0},
physical = false,
textures = {'more_fire_molotov_cocktail.png'},
lastpos={},
}
MORE_FIRE_MOLOTOV_ENTITY.on_step = function(self, dtime)
self.timer = self.timer + dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
minetest.add_particlespawner({
amount = 10,
time = 0.5,
minpos = pos,
maxpos = pos,
minvel = {x=-0, y=0, z=-0.5},
maxvel = {x=0, y=0, z=-0.75},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 0.5,
maxexptime = 1,
minsize = 0.25,
maxsize = 0.5,
texture = 'more_fire_smoke.png',
})
minetest.add_particlespawner({
amount = 100,
time = 0.25,
minpos = pos,
maxpos = pos,
minvel = {x=-0, y=0, z=-0.5},
maxvel = {x=0, y=0, z=-0.75},
minacc = {x=0, y=0, z=-0.75},
maxacc = {x=-0, y=0, z=-0.5},
minexptime = 0.25,
maxexptime = 0.5,
minsize = 0.5,
maxsize = 0.75,
texture = 'more_fire_spark.png',
})
if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= 'more_fire:molotov_entity' and obj:get_luaentity().name ~= '__builtin:item' then
if self.node ~= '' then
minetest.sound_play('more_fire_shatter', {gain = 1.0})
for dx=-3,3 do
for dy=-3,3 do
for dz=-3,3 do
local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local n = minetest.get_node(pos).name
if minetest.registered_nodes[n].groups.flammable or math.random(1, 100) <= 20 then
minetest.sound_play('more_fire_ignite', {pos = self.lastpos})
minetest.set_node(p, {name='more_fire:napalm'})
else
--minetest.remove_node(p)
minetest.sound_play('more_fire_ignite', {pos = self.lastpos})
minetest.set_node(p, {name='fire:basic_flame'})
end
end
end
end
end
self.object:remove()
end
else
if self.node ~= '' then
minetest.sound_play('more_fire_shatter', {gain = 1.0})
for dx=-2,2 do
for dy=-2,2 do
for dz=-2,2 do
local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local n = minetest.get_node(pos).name
if minetest.registered_nodes[n].groups.flammable or math.random(1, 100) <= 20 then
minetest.sound_play('more_fire_ignite', {pos = self.lastpos})
minetest.set_node(p, {name='more_fire:napalm'})
else
--minetest.remove_node(p)
minetest.sound_play('more_fire_ignite', {pos = self.lastpos})
minetest.set_node(p, {name='fire:basic_flame'})
end
end
end
end
end
self.object:remove()
end
end
end
if self.lastpos.x~=nil then
if node.name ~= 'air' then
if self.node ~= '' then
minetest.sound_play('more_fire_shatter', {gain = 1.0})
for dx=-1,1 do
for dy=-1,1 do
for dz=-1,1 do
local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local n = minetest.get_node(pos).name
if minetest.registered_nodes[n].groups.flammable or math.random(1, 100) <= 20 then
minetest.sound_play('more_fire_ignite', {pos = self.lastpos})
minetest.set_node(p, {name='more_fire:napalm'})
else
minetest.sound_play('more_fire_ignite', {pos = self.lastpos})
minetest.set_node(p, {name='fire:basic_flame'})
end
end
end
end
end
self.object:remove()
napalm(self.lastpos)
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
minetest.register_entity('more_fire:molotov_entity', MORE_FIRE_MOLOTOV_ENTITY)
minetest.override_item('more_fire:molotov_cocktail', {on_use = throw_cocktail})
minetest.register_node('more_fire:napalm', {
drawtype = 'firelike',
tiles = {{
name='fire_basic_flame_animated.png',
animation={type='vertical_frames', aspect_w=16, aspect_h=16, length=1},
}},
inventory_image = 'fire_basic_flame.png',
light_source = 14,
groups = {igniter=1,dig_immediate=3, not_in_creative_inventory =1, not_in_craft_guide=1},
drop = '',
walkable = false,
buildable_to = true,
damage_per_second = 4,
})
minetest.register_abm({
nodenames={'more_fire:napalm'},
neighbors={'air'},
interval = 1,
chance = 1,
action = function(pos,node,active_object_count,active_object_count_wider)
minetest.add_particlespawner({
amount = 200,
time = 3,
minpos = pos,
maxpos = pos,
minvel = {x=2, y=-0.2, z=2},
maxvel = {x=-2, y=-0.5, z=-2},
minacc = {x=0, y=-6, z=0},
maxacc = {x=0, y=-10, z=0},
minexptime = 2,
maxexptime = 6,
minsize = 0.05,
maxsize = 0.5,
collisiondetection = false,
texture = 'more_fire_spark.png'})
minetest.add_particlespawner({
amount = 20,
time = 2,
minpos = pos,
maxpos = pos,
minvel = {x=-2, y=2, z=-2},
maxvel = {x=1, y=3, z=1},
minacc = {x=0, y=6, z=0},
maxacc = {x=0, y=2, z=0},
minexptime = 1,
maxexptime = 3,
minsize = 3,
maxsize = 5,
collisiondetection = false,
texture = 'more_fire_smoke.png'})
minetest.add_particlespawner({
amount = 10,
time = 4,
minpos = pos,
maxpos = pos,
minvel = {x=0, y= 3, z=0},
maxvel = {x=0, y=5, z=0},
minacc = {x=0.1, y=0.5, z=-0.1},
maxacc = {x=-0.2, y=2, z=0.2},
minexptime = 1,
maxexptime = 3,
minsize = 1,
maxsize = 3,
collisiondetection = false,
texture = 'more_fire_smoke.png'})
local r = 0-- Radius for destroying
for x = pos.x-r, pos.x+r, 1 do
for y = pos.y-r, pos.y+r, 1 do
for z = pos.z-r, pos.z+r, 1 do
local cpos = {x=x,y=y,z=z}
if minetest.get_node(cpos).name == 'more_fire:napalm' then
minetest.set_node(cpos,{name='fire:basic_flame'})
end
if math.random(0,1) == 1
or minetest.get_node(cpos).name == 'more_fire:napalm'
then
minetest.remove_node(cpos)
end
end
end
end
end,
})
minetest.register_abm({
nodenames={'fire:basic_flame'},
neighbors={'air'},
interval = 1,
chance = 2,
action = function(pos, node)
if minetest.get_node({x=pos.x, y=pos.y+1.0, z=pos.z}).name == 'air' and
minetest.get_node({x=pos.x, y=pos.y+2.0, z=pos.z}).name == 'air' then
minetest.add_particlespawner({
amount = 30,
time = 2,
minpos = pos,
maxpos = pos,
minvel = {x=-2, y=2, z=-2},
maxvel = {x=1, y=3, z=1},
minacc = {x=0, y=6, z=0},
maxacc = {x=0, y=2, z=0},
minexptime = 1,
maxexptime = 3,
minsize = 10,
maxsize = 20,
collisiondetection = false,
texture = 'more_fire_smoke.png'})
minetest.add_particlespawner({
amount = 15,
time = 4,
minpos = pos,
maxpos = pos,
minvel = {x=0, y= 3, z=0},
maxvel = {x=0, y=5, z=0},
minacc = {x=0.1, y=0.5, z=-0.1},
maxacc = {x=-0.2, y=2, z=0.2},
minexptime = 1,
maxexptime = 3,
minsize = 5,
maxsize = 10,
collisiondetection = false,
texture ='more_fire_smoke.png'})
end
end
})
--crafting recipes
minetest.register_craft( {
output = 'more_fire:molotov_cocktail',
recipe = {
{'farming:cotton'},
{'more_fire:oil'},
{'vessels:glass_bottle'},
}
})
-- fuel recipes
minetest.register_craft({
type = 'fuel',
recipe = 'more_fire:molotov_cocktail',
burntime = 5,
})