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