-
Notifications
You must be signed in to change notification settings - Fork 5
/
init.lua
776 lines (708 loc) · 21.7 KB
/
init.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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
-- Translation support
local S = minetest.get_translator("new_campfire")
-- VARIABLES
new_campfire = {}
new_campfire.cooking = 1 -- nil - not cooked, 1 - cooked
new_campfire.limited = 1 -- nil - unlimited campfire, 1 - limited
new_campfire.flames_ttl = 30 -- Time in seconds until a fire burns down into embers
new_campfire.embers_ttl = 60 -- seconds until embers burn out completely leaving ash and an empty fireplace.
new_campfire.flare_up = 2 -- seconds from adding a stick to embers before it flares into a fire again
new_campfire.stick_time = new_campfire.flames_ttl/2; -- How long does the stick increase. In sec.
-- FUNCTIONS
local function fire_particles_on(pos) -- 3 layers of fire
local meta = minetest.get_meta(pos)
local id = minetest.add_particlespawner({ -- 1 layer big particles fire
amount = 9,
time = 1.3,
minpos = {x = pos.x - 0.2, y = pos.y - 0.4, z = pos.z - 0.2},
maxpos = {x = pos.x + 0.2, y = pos.y - 0.1, z = pos.z + 0.2},
minvel = {x= 0, y= 0, z= 0},
maxvel = {x= 0, y= 0.1, z= 0},
minacc = {x= 0, y= 0, z= 0},
maxacc = {x= 0, y= 0.7, z= 0},
minexptime = 0.5,
maxexptime = 0.7,
minsize = 2,
maxsize = 5,
collisiondetection = false,
vertical = true,
texture = "new_campfire_anim_fire.png",
animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length = 0.8,},
})
meta:set_int("layer_1", id)
local id = minetest.add_particlespawner({ -- 2 layer smol particles fire
amount = 1,
time = 1.3,
minpos = {x = pos.x - 0.1, y = pos.y, z = pos.z - 0.1},
maxpos = {x = pos.x + 0.1, y = pos.y + 0.4, z = pos.z + 0.1},
minvel = {x= 0, y= 0, z= 0},
maxvel = {x= 0, y= 0.1, z= 0},
minacc = {x= 0, y= 0, z= 0},
maxacc = {x= 0, y= 1, z= 0},
minexptime = 0.4,
maxexptime = 0.6,
minsize = 0.5,
maxsize = 0.7,
collisiondetection = false,
vertical = true,
texture = "new_campfire_anim_fire.png",
animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length = 0.7,},
})
meta:set_int("layer_2", id)
local id = minetest.add_particlespawner({ --3 layer smoke
amount = 1,
time = 1.3,
minpos = {x = pos.x - 0.1, y = pos.y - 0.2, z = pos.z - 0.1},
maxpos = {x = pos.x + 0.2, y = pos.y + 0.4, z = pos.z + 0.2},
minvel = {x= 0, y= 0, z= 0},
maxvel = {x= 0, y= 0.1, z= 0},
minacc = {x= 0, y= 0, z= 0},
maxacc = {x= 0, y= 1, z= 0},
minexptime = 0.6,
maxexptime = 0.8,
minsize = 2,
maxsize = 4,
collisiondetection = true,
vertical = true,
texture = "new_campfire_anim_smoke.png",
animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length = 0.9,},
})
meta:set_int("layer_3", id)
end
local function fire_particles_off(pos)
local meta = minetest.get_meta(pos)
local id_1 = meta:get_int("layer_1");
local id_2 = meta:get_int("layer_2");
local id_3 = meta:get_int("layer_3");
minetest.delete_particlespawner(id_1)
minetest.delete_particlespawner(id_2)
minetest.delete_particlespawner(id_3)
end
-- we do this to determine the number of bytes each block symbol takes in the
-- user's current encoding (they're 3-byte UTF8 on my box, but that may not be
-- the case elsewhere)
local utf8_len_1=string.find("▓X", "X")-1
local utf8_len_2=string.find("▒X", "X")-1
local function indicator(maxVal, curVal)
local percent_val = math.floor(curVal / maxVal * 100)
local v = math.min(math.ceil(percent_val / 10), 10)
return "\n"
..string.sub("▓▓▓▓▓▓▓▓▓▓", 1, v*utf8_len_1)
..string.sub("▒▒▒▒▒▒▒▒▒▒", 1, (10-v)*utf8_len_2)
.." "..percent_val.."%"
end
local function effect(pos, texture, vlc, acc, time, size)
local id = minetest.add_particle({
pos = pos,
velocity = vlc,
acceleration = acc,
expirationtime = time,
size = size,
collisiondetection = true,
vertical = true,
texture = texture,
})
end
local function infotext_edit(meta)
local infotext = S("Active campfire")
if new_campfire.limited and new_campfire.flames_ttl > 0 then
local it_val = meta:get_int("it_val");
infotext = infotext..indicator(new_campfire.flames_ttl, it_val)
end
local cooked_time = meta:get_int('cooked_time');
if new_campfire.cooking and cooked_time ~= 0 then
local cooked_cur_time = meta:get_int('cooked_cur_time');
infotext = infotext.."\n"..S("Cooking")..indicator(cooked_time, cooked_cur_time)
end
meta:set_string('infotext', infotext)
end
local function cooking(pos, itemstack)
local meta = minetest.get_meta(pos)
local cooked, _ = minetest.get_craft_result({method = "cooking", width = 1, items = {itemstack}})
local cookable = cooked.time ~= 0
if cookable and new_campfire.cooking then
local eat_y = ItemStack(cooked.item:to_table().name):get_definition().on_use
if string.find(minetest.serialize(eat_y), "do_item_eat") and meta:get_int("cooked_time") == 0 then
meta:set_int('cooked_time', cooked.time);
meta:set_int('cooked_cur_time', 0);
local name = itemstack:get_name()
local texture = itemstack:get_definition().inventory_image
infotext_edit(meta)
effect(
{x = pos.x, y = pos.y+0.2, z = pos.z},
texture,
{x=0, y=0, z=0},
{x=0, y=0, z=0},
cooked.time,
4
)
minetest.after(cooked.time/2, function()
if meta:get_int("it_val") > 0 then
local item = cooked.item:to_table().name
minetest.after(cooked.time/2, function(item)
if meta:get_int("it_val") > 0 then
minetest.add_item({x=pos.x, y=pos.y+0.2, z=pos.z}, item)
meta:set_int('cooked_time', 0);
meta:set_int('cooked_cur_time', 0);
else
minetest.add_item({x=pos.x, y=pos.y+0.2, z=pos.z}, name)
end
end, item)
else
minetest.add_item({x=pos.x, y=pos.y+0.2, z=pos.z}, name)
end
end)
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
return itemstack
end
end
end
end
local function add_stick(pos, itemstack)
local meta = minetest.get_meta(pos)
local name = itemstack:get_name()
if itemstack:get_definition().groups.stick == 1 then
local it_val = meta:get_int("it_val") + (new_campfire.flames_ttl);
meta:set_int('it_val', it_val);
effect(
pos,
"default_stick.png",
{x=0, y=-1, z=0},
{x=0, y=0, z=0},
1,
6
)
infotext_edit(meta)
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
return itemstack
end
return true
end
end
local function burn_out(pos, node)
if string.find(node.name, "embers") then
minetest.set_node(pos, {name = string.gsub(node.name, "_with_embers", "")})
minetest.add_item(pos, "new_campfire:ash")
else
fire_particles_off(pos)
minetest.set_node(pos, {name = string.gsub(node.name, "campfire_active", "fireplace_with_embers")})
end
end
-- NODES
local sbox = {
type = 'fixed',
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16},
}
local grille_sbox = {
type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, 2/16, 8/16 },
}
local grille_cbox = {
type = "fixed",
fixed = {
{ -8/16, 1/16, -8/16, 8/16, 2/16, 8/16 },
{ -8/16, -8/16, -8/16, -7/16, 1/16, -7/16 },
{ 8/16, -8/16, 8/16, 7/16, 1/16, 7/16 },
{ 8/16, -8/16, -8/16, 7/16, 1/16, -7/16 },
{ -8/16, -8/16, 8/16, -7/16, 1/16, 7/16 }
}
}
minetest.register_node('new_campfire:fireplace', {
description = S("Fireplace"),
drawtype = 'mesh',
mesh = 'contained_campfire.obj',
tiles = {
"default_stone.png",
"new_campfire_empty_tile.png",
"new_campfire_empty_tile.png",
"new_campfire_empty_tile.png"
},
use_texture_alpha = "blend",
walkable = false,
buildable_to = false,
sunlight_propagates = false,
paramtype = 'light',
groups = {dig_immediate=3, flammable=0, not_in_creative_inventory=1},
is_ground_content = false,
selection_box = sbox,
sounds = default.node_sound_stone_defaults(),
drop = {max_items = 3, items = {{items = {"stairs:slab_cobble 3"}}}},
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local name = itemstack:get_name()
local a=add_stick(pos, itemstack)
if a then
minetest.swap_node(pos, {name = "new_campfire:campfire"})
elseif name == "new_campfire:grille" then
itemstack:take_item()
minetest.swap_node(pos, {name = "new_campfire:fireplace_with_grille"})
end
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string('infotext', S("Fireplace"));
meta:set_int("it_val", 0)
meta:set_int("em_val", 0)
end,
})
minetest.register_node('new_campfire:campfire', {
description = S("Campfire"),
drawtype = 'mesh',
mesh = 'contained_campfire.obj',
tiles = {
"default_stone.png",
"default_wood.png",
"new_campfire_empty_tile.png",
"new_campfire_empty_tile.png"
},
use_texture_alpha = "blend",
inventory_image = "new_campfire_campfire.png",
walkable = false,
buildable_to = false,
sunlight_propagates = true,
groups = {dig_immediate=3, flammable=0},
is_ground_content = false,
paramtype = 'light',
selection_box = sbox,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("it_val", 0)
meta:set_int("em_val", 0)
meta:set_string('infotext', S("Campfire"));
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local itemname = itemstack:get_name()
if itemname == "fire:flint_and_steel" then
minetest.sound_play("fire_flint_and_steel",{pos = pos, gain = 0.5, max_hear_distance = 8})
minetest.set_node(pos, {name = 'new_campfire:campfire_active'})
local id = minetest.add_particle({
pos = {x = pos.x, y = pos.y, z = pos.z},
velocity = {x=0, y=0.1, z=0},
acceleration = {x=0, y=0, z=0},
expirationtime = 2,
size = 4,
collisiondetection = true,
vertical = true,
texture = "new_campfire_anim_smoke.png",
animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length = 2.5,},
})
elseif itemname == "new_campfire:grille" then
itemstack:take_item()
minetest.swap_node(pos, {name = "new_campfire:campfire_with_grille"})
end
end,
})
minetest.register_node('new_campfire:campfire_active', {
description = S("Active campfire"),
drawtype = 'mesh',
mesh = 'contained_campfire.obj',
tiles = {
"default_stone.png",
"default_wood.png",
"new_campfire_empty_tile.png",
"new_campfire_empty_tile.png"
},
use_texture_alpha = "blend",
inventory_image = "new_campfire_campfire.png",
walkable = false,
buildable_to = false,
sunlight_propagates = true,
groups = {oddly_breakable_by_hand=3, flammable=0, not_in_creative_inventory=1, igniter=1},
is_ground_content = false,
paramtype = 'none',
light_source = 13,
damage_per_second = 3,
drop = "new_campfire:campfire",
sounds = default.node_sound_stone_defaults(),
selection_box = sbox,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local name = itemstack:get_name()
local a=add_stick(pos, itemstack)
if not a then
if name == "new_campfire:grille" then
itemstack:take_item()
minetest.swap_node(pos, {name = "new_campfire:campfire_active_with_grille"})
end
end
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int('it_val', new_campfire.flames_ttl)
meta:set_int("em_val", 0)
infotext_edit(meta)
minetest.get_node_timer(pos):start(2)
end,
on_destruct = function(pos, oldnode, oldmetadata, digger)
fire_particles_off(pos)
local meta = minetest.get_meta(pos)
local handle = meta:get_int("handle")
minetest.sound_stop(handle)
end,
})
minetest.register_node('new_campfire:fireplace_with_embers', {
description = S("Fireplace with embers"),
drawtype = 'mesh',
mesh = 'contained_campfire.obj',
tiles = {
"default_stone.png",
"new_campfire_empty_tile.png",
"new_campfire_empty_tile.png",
{
name = "new_campfire_anim_embers.png",
animation = {
type="vertical_frames",
aspect_w=16,
aspect_h=16,
length=2
}
}
},
use_texture_alpha = "blend",
walkable = false,
buildable_to = false,
sunlight_propagates = false,
paramtype = 'light',
light_source = 5,
groups = {dig_immediate=3, flammable=0, not_in_creative_inventory=1},
is_ground_content = false,
selection_box = sbox,
sounds = default.node_sound_stone_defaults(),
drop = {max_items = 3, items = {{items = {"stairs:slab_cobble 3"}}}},
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local name = itemstack:get_name()
local a=add_stick(pos, itemstack)
if a then
minetest.swap_node(pos, {name = "new_campfire:campfire"})
minetest.after(new_campfire.flare_up, function()
if minetest.get_meta(pos):get_int("it_val") > 0 then
minetest.swap_node(pos, {name="new_campfire:campfire_active"})
end
end)
elseif name == "new_campfire:grille" then
itemstack:take_item()
minetest.swap_node(pos, {name = "new_campfire:fireplace_with_embers_with_grille"})
end
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("it_val", 0)
meta:set_int("em_val", new_campfire.embers_ttl)
meta:set_string('infotext', S("Fireplace with embers"));
end,
})
minetest.register_node('new_campfire:fireplace_with_embers_with_grille', {
description = S("Fireplace with embers and grille"),
drawtype = 'mesh',
mesh = 'contained_campfire.obj',
tiles = {
"default_stone.png",
"new_campfire_empty_tile.png",
"default_steel_block.png",
{
name = "new_campfire_anim_embers.png",
animation = {
type="vertical_frames",
aspect_w=16,
aspect_h=16,
length=2
}
}
},
use_texture_alpha = "blend",
walkable = false,
buildable_to = false,
sunlight_propagates = false,
paramtype = 'light',
light_source = 5,
groups = {dig_immediate=3, flammable=0, not_in_creative_inventory=1},
is_ground_content = false,
selection_box = grille_sbox,
node_box = grille_cbox,
sounds = default.node_sound_stone_defaults(),
drop = {
max_items = 4,
items = {
{
items = {"stairs:slab_cobble 3"},
items = {"new_campfire:grille 1"}
}
}
},
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local name = itemstack:get_name()
local a=add_stick(pos, itemstack)
if a then
minetest.swap_node(pos, {name = "new_campfire:campfire_with_grille"})
minetest.after(new_campfire.flare_up, function()
if minetest.get_meta(pos):get_int("it_val") > 0 then
minetest.swap_node(pos, {name="new_campfire:campfire_active_with_grille"})
end
end)
end
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("it_val", 0)
meta:set_int("em_val", new_campfire.embers_ttl)
meta:set_string('infotext', S("Fireplace with embers"));
end,
})
minetest.register_node('new_campfire:fireplace_with_grille', {
description = S("Fireplace with grille"),
drawtype = 'mesh',
mesh = 'contained_campfire.obj',
tiles = {
"default_stone.png",
"new_campfire_empty_tile.png",
"default_steel_block.png",
"new_campfire_empty_tile.png"
},
use_texture_alpha = "blend",
buildable_to = false,
sunlight_propagates = false,
paramtype = 'light',
groups = {dig_immediate=3, flammable=0, not_in_creative_inventory=1},
is_ground_content = false,
selection_box = grille_sbox,
node_box = grille_cbox,
sounds = default.node_sound_stone_defaults(),
drop = {
max_items = 4,
items = {
{
items = {"stairs:slab_cobble 3"},
items = {"new_campfire:grille 1"}
}
}
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("it_val", 0)
meta:set_int("em_val", 0)
meta:set_string('infotext', S("Fireplace"));
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local name = itemstack:get_name()
local a=add_stick(pos, itemstack)
if a then
minetest.swap_node(pos, {name = "new_campfire:campfire_with_grille"})
end
end,
})
minetest.register_node('new_campfire:campfire_with_grille', {
description = S("Campfire with grille"),
drawtype = 'mesh',
mesh = 'contained_campfire.obj',
tiles = {
"default_stone.png",
"default_wood.png",
"default_steel_block.png",
"new_campfire_empty_tile.png"
},
use_texture_alpha = "blend",
inventory_image = "new_campfire_campfire.png",
buildable_to = false,
sunlight_propagates = true,
groups = {dig_immediate=3, flammable=0, not_in_creative_inventory=1},
is_ground_content = false,
paramtype = 'light',
selection_box = grille_sbox,
node_box = grille_cbox,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("it_val", 0)
meta:set_int("em_val", 0)
meta:set_string('infotext', S("Campfire"));
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
if itemstack:get_name() == "fire:flint_and_steel" then
minetest.sound_play("fire_flint_and_steel",{pos = pos, gain = 0.5, max_hear_distance = 8})
minetest.set_node(pos, {name = 'new_campfire:campfire_active_with_grille'})
local id = minetest.add_particle({
pos = {x = pos.x, y = pos.y, z = pos.z},
velocity = {x=0, y=0.1, z=0},
acceleration = {x=0, y=0, z=0},
expirationtime = 2,
size = 4,
collisiondetection = true,
vertical = true,
texture = "new_campfire_anim_smoke.png",
animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length = 2.5,},
})
end
end,
drop = {
max_items = 4,
items = {
{
items = {"new_campfire:campfire 1"},
items = {"new_campfire:grille 1"}
}
}
},
})
minetest.register_node('new_campfire:campfire_active_with_grille', {
description = S("Active campfire with grille"),
drawtype = 'mesh',
mesh = 'contained_campfire.obj',
tiles = {
"default_stone.png",
"default_wood.png",
"default_steel_block.png",
"new_campfire_empty_tile.png"
},
use_texture_alpha = "blend",
inventory_image = "new_campfire_campfire.png",
buildable_to = false,
sunlight_propagates = true,
groups = {oddly_breakable_by_hand=3, flammable=0, not_in_creative_inventory=1, igniter=1},
is_ground_content = false,
paramtype = 'none',
light_source = 13,
damage_per_second = 3,
drop = {
max_items = 4,
items = {
{
items = {"new_campfire:campfire 1"},
items = {"new_campfire:grille 1"}
}
}
},
sounds = default.node_sound_stone_defaults(),
selection_box = grille_sbox,
node_box = grille_cbox,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local name = itemstack:get_name()
local a=add_stick(pos, itemstack)
if not a then
return cooking(pos, itemstack)
end
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int('it_val', new_campfire.flames_ttl);
meta:set_int("em_val", 0)
infotext_edit(meta)
minetest.get_node_timer(pos):start(2)
end,
on_destruct = function(pos, oldnode, oldmetadata, digger)
fire_particles_off(pos)
local meta = minetest.get_meta(pos)
local handle = meta:get_int("handle")
minetest.sound_stop(handle)
end,
on_timer = function(pos) -- Every 6 seconds play sound fire_small
local meta = minetest.get_meta(pos)
local handle = minetest.sound_play("fire_small",{pos=pos, max_hear_distance = 18, loop=false, gain=0.1})
meta:set_int("handle", handle)
minetest.get_node_timer(pos):start(6)
end,
})
-- ABMs
minetest.register_abm({
nodenames = {
"new_campfire:fireplace_with_embers",
"new_campfire:fireplace_with_embers_with_grille"
},
interval = 1.0, -- Run every second
chance = 1, -- Select every node
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local em_val = meta:get_int("em_val")
meta:set_int("em_val", em_val - 1)
if em_val <= 0 then
burn_out(pos, node)
end
end
})
minetest.register_abm({
nodenames = {
"new_campfire:campfire_active",
"new_campfire:campfire_active_with_grille"
},
interval = 1.0, -- Run every second
chance = 1, -- Select every node
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
local fpos, num = minetest.find_nodes_in_area(
{x=pos.x-1, y=pos.y, z=pos.z-1},
{x=pos.x+1, y=pos.y+1, z=pos.z+1},
{"group:water"}
)
if #fpos > 0 then
if string.find(node.name, "embers") then
burn_out(pos, node)
else
minetest.set_node(pos, {name = string.gsub(node.name, "_active", "")})
end
minetest.sound_play("fire_extinguish_flame",{pos = pos, max_hear_distance = 16, gain = 0.15})
else
local meta = minetest.get_meta(pos)
local it_val = meta:get_int("it_val") - 1;
if new_campfire.limited and new_campfire.flames_ttl > 0 then
if it_val <= 0 then
burn_out(pos, node)
return
end
meta:set_int('it_val', it_val);
end
if new_campfire.cooking then
if meta:get_int('cooked_cur_time') <= meta:get_int('cooked_time') then
meta:set_int('cooked_cur_time', meta:get_int('cooked_cur_time') + 1);
else
meta:set_int('cooked_time', 0);
meta:set_int('cooked_cur_time', 0);
end
end
infotext_edit(meta)
fire_particles_on(pos)
end
end
})
-- CRAFTS
if minetest.get_modpath("basic_materials") then
minetest.register_craft({
output = "new_campfire:grille",
recipe = {
{"basic_materials:steel_bar", "", "basic_materials:steel_bar"},
{"", "basic_materials:steel_wire", ""},
{"basic_materials:steel_bar", "", "basic_materials:steel_bar"}
}
})
else
minetest.register_craft({
output = "new_campfire:grille",
recipe = {
{"default:steel_ingot", "", "default:steel_ingot"},
{"", "xpanes:bar_flat", ""},
{"default:steel_ingot", "", "default:steel_ingot"}
}
})
end
minetest.register_craft({
output = "new_campfire:campfire",
recipe = {
{'', 'group:stick', ''},
{'stairs:slab_cobble','group:stick', 'stairs:slab_cobble'},
{'', 'stairs:slab_cobble', ''},
}
})
-- ITEMS
minetest.register_craftitem("new_campfire:grille", {
description = S("Metal Grille"),
inventory_image = "new_campfire_grille.png"
})
minetest.register_craftitem("new_campfire:ash", {
description = S("Ash"),
inventory_image = "new_campfire_ash.png"
})
-- EXTRA
if not minetest.get_modpath("campfire") then
minetest.register_alias("campfire:campfire", "new_campfire:campfire")
minetest.register_alias("campfire:campfire_active", "new_campfire:campfire")
end