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