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