]> git.lizzy.rs Git - dragonfireclient.git/blob - data/mods/default/init.lua
Reshape LuaEntityCAO implementation a bit and make TNT to blink
[dragonfireclient.git] / data / mods / default / init.lua
1 -- Helper functions defined by builtin.lua:
2 -- dump2(obj, name="_", dumped={})
3 -- dump(obj, dumped={})
4 --
5 -- Textures:
6 -- Mods should prefix their textures with modname_, eg. given the mod
7 -- name "foomod", a texture could be called "foomod_superfurnace.png"
8 --
9 -- Global functions:
10 -- minetest.register_entity(name, prototype_table)
11 -- minetest.register_tool(name, {lots of stuff})
12 -- minetest.register_node(name, {lots of stuff})
13 -- minetest.register_craft({output=item, recipe={...})
14 -- minetest.register_globalstep(func)
15 -- minetest.register_on_placenode(func(pos, newnode, placer))
16 -- minetest.register_on_dignode(func(pos, oldnode, digger))
17 -- minetest.register_on_punchnode(func(pos, node, puncher))
18 -- minetest.register_on_newplayer(func(ObjectRef))
19 -- minetest.register_on_respawnplayer(func(ObjectRef))
20 -- ^ return true in func to disable regular player placement
21 -- minetest.setting_get(name)
22 -- minetest.setting_getbool(name)
23 --
24 -- Global objects:
25 -- minetest.env - environment reference
26 --
27 -- Global tables:
28 -- minetest.registered_nodes
29 -- ^ List of registed node definitions, indexed by name
30 -- minetest.registered_entities
31 -- ^ List of registered entity prototypes, indexed by name
32 -- minetest.object_refs
33 -- ^ List of object references, indexed by active object id
34 -- minetest.luaentities
35 -- ^ List of lua entities, indexed by active object id
36 --
37 -- EnvRef is basically ServerEnvironment and ServerMap combined.
38 -- EnvRef methods:
39 -- - add_node(pos, node)
40 -- - remove_node(pos)
41 -- - get_node(pos)
42 -- - add_luaentity(pos, name)
43 --
44 -- ObjectRef is basically ServerActiveObject.
45 -- ObjectRef methods:
46 -- - remove(): remove object (after returning from Lua)
47 -- - getpos(): returns {x=num, y=num, z=num}
48 -- - setpos(pos); pos={x=num, y=num, z=num}
49 -- - moveto(pos, continuous=false): interpolated move
50 -- - add_to_inventory(itemstring): add an item to object inventory
51 --
52 -- Registered entities:
53 -- - Functions receive a "luaentity" as self:
54 --   - It has the member .object, which is an ObjectRef pointing to the object
55 --   - The original prototype stuff is visible directly via a metatable
56 -- - Callbacks:
57 --   - on_activate(self, staticdata)
58 --   - on_step(self, dtime)
59 --   - on_punch(self, hitter)
60 --   - on_rightclick(self, clicker)
61 --   - get_staticdata(self): return string
62 --
63 -- MapNode representation:
64 -- {name="name", param1=num, param2=num}
65 --
66 -- Position representation:
67 -- {x=num, y=num, z=num}
68 --
69
70 -- print("minetest dump: "..dump(minetest))
71
72 WATER_ALPHA = 160
73 WATER_VISC = 1
74 LAVA_VISC = 7
75 LIGHT_MAX = 14
76
77 --
78 -- Tool definition
79 --
80
81 minetest.register_tool("WPick", {
82         image = "tool_woodpick.png",
83         basetime = 2.0,
84         dt_weight = 0,
85         dt_crackiness = -0.5,
86         dt_crumbliness = 2,
87         dt_cuttability = 0,
88         basedurability = 30,
89         dd_weight = 0,
90         dd_crackiness = 0,
91         dd_crumbliness = 0,
92         dd_cuttability = 0,
93 })
94 minetest.register_tool("STPick", {
95         image = "tool_stonepick.png",
96         basetime = 1.5,
97         dt_weight = 0,
98         dt_crackiness = -0.5,
99         dt_crumbliness = 2,
100         dt_cuttability = 0,
101         basedurability = 100,
102         dd_weight = 0,
103         dd_crackiness = 0,
104         dd_crumbliness = 0,
105         dd_cuttability = 0,
106 })
107 minetest.register_tool("SteelPick", {
108         image = "tool_steelpick.png",
109         basetime = 1.0,
110         dt_weight = 0,
111         dt_crackiness = -0.5,
112         dt_crumbliness = 2,
113         dt_cuttability = 0,
114         basedurability = 333,
115         dd_weight = 0,
116         dd_crackiness = 0,
117         dd_crumbliness = 0,
118         dd_cuttability = 0,
119 })
120 minetest.register_tool("MesePick", {
121         image = "tool_mesepick.png",
122         basetime = 0,
123         dt_weight = 0,
124         dt_crackiness = 0,
125         dt_crumbliness = 0,
126         dt_cuttability = 0,
127         basedurability = 1337,
128         dd_weight = 0,
129         dd_crackiness = 0,
130         dd_crumbliness = 0,
131         dd_cuttability = 0,
132 })
133 minetest.register_tool("WShovel", {
134         image = "tool_woodshovel.png",
135         basetime = 2.0,
136         dt_weight = 0.5,
137         dt_crackiness = 2,
138         dt_crumbliness = -1.5,
139         dt_cuttability = 0.3,
140         basedurability = 30,
141         dd_weight = 0,
142         dd_crackiness = 0,
143         dd_crumbliness = 0,
144         dd_cuttability = 0,
145 })
146 minetest.register_tool("STShovel", {
147         image = "tool_stoneshovel.png",
148         basetime = 1.5,
149         dt_weight = 0.5,
150         dt_crackiness = 2,
151         dt_crumbliness = -1.5,
152         dt_cuttability = 0.1,
153         basedurability = 100,
154         dd_weight = 0,
155         dd_crackiness = 0,
156         dd_crumbliness = 0,
157         dd_cuttability = 0,
158 })
159 minetest.register_tool("SteelShovel", {
160         image = "tool_steelshovel.png",
161         basetime = 1.0,
162         dt_weight = 0.5,
163         dt_crackiness = 2,
164         dt_crumbliness = -1.5,
165         dt_cuttability = 0.0,
166         basedurability = 330,
167         dd_weight = 0,
168         dd_crackiness = 0,
169         dd_crumbliness = 0,
170         dd_cuttability = 0,
171 })
172 minetest.register_tool("WAxe", {
173         image = "tool_woodaxe.png",
174         basetime = 2.0,
175         dt_weight = 0.5,
176         dt_crackiness = -0.2,
177         dt_crumbliness = 1,
178         dt_cuttability = -0.5,
179         basedurability = 30,
180         dd_weight = 0,
181         dd_crackiness = 0,
182         dd_crumbliness = 0,
183         dd_cuttability = 0,
184 })
185 minetest.register_tool("STAxe", {
186         image = "tool_stoneaxe.png",
187         basetime = 1.5,
188         dt_weight = 0.5,
189         dt_crackiness = -0.2,
190         dt_crumbliness = 1,
191         dt_cuttability = -0.5,
192         basedurability = 100,
193         dd_weight = 0,
194         dd_crackiness = 0,
195         dd_crumbliness = 0,
196         dd_cuttability = 0,
197 })
198 minetest.register_tool("SteelAxe", {
199         image = "tool_steelaxe.png",
200         basetime = 1.0,
201         dt_weight = 0.5,
202         dt_crackiness = -0.2,
203         dt_crumbliness = 1,
204         dt_cuttability = -0.5,
205         basedurability = 330,
206         dd_weight = 0,
207         dd_crackiness = 0,
208         dd_crumbliness = 0,
209         dd_cuttability = 0,
210 })
211 minetest.register_tool("WSword", {
212         image = "tool_woodsword.png",
213         basetime = 3.0,
214         dt_weight = 3,
215         dt_crackiness = 0,
216         dt_crumbliness = 1,
217         dt_cuttability = -1,
218         basedurability = 30,
219         dd_weight = 0,
220         dd_crackiness = 0,
221         dd_crumbliness = 0,
222         dd_cuttability = 0,
223 })
224 minetest.register_tool("STSword", {
225         image = "tool_stonesword.png",
226         basetime = 2.5,
227         dt_weight = 3,
228         dt_crackiness = 0,
229         dt_crumbliness = 1,
230         dt_cuttability = -1,
231         basedurability = 100,
232         dd_weight = 0,
233         dd_crackiness = 0,
234         dd_crumbliness = 0,
235         dd_cuttability = 0,
236 })
237 minetest.register_tool("SteelSword", {
238         image = "tool_steelsword.png",
239         basetime = 2.0,
240         dt_weight = 3,
241         dt_crackiness = 0,
242         dt_crumbliness = 1,
243         dt_cuttability = -1,
244         basedurability = 330,
245         dd_weight = 0,
246         dd_crackiness = 0,
247         dd_crumbliness = 0,
248         dd_cuttability = 0,
249 })
250 minetest.register_tool("", {
251         image = "",
252         basetime = 0.5,
253         dt_weight = 1,
254         dt_crackiness = 0,
255         dt_crumbliness = -1,
256         dt_cuttability = 0,
257         basedurability = 50,
258         dd_weight = 0,
259         dd_crackiness = 0,
260         dd_crumbliness = 0,
261         dd_cuttability = 0,
262 })
263
264 --[[
265 minetest.register_tool("horribletool", {
266         image = "lava.png",
267         basetime = 2.0
268         dt_weight = 0.2
269         dt_crackiness = 0.2
270         dt_crumbliness = 0.2
271         dt_cuttability = 0.2
272         basedurability = 50
273         dd_weight = -5
274         dd_crackiness = -5
275         dd_crumbliness = -5
276         dd_cuttability = -5
277 })
278 --]]
279
280 --
281 -- Crafting definition
282 --
283
284 minetest.register_craft({
285         output = 'NodeItem "wood" 4',
286         recipe = {
287                 {'NodeItem "tree"'},
288         }
289 })
290
291 minetest.register_craft({
292         output = 'CraftItem "Stick" 4',
293         recipe = {
294                 {'NodeItem "wood"'},
295         }
296 })
297
298 minetest.register_craft({
299         output = 'NodeItem "wooden_fence" 2',
300         recipe = {
301                 {'CraftItem "Stick"', 'CraftItem "Stick"', 'CraftItem "Stick"'},
302                 {'CraftItem "Stick"', 'CraftItem "Stick"', 'CraftItem "Stick"'},
303         }
304 })
305
306 minetest.register_craft({
307         output = 'NodeItem "sign_wall" 1',
308         recipe = {
309                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
310                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
311                 {'', 'CraftItem "Stick"', ''},
312         }
313 })
314
315 minetest.register_craft({
316         output = 'NodeItem "torch" 4',
317         recipe = {
318                 {'CraftItem "lump_of_coal"'},
319                 {'CraftItem "Stick"'},
320         }
321 })
322
323 minetest.register_craft({
324         output = 'ToolItem "WPick"',
325         recipe = {
326                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
327                 {'', 'CraftItem "Stick"', ''},
328                 {'', 'CraftItem "Stick"', ''},
329         }
330 })
331
332 minetest.register_craft({
333         output = 'ToolItem "STPick"',
334         recipe = {
335                 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
336                 {'', 'CraftItem "Stick"', ''},
337                 {'', 'CraftItem "Stick"', ''},
338         }
339 })
340
341 minetest.register_craft({
342         output = 'ToolItem "SteelPick"',
343         recipe = {
344                 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
345                 {'', 'CraftItem "Stick"', ''},
346                 {'', 'CraftItem "Stick"', ''},
347         }
348 })
349
350 minetest.register_craft({
351         output = 'ToolItem "MesePick"',
352         recipe = {
353                 {'NodeItem "mese"', 'NodeItem "mese"', 'NodeItem "mese"'},
354                 {'', 'CraftItem "Stick"', ''},
355                 {'', 'CraftItem "Stick"', ''},
356         }
357 })
358
359 minetest.register_craft({
360         output = 'ToolItem "WShovel"',
361         recipe = {
362                 {'NodeItem "wood"'},
363                 {'CraftItem "Stick"'},
364                 {'CraftItem "Stick"'},
365         }
366 })
367
368 minetest.register_craft({
369         output = 'ToolItem "STShovel"',
370         recipe = {
371                 {'NodeItem "cobble"'},
372                 {'CraftItem "Stick"'},
373                 {'CraftItem "Stick"'},
374         }
375 })
376
377 minetest.register_craft({
378         output = 'ToolItem "SteelShovel"',
379         recipe = {
380                 {'CraftItem "steel_ingot"'},
381                 {'CraftItem "Stick"'},
382                 {'CraftItem "Stick"'},
383         }
384 })
385
386 minetest.register_craft({
387         output = 'ToolItem "WAxe"',
388         recipe = {
389                 {'NodeItem "wood"', 'NodeItem "wood"'},
390                 {'NodeItem "wood"', 'CraftItem "Stick"'},
391                 {'', 'CraftItem "Stick"'},
392         }
393 })
394
395 minetest.register_craft({
396         output = 'ToolItem "STAxe"',
397         recipe = {
398                 {'NodeItem "cobble"', 'NodeItem "cobble"'},
399                 {'NodeItem "cobble"', 'CraftItem "Stick"'},
400                 {'', 'CraftItem "Stick"'},
401         }
402 })
403
404 minetest.register_craft({
405         output = 'ToolItem "SteelAxe"',
406         recipe = {
407                 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
408                 {'CraftItem "steel_ingot"', 'CraftItem "Stick"'},
409                 {'', 'CraftItem "Stick"'},
410         }
411 })
412
413 minetest.register_craft({
414         output = 'ToolItem "WSword"',
415         recipe = {
416                 {'NodeItem "wood"'},
417                 {'NodeItem "wood"'},
418                 {'CraftItem "Stick"'},
419         }
420 })
421
422 minetest.register_craft({
423         output = 'ToolItem "STSword"',
424         recipe = {
425                 {'NodeItem "cobble"'},
426                 {'NodeItem "cobble"'},
427                 {'CraftItem "Stick"'},
428         }
429 })
430
431 minetest.register_craft({
432         output = 'ToolItem "SteelSword"',
433         recipe = {
434                 {'CraftItem "steel_ingot"'},
435                 {'CraftItem "steel_ingot"'},
436                 {'CraftItem "Stick"'},
437         }
438 })
439
440 minetest.register_craft({
441         output = 'NodeItem "rail" 15',
442         recipe = {
443                 {'CraftItem "steel_ingot"', '', 'CraftItem "steel_ingot"'},
444                 {'CraftItem "steel_ingot"', 'CraftItem "Stick"', 'CraftItem "steel_ingot"'},
445                 {'CraftItem "steel_ingot"', '', 'CraftItem "steel_ingot"'},
446         }
447 })
448
449 minetest.register_craft({
450         output = 'NodeItem "chest" 1',
451         recipe = {
452                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
453                 {'NodeItem "wood"', '', 'NodeItem "wood"'},
454                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
455         }
456 })
457
458 minetest.register_craft({
459         output = 'NodeItem "locked_chest" 1',
460         recipe = {
461                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
462                 {'NodeItem "wood"', 'CraftItem "steel_ingot"', 'NodeItem "wood"'},
463                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
464         }
465 })
466
467 minetest.register_craft({
468         output = 'NodeItem "furnace" 1',
469         recipe = {
470                 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
471                 {'NodeItem "cobble"', '', 'NodeItem "cobble"'},
472                 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
473         }
474 })
475
476 minetest.register_craft({
477         output = 'NodeItem "steelblock" 1',
478         recipe = {
479                 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
480                 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
481                 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
482         }
483 })
484
485 minetest.register_craft({
486         output = 'NodeItem "sandstone" 1',
487         recipe = {
488                 {'NodeItem "sand"', 'NodeItem "sand"'},
489                 {'NodeItem "sand"', 'NodeItem "sand"'},
490         }
491 })
492
493 minetest.register_craft({
494         output = 'NodeItem "clay" 1',
495         recipe = {
496                 {'CraftItem "lump_of_clay"', 'CraftItem "lump_of_clay"'},
497                 {'CraftItem "lump_of_clay"', 'CraftItem "lump_of_clay"'},
498         }
499 })
500
501 minetest.register_craft({
502         output = 'NodeItem "brick" 1',
503         recipe = {
504                 {'CraftItem "clay_brick"', 'CraftItem "clay_brick"'},
505                 {'CraftItem "clay_brick"', 'CraftItem "clay_brick"'},
506         }
507 })
508
509 minetest.register_craft({
510         output = 'CraftItem "paper" 1',
511         recipe = {
512                 {'NodeItem "papyrus"', 'NodeItem "papyrus"', 'NodeItem "papyrus"'},
513         }
514 })
515
516 minetest.register_craft({
517         output = 'CraftItem "book" 1',
518         recipe = {
519                 {'CraftItem "paper"'},
520                 {'CraftItem "paper"'},
521                 {'CraftItem "paper"'},
522         }
523 })
524
525 minetest.register_craft({
526         output = 'NodeItem "bookshelf" 1',
527         recipe = {
528                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
529                 {'CraftItem "book"', 'CraftItem "book"', 'CraftItem "book"'},
530                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
531         }
532 })
533
534 minetest.register_craft({
535         output = 'NodeItem "ladder" 1',
536         recipe = {
537                 {'CraftItem "Stick"', '', 'CraftItem "Stick"'},
538                 {'CraftItem "Stick"', 'CraftItem "Stick"', 'CraftItem "Stick"'},
539                 {'CraftItem "Stick"', '', 'CraftItem "Stick"'},
540         }
541 })
542
543 minetest.register_craft({
544         output = 'CraftItem "apple_iron" 1',
545         recipe = {
546                 {'', 'CraftItem "steel_ingot"', ''},
547                 {'CraftItem "steel_ingot"', 'CraftItem "apple"', 'CraftItem "steel_ingot"'},
548                 {'', 'CraftItem "steel_ingot"', ''},
549         }
550 })
551
552 minetest.register_craft({
553         output = 'NodeItem "TNT" 4',
554         recipe = {
555                 {'NodeItem "wood" 1'},
556                 {'CraftItem "lump_of_coal" 1'},
557                 {'NodeItem "wood" 1'}
558         }
559 })
560
561 minetest.register_craft({
562         output = 'NodeItem "somenode" 4',
563         recipe = {
564                 {'CraftItem "Stick" 1'},
565         }
566 })
567
568 --
569 -- Node definitions
570 --
571
572 function digprop_constanttime(time)
573         return {
574                 diggability = "constant",
575                 constant_time = time,
576         }
577 end
578
579 function digprop_stonelike(toughness)
580         return {
581                 diggablity = "normal",
582                 weight = toughness * 5,
583                 crackiness = 1,
584                 crumbliness = -0.1,
585                 cuttability = -0.2,
586         }
587 end
588
589 function digprop_dirtlike(toughness)
590         return {
591                 diggablity = "normal",
592                 weight = toughness * 1.2,
593                 crackiness = 0,
594                 crumbliness = 1.2,
595                 cuttability = -0.4,
596         }
597 end
598
599 function digprop_gravellike(toughness)
600         return {
601                 diggablity = "normal",
602                 weight = toughness * 2,
603                 crackiness = 0.2,
604                 crumbliness = 1.5,
605                 cuttability = -1.0,
606         }
607 end
608
609 function digprop_woodlike(toughness)
610         return {
611                 diggablity = "normal",
612                 weight = toughness * 1.0,
613                 crackiness = 0.75,
614                 crumbliness = -1.0,
615                 cuttability = 1.5,
616         }
617 end
618
619 function digprop_leaveslike(toughness)
620         return {
621                 diggablity = "normal",
622                 weight = toughness * (-0.5),
623                 crackiness = 0,
624                 crumbliness = 0,
625                 cuttability = 2.0,
626         }
627 end
628
629 function digprop_glasslike(toughness)
630         return {
631                 diggablity = "normal",
632                 weight = toughness * 0.1,
633                 crackiness = 2.0,
634                 crumbliness = -1.0,
635                 cuttability = -1.0,
636         }
637 end
638
639 function inventorycube(img1, img2, img3)
640         img2 = img2 or img1
641         img3 = img3 or img1
642         return "[inventorycube"
643                         .. "{" .. img1:gsub("%^", "&")
644                         .. "{" .. img2:gsub("%^", "&")
645                         .. "{" .. img3:gsub("%^", "&")
646 end
647
648 -- Legacy nodes
649
650 minetest.register_node("stone", {
651         tile_images = {"stone.png"},
652         inventory_image = inventorycube("stone.png"),
653         paramtype = "mineral",
654         is_ground_content = true,
655         often_contains_mineral = true, -- Texture atlas hint
656         material = digprop_stonelike(1.0),
657         dug_item = 'NodeItem "cobble" 1',
658 })
659
660 minetest.register_node("dirt_with_grass", {
661         tile_images = {"grass.png", "mud.png", "mud.png^grass_side.png"},
662         inventory_image = inventorycube("mud.png^grass_side.png"),
663         is_ground_content = true,
664         material = digprop_dirtlike(1.0),
665         dug_item = 'NodeItem "dirt" 1',
666 })
667
668 minetest.register_node("dirt_with_grass_footsteps", {
669         tile_images = {"grass_footsteps.png", "mud.png", "mud.png^grass_side.png"},
670         inventory_image = "grass_footsteps.png",
671         is_ground_content = true,
672         material = digprop_dirtlike(1.0),
673         dug_item = 'NodeItem "dirt" 1',
674 })
675
676 minetest.register_node("dirt", {
677         tile_images = {"mud.png"},
678         inventory_image = inventorycube("mud.png"),
679         is_ground_content = true,
680         material = digprop_dirtlike(1.0),
681 })
682
683 minetest.register_node("sand", {
684         tile_images = {"sand.png"},
685         inventory_image = inventorycube("sand.png"),
686         is_ground_content = true,
687         material = digprop_dirtlike(1.0),
688 })
689
690 minetest.register_node("gravel", {
691         tile_images = {"gravel.png"},
692         inventory_image = inventorycube("gravel.png"),
693         is_ground_content = true,
694         material = digprop_gravellike(1.0),
695 })
696
697 minetest.register_node("sandstone", {
698         tile_images = {"sandstone.png"},
699         inventory_image = inventorycube("sandstone.png"),
700         is_ground_content = true,
701         material = digprop_dirtlike(1.0),  -- FIXME should this be stonelike?
702         dug_item = 'NodeItem "sand" 1',  -- FIXME is this intentional?
703 })
704
705 minetest.register_node("clay", {
706         tile_images = {"clay.png"},
707         inventory_image = inventorycube("clay.png"),
708         is_ground_content = true,
709         material = digprop_dirtlike(1.0),
710         dug_item = 'CraftItem "lump_of_clay" 4',
711 })
712
713 minetest.register_node("brick", {
714         tile_images = {"brick.png"},
715         inventory_image = inventorycube("brick.png"),
716         is_ground_content = true,
717         material = digprop_stonelike(1.0),
718         dug_item = 'CraftItem "clay_brick" 4',
719 })
720
721 minetest.register_node("tree", {
722         tile_images = {"tree_top.png", "tree_top.png", "tree.png"},
723         inventory_image = inventorycube("tree_top.png", "tree.png", "tree.png"),
724         is_ground_content = true,
725         material = digprop_woodlike(1.0),
726         cookresult_item = 'CraftItem "lump_of_coal" 1',
727         furnace_burntime = 30,
728 })
729
730 minetest.register_node("jungletree", {
731         tile_images = {"jungletree_top.png", "jungletree_top.png", "jungletree.png"},
732         inventory_image = inventorycube("jungletree_top.png", "jungletree.png", "jungletree.png"),
733         is_ground_content = true,
734         material = digprop_woodlike(1.0),
735         cookresult_item = 'CraftItem "lump_of_coal" 1',
736         furnace_burntime = 30,
737 })
738
739 minetest.register_node("junglegrass", {
740         drawtype = "plantlike",
741         visual_scale = 1.3,
742         tile_images = {"junglegrass.png"},
743         inventory_image = "junglegrass.png",
744         light_propagates = true,
745         paramtype = "light",
746         walkable = false,
747         material = digprop_leaveslike(1.0),
748         furnace_burntime = 2,
749 })
750
751 minetest.register_node("leaves", {
752         drawtype = "allfaces_optional",
753         visual_scale = 1.3,
754         tile_images = {"leaves.png"},
755         inventory_image = "leaves.png",
756         light_propagates = true,
757         paramtype = "light",
758         material = digprop_leaveslike(1.0),
759         extra_dug_item = 'NodeItem "sapling" 1',
760         extra_dug_item_rarity = 20,
761         furnace_burntime = 1,
762 })
763
764 minetest.register_node("cactus", {
765         tile_images = {"cactus_top.png", "cactus_top.png", "cactus_side.png"},
766         inventory_image = inventorycube("cactus_top.png", "cactus_side.png", "cactus_side.png"),
767         is_ground_content = true,
768         material = digprop_woodlike(0.75),
769         furnace_burntime = 15,
770 })
771
772 minetest.register_node("papyrus", {
773         drawtype = "plantlike",
774         tile_images = {"papyrus.png"},
775         inventory_image = "papyrus.png",
776         light_propagates = true,
777         paramtype = "light",
778         is_ground_content = true,
779         walkable = false,
780         material = digprop_leaveslike(0.5),
781         furnace_burntime = 1,
782 })
783
784 minetest.register_node("bookshelf", {
785         tile_images = {"wood.png", "wood.png", "bookshelf.png"},
786         -- FIXME: inventorycube only cares for the first texture
787         --inventory_image = inventorycube("wood.png", "bookshelf.png", "bookshelf.png")
788         inventory_image = inventorycube("bookshelf.png"),
789         is_ground_content = true,
790         material = digprop_woodlike(0.75),
791         furnace_burntime = 30,
792 })
793
794 minetest.register_node("glass", {
795         drawtype = "glasslike",
796         tile_images = {"glass.png"},
797         inventory_image = inventorycube("glass.png"),
798         light_propagates = true,
799         paramtype = "light",
800         sunlight_propagates = true,
801         is_ground_content = true,
802         material = digprop_glasslike(1.0),
803 })
804
805 minetest.register_node("wooden_fence", {
806         drawtype = "fencelike",
807         tile_images = {"wood.png"},
808         inventory_image = "fence.png",
809         light_propagates = true,
810         paramtype = "light",
811         is_ground_content = true,
812         selection_box = {
813                 type = "fixed",
814                 fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
815         },
816         furnace_burntime = 15,
817         material = digprop_woodlike(0.75),
818 })
819
820 minetest.register_node("rail", {
821         drawtype = "raillike",
822         tile_images = {"rail.png", "rail_curved.png", "rail_t_junction.png", "rail_crossing.png"},
823         inventory_image = "rail.png",
824         light_propagates = true,
825         paramtype = "light",
826         is_ground_content = true,
827         walkable = false,
828         selection_box = {
829                 type = "fixed",
830                 --fixed = <default>
831         },
832         material = digprop_dirtlike(0.75),
833 })
834
835 minetest.register_node("ladder", {
836         drawtype = "signlike",
837         tile_images = {"ladder.png"},
838         inventory_image = "ladder.png",
839         light_propagates = true,
840         paramtype = "light",
841         is_ground_content = true,
842         wall_mounted = true,
843         walkable = false,
844         climbable = true,
845         selection_box = {
846                 type = "wallmounted",
847                 --wall_top = = <default>
848                 --wall_bottom = = <default>
849                 --wall_side = = <default>
850         },
851         furnace_burntime = 5,
852         material = digprop_woodlike(0.5),
853 })
854
855 minetest.register_node("coalstone", {
856         tile_images = {"stone.png^mineral_coal.png"},
857         inventory_image = "stone.png^mineral_coal.png",
858         is_ground_content = true,
859         material = digprop_stonelike(1.5),
860 })
861
862 minetest.register_node("wood", {
863         tile_images = {"wood.png"},
864         inventory_image = inventorycube("wood.png"),
865         is_ground_content = true,
866         furnace_burntime = 7,
867         material = digprop_woodlike(0.75),
868 })
869
870 minetest.register_node("mese", {
871         tile_images = {"mese.png"},
872         inventory_image = inventorycube("mese.png"),
873         is_ground_content = true,
874         furnace_burntime = 30,
875         material = digprop_stonelike(0.5),
876 })
877
878 minetest.register_node("cloud", {
879         tile_images = {"cloud.png"},
880         inventory_image = inventorycube("cloud.png"),
881         is_ground_content = true,
882 })
883
884 minetest.register_node("water_flowing", {
885         drawtype = "flowingliquid",
886         tile_images = {"water.png"},
887         alpha = WATER_ALPHA,
888         inventory_image = inventorycube("water.png"),
889         paramtype = "light",
890         light_propagates = true,
891         walkable = false,
892         pointable = false,
893         diggable = false,
894         buildable_to = true,
895         liquidtype = "flowing",
896         liquid_alternative_flowing = "water_flowing",
897         liquid_alternative_source = "water_source",
898         liquid_viscosity = WATER_VISC,
899         post_effect_color = {a=64, r=100, g=100, b=200},
900         special_materials = {
901                 {image="water.png", backface_culling=false},
902                 {image="water.png", backface_culling=true},
903         },
904 })
905
906 minetest.register_node("water_source", {
907         drawtype = "liquid",
908         tile_images = {"water.png"},
909         alpha = WATER_ALPHA,
910         inventory_image = inventorycube("water.png"),
911         paramtype = "light",
912         light_propagates = true,
913         walkable = false,
914         pointable = false,
915         diggable = false,
916         buildable_to = true,
917         liquidtype = "source",
918         liquid_alternative_flowing = "water_flowing",
919         liquid_alternative_source = "water_source",
920         liquid_viscosity = WATER_VISC,
921         post_effect_color = {a=64, r=100, g=100, b=200},
922         special_materials = {
923                 -- New-style water source material (mostly unused)
924                 {image="water.png", backface_culling=false},
925         },
926 })
927
928 minetest.register_node("lava_flowing", {
929         drawtype = "flowingliquid",
930         tile_images = {"lava.png"},
931         inventory_image = inventorycube("lava.png"),
932         paramtype = "light",
933         light_propagates = false,
934         light_source = LIGHT_MAX - 1,
935         walkable = false,
936         pointable = false,
937         diggable = false,
938         buildable_to = true,
939         liquidtype = "flowing",
940         liquid_alternative_flowing = "lava_flowing",
941         liquid_alternative_source = "lava_source",
942         liquid_viscosity = LAVA_VISC,
943         damage_per_second = 4*2,
944         post_effect_color = {a=192, r=255, g=64, b=0},
945         special_materials = {
946                 {image="lava.png", backface_culling=false},
947                 {image="lava.png", backface_culling=true},
948         },
949 })
950
951 minetest.register_node("lava_source", {
952         drawtype = "liquid",
953         tile_images = {"lava.png"},
954         inventory_image = inventorycube("lava.png"),
955         paramtype = "light",
956         light_propagates = false,
957         light_source = LIGHT_MAX - 1,
958         walkable = false,
959         pointable = false,
960         diggable = false,
961         buildable_to = true,
962         liquidtype = "source",
963         liquid_alternative_flowing = "lava_flowing",
964         liquid_alternative_source = "lava_source",
965         liquid_viscosity = LAVA_VISC,
966         damage_per_second = 4*2,
967         post_effect_color = {a=192, r=255, g=64, b=0},
968         special_materials = {
969                 -- New-style lava source material (mostly unused)
970                 {image="lava.png", backface_culling=false},
971         },
972         furnace_burntime = 60,
973 })
974
975 minetest.register_node("torch", {
976         drawtype = "torchlike",
977         tile_images = {"torch_on_floor.png", "torch_on_ceiling.png", "torch.png"},
978         inventory_image = "torch_on_floor.png",
979         paramtype = "light",
980         light_propagates = true,
981         sunlight_propagates = true,
982         walkable = false,
983         wall_mounted = true,
984         light_source = LIGHT_MAX-1,
985         selection_box = {
986                 type = "wallmounted",
987                 wall_top = {-0.1, 0.5-0.6, -0.1, 0.1, 0.5, 0.1},
988                 wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
989                 wall_side = {-0.5, -0.3, -0.1, -0.5+0.3, 0.3, 0.1},
990         },
991         material = digprop_constanttime(0.0),
992         furnace_burntime = 4,
993 })
994
995 minetest.register_node("sign_wall", {
996         drawtype = "signlike",
997         tile_images = {"sign_wall.png"},
998         inventory_image = "sign_wall.png",
999         paramtype = "light",
1000         light_propagates = true,
1001         sunlight_propagates = true,
1002         walkable = false,
1003         wall_mounted = true,
1004         metadata_name = "sign",
1005         selection_box = {
1006                 type = "wallmounted",
1007                 --wall_top = <default>
1008                 --wall_bottom = <default>
1009                 --wall_side = <default>
1010         },
1011         material = digprop_constanttime(0.5),
1012         furnace_burntime = 10,
1013 })
1014
1015 minetest.register_node("chest", {
1016         tile_images = {"chest_top.png", "chest_top.png", "chest_side.png",
1017                 "chest_side.png", "chest_side.png", "chest_front.png"},
1018         inventory_image = "chest_top.png",
1019         --inventory_image = inventorycube("chest_top.png", "chest_side.png", "chest_front.png"),
1020         paramtype = "facedir_simple",
1021         metadata_name = "chest",
1022         material = digprop_woodlike(1.0),
1023         furnace_burntime = 30,
1024 })
1025
1026 minetest.register_node("locked_chest", {
1027         tile_images = {"chest_top.png", "chest_top.png", "chest_side.png",
1028                 "chest_side.png", "chest_side.png", "chest_lock.png"},
1029         inventory_image = "chest_lock.png",
1030         paramtype = "facedir_simple",
1031         metadata_name = "locked_chest",
1032         material = digprop_woodlike(1.0),
1033         furnace_burntime = 30,
1034 })
1035
1036 minetest.register_node("furnace", {
1037         tile_images = {"furnace_side.png", "furnace_side.png", "furnace_side.png",
1038                 "furnace_side.png", "furnace_side.png", "furnace_front.png"},
1039         inventory_image = "furnace_front.png",
1040         paramtype = "facedir_simple",
1041         metadata_name = "furnace",
1042         material = digprop_stonelike(3.0),
1043 })
1044
1045 minetest.register_node("cobble", {
1046         tile_images = {"cobble.png"},
1047         inventory_image = inventorycube("cobble.png"),
1048         is_ground_content = true,
1049         cookresult_item = 'NodeItem "stone" 1',
1050         material = digprop_stonelike(0.9),
1051 })
1052
1053 minetest.register_node("mossycobble", {
1054         tile_images = {"mossycobble.png"},
1055         inventory_image = inventorycube("mossycobble.png"),
1056         is_ground_content = true,
1057         material = digprop_stonelike(0.8),
1058 })
1059
1060 minetest.register_node("steelblock", {
1061         tile_images = {"steel_block.png"},
1062         inventory_image = inventorycube("steel_block.png"),
1063         is_ground_content = true,
1064         material = digprop_stonelike(5.0),
1065 })
1066
1067 minetest.register_node("nyancat", {
1068         tile_images = {"nc_side.png", "nc_side.png", "nc_side.png",
1069                 "nc_side.png", "nc_back.png", "nc_front.png"},
1070         inventory_image = "nc_front.png",
1071         paramtype = "facedir_simple",
1072         material = digprop_stonelike(3.0),
1073         furnace_burntime = 1,
1074 })
1075
1076 minetest.register_node("nyancat_rainbow", {
1077         tile_images = {"nc_rb.png"},
1078         inventory_image = "nc_rb.png",
1079         material = digprop_stonelike(3.0),
1080         furnace_burntime = 1,
1081 })
1082
1083 minetest.register_node("sapling", {
1084         drawtype = "plantlike",
1085         visual_scale = 1.0,
1086         tile_images = {"sapling.png"},
1087         inventory_image = "sapling.png",
1088         paramtype = "light",
1089         light_propagates = true,
1090         walkable = false,
1091         material = digprop_constanttime(0.0),
1092         furnace_burntime = 10,
1093 })
1094
1095 minetest.register_node("apple", {
1096         drawtype = "plantlike",
1097         visual_scale = 1.0,
1098         tile_images = {"apple.png"},
1099         inventory_image = "apple.png",
1100         paramtype = "light",
1101         light_propagates = true,
1102         sunlight_propagates = true,
1103         walkable = false,
1104         dug_item = 'CraftItem "apple" 1',
1105         material = digprop_constanttime(0.0),
1106         furnace_burntime = 3,
1107 })
1108
1109 -- New nodes
1110
1111 minetest.register_node("somenode", {
1112         tile_images = {"lava.png", "mese.png", "stone.png", "grass.png", "cobble.png", "tree_top.png"},
1113         inventory_image = "treeprop.png",
1114         material = {
1115                 diggability = "normal",
1116                 weight = 0,
1117                 crackiness = 0,
1118                 crumbliness = 0,
1119                 cuttability = 0,
1120                 flammability = 0
1121         },
1122         metadata_name = "chest",
1123 })
1124
1125 minetest.register_node("TNT", {
1126         tile_images = {"tnt_top.png", "tnt_bottom.png", "tnt_side.png", "tnt_side.png", "tnt_side.png", "tnt_side.png"},
1127         inventory_image = "tnt_side.png",
1128         dug_item = '', -- Get nothing
1129         material = {
1130                 diggability = "not",
1131         },
1132 })
1133
1134 --
1135 -- Some common functions
1136 --
1137
1138 function nodeupdate_single(p)
1139         n = minetest.env:get_node(p)
1140         if n.name == "sand" or n.name == "gravel" then
1141                 p_bottom = {x=p.x, y=p.y-1, z=p.z}
1142                 n_bottom = minetest.env:get_node(p_bottom)
1143                 if n_bottom.name == "air" then
1144                         minetest.env:remove_node(p)
1145                         minetest.env:add_luaentity(p, "falling_"..n.name)
1146                         nodeupdate(p)
1147                 end
1148         end
1149 end
1150
1151 function nodeupdate(p)
1152         for x = -1,1 do
1153         for y = -1,1 do
1154         for z = -1,1 do
1155                 p2 = {x=p.x+x, y=p.y+y, z=p.z+z}
1156                 nodeupdate_single(p2)
1157         end
1158         end
1159         end
1160 end
1161
1162 --
1163 -- TNT (not functional)
1164 --
1165
1166 local TNT = {
1167         -- Static definition
1168         physical = true, -- Collides with things
1169         -- weight = 5,
1170         collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
1171         visual = "cube",
1172         textures = {"tnt_top.png","tnt_bottom.png","tnt_side.png","tnt_side.png","tnt_side.png","tnt_side.png"},
1173         --visual = "single_sprite",
1174         --textures = {"mese.png^[forcesingle"},
1175         -- Initial value for our timer
1176         timer = 0,
1177         -- Number of punches required to defuse
1178         health = 1,
1179         blinktimer = 0,
1180         blinkstatus = true,
1181 }
1182
1183 -- Called when a TNT object is created
1184 function TNT:on_activate(staticdata)
1185         print("TNT:on_activate()")
1186         self.object:setvelocity({x=0, y=4, z=0})
1187         self.object:setacceleration({x=0, y=-10, z=0})
1188         self.object:settexturemod("^[brighten")
1189 end
1190
1191 -- Called periodically
1192 function TNT:on_step(dtime)
1193         --print("TNT:on_step()")
1194         self.timer = self.timer + dtime
1195         self.blinktimer = self.blinktimer + dtime
1196         if self.blinktimer > 0.5 then
1197                 self.blinktimer = self.blinktimer - 0.5
1198                 if blinkstatus then
1199                         self.object:settexturemod("")
1200                 else
1201                         self.object:settexturemod("^[brighten")
1202                 end
1203                 blinkstatus = not blinkstatus
1204         end
1205 end
1206
1207 -- Called when object is punched
1208 function TNT:on_punch(hitter)
1209         print("TNT:on_punch()")
1210         self.health = self.health - 1
1211         if self.health <= 0 then
1212                 self.object:remove()
1213                 hitter:add_to_inventory("NodeItem TNT 1")
1214         end
1215 end
1216
1217 -- Called when object is right-clicked
1218 function TNT:on_rightclick(clicker)
1219         --pos = self.object:getpos()
1220         --pos = {x=pos.x, y=pos.y+0.1, z=pos.z}
1221         --self.object:moveto(pos, false)
1222 end
1223
1224 print("TNT dump: "..dump(TNT))
1225
1226 print("Registering TNT");
1227 minetest.register_entity("TNT", TNT)
1228
1229 --
1230 -- Falling stuff
1231 --
1232
1233 function register_falling_node(nodename, texture)
1234         minetest.register_entity("falling_"..nodename, {
1235                 -- Static definition
1236                 physical = true,
1237                 collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
1238                 visual = "cube",
1239                 textures = {texture,texture,texture,texture,texture,texture},
1240                 -- State
1241                 -- Methods
1242                 on_step = function(self, dtime)
1243                         -- Set gravity
1244                         self.object:setacceleration({x=0, y=-10, z=0})
1245                         -- Turn to actual sand when collides to ground or just move
1246                         local pos = self.object:getpos()
1247                         local bcp = {x=pos.x, y=pos.y-0.7, z=pos.z} -- Position of bottom center point
1248                         local bcn = minetest.env:get_node(bcp)
1249                         if bcn.name ~= "air" then
1250                                 -- Turn to a sand node
1251                                 local np = {x=bcp.x, y=bcp.y+1, z=bcp.z}
1252                                 minetest.env:add_node(np, {name=nodename})
1253                                 self.object:remove()
1254                         else
1255                                 -- Do nothing
1256                         end
1257                 end
1258         })
1259 end
1260
1261 register_falling_node("sand", "sand.png")
1262 register_falling_node("gravel", "gravel.png")
1263
1264 --[[
1265 minetest.register_entity("falling_sand", {
1266         -- Definition
1267         collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
1268         visual = "cube",
1269         textures = {"sand.png","sand.png","sand.png","sand.png","sand.png","sand.png"},
1270         -- State
1271         fallspeed = 0,
1272         -- Methods
1273         on_step = function(self, dtime)
1274                 -- Apply gravity
1275                 self.fallspeed = self.fallspeed + dtime * 5
1276                 fp = self.object:getpos()
1277                 fp.y = fp.y - self.fallspeed * dtime
1278                 self.object:moveto(fp)
1279                 -- Turn to actual sand when collides to ground or just move
1280                 bcp = {x=fp.x, y=fp.y-0.5, z=fp.z} -- Position of bottom center point
1281                 bcn = minetest.env:get_node(bcp)
1282                 if bcn.name ~= "air" then
1283                         -- Turn to a sand node
1284                         np = {x=bcp.x, y=bcp.y+1, z=bcp.z}
1285                         minetest.env:add_node(np, {name="sand"})
1286                         self.object:remove()
1287                 else
1288                         -- Do nothing
1289                 end
1290         end
1291 })
1292 --]]
1293
1294 --
1295 -- Global callbacks
1296 --
1297
1298 -- Global environment step function
1299 function on_step(dtime)
1300         -- print("on_step")
1301 end
1302 minetest.register_globalstep(on_step)
1303
1304 function on_placenode(p, node)
1305         print("on_placenode")
1306         nodeupdate(p)
1307 end
1308 minetest.register_on_placenode(on_placenode)
1309
1310 function on_dignode(p, node)
1311         print("on_dignode")
1312         nodeupdate(p)
1313 end
1314 minetest.register_on_dignode(on_dignode)
1315
1316 function on_punchnode(p, node)
1317         print("on_punchnode")
1318         if node.name == "TNT" then
1319                 minetest.env:remove_node(p)
1320                 minetest.env:add_luaentity(p, "TNT")
1321                 nodeupdate(p)
1322         end
1323 end
1324 minetest.register_on_punchnode(on_punchnode)
1325
1326 minetest.register_on_respawnplayer(function(player)
1327         print("on_respawnplayer")
1328         -- player:setpos({x=0, y=30, z=0})
1329         -- return true
1330 end)
1331
1332 -- Example setting get
1333 print("setting max_users = " .. dump(minetest.setting_get("max_users")))
1334 print("setting asdf = " .. dump(minetest.setting_get("asdf")))
1335
1336 --
1337 -- Done, print some random stuff
1338 --
1339
1340 print("minetest.registered_entities:")
1341 dump2(minetest.registered_entities)
1342
1343 -- END