Lua interface for ActiveBlockModifier
[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 --
9 -- Global functions:
10 -- minetest.register_entity(name, prototype_table)
11 -- minetest.register_tool(name, {lots of stuff})
12 -- minetest.register_node(name, {lots of stuff})
13 -- minetest.register_craft({output=item, recipe={...})
14 -- minetest.register_globalstep(func)
15 -- minetest.register_on_placenode(func(pos, newnode, placer))
16 -- minetest.register_on_dignode(func(pos, oldnode, digger))
17 -- minetest.register_on_punchnode(func(pos, node, puncher))
18 -- minetest.register_on_generated(func(minp, maxp))
19 -- minetest.register_on_newplayer(func(ObjectRef))
20 -- minetest.register_on_respawnplayer(func(ObjectRef))
21 -- ^ return true in func to disable regular player placement
22 -- minetest.register_on_chat_message(func(name, message))
23 -- minetest.setting_get(name)
24 -- minetest.setting_getbool(name)
25 -- minetest.chat_send_all(text)
26 -- minetest.chat_send_player(name, text)
27 --
28 -- Global objects:
29 -- minetest.env - environment reference
30 --
31 -- Global tables:
32 -- minetest.registered_nodes
33 -- ^ List of registed node definitions, indexed by name
34 -- minetest.registered_entities
35 -- ^ List of registered entity prototypes, indexed by name
36 -- minetest.object_refs
37 -- ^ List of object references, indexed by active object id
38 -- minetest.luaentities
39 -- ^ List of lua entities, indexed by active object id
40 --
41 -- EnvRef is basically ServerEnvironment and ServerMap combined.
42 -- EnvRef methods:
43 -- - add_node(pos, node)
44 -- - remove_node(pos)
45 -- - get_node(pos)
46 -- - add_luaentity(pos, name)
47 --
48 -- ObjectRef is basically ServerActiveObject.
49 -- ObjectRef methods:
50 -- - remove(): remove object (after returning from Lua)
51 -- - getpos(): returns {x=num, y=num, z=num}
52 -- - setpos(pos); pos={x=num, y=num, z=num}
53 -- - moveto(pos, continuous=false): interpolated move
54 -- - add_to_inventory(itemstring): add an item to object inventory
55 -- - settexturemod(mod)
56 -- - setsprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
57 -- -           select_horiz_by_yawpitch=false)
58 --
59 -- Registered entities:
60 -- - Functions receive a "luaentity" as self:
61 --   - It has the member .object, which is an ObjectRef pointing to the object
62 --   - The original prototype stuff is visible directly via a metatable
63 -- - Callbacks:
64 --   - on_activate(self, staticdata)
65 --   - on_step(self, dtime)
66 --   - on_punch(self, hitter)
67 --   - on_rightclick(self, clicker)
68 --   - get_staticdata(self): return string
69 --
70 -- MapNode representation:
71 -- {name="name", param1=num, param2=num}
72 --
73 -- Position representation:
74 -- {x=num, y=num, z=num}
75 --
76
77 -- print("minetest dump: "..dump(minetest))
78
79 WATER_ALPHA = 160
80 WATER_VISC = 1
81 LAVA_VISC = 7
82 LIGHT_MAX = 14
83
84 --
85 -- Tool definition
86 --
87
88 minetest.register_tool("WPick", {
89         image = "tool_woodpick.png",
90         basetime = 2.0,
91         dt_weight = 0,
92         dt_crackiness = -0.5,
93         dt_crumbliness = 2,
94         dt_cuttability = 0,
95         basedurability = 30,
96         dd_weight = 0,
97         dd_crackiness = 0,
98         dd_crumbliness = 0,
99         dd_cuttability = 0,
100 })
101 minetest.register_tool("STPick", {
102         image = "tool_stonepick.png",
103         basetime = 1.5,
104         dt_weight = 0,
105         dt_crackiness = -0.5,
106         dt_crumbliness = 2,
107         dt_cuttability = 0,
108         basedurability = 100,
109         dd_weight = 0,
110         dd_crackiness = 0,
111         dd_crumbliness = 0,
112         dd_cuttability = 0,
113 })
114 minetest.register_tool("SteelPick", {
115         image = "tool_steelpick.png",
116         basetime = 1.0,
117         dt_weight = 0,
118         dt_crackiness = -0.5,
119         dt_crumbliness = 2,
120         dt_cuttability = 0,
121         basedurability = 333,
122         dd_weight = 0,
123         dd_crackiness = 0,
124         dd_crumbliness = 0,
125         dd_cuttability = 0,
126 })
127 minetest.register_tool("MesePick", {
128         image = "tool_mesepick.png",
129         basetime = 0,
130         dt_weight = 0,
131         dt_crackiness = 0,
132         dt_crumbliness = 0,
133         dt_cuttability = 0,
134         basedurability = 1337,
135         dd_weight = 0,
136         dd_crackiness = 0,
137         dd_crumbliness = 0,
138         dd_cuttability = 0,
139 })
140 minetest.register_tool("WShovel", {
141         image = "tool_woodshovel.png",
142         basetime = 2.0,
143         dt_weight = 0.5,
144         dt_crackiness = 2,
145         dt_crumbliness = -1.5,
146         dt_cuttability = 0.3,
147         basedurability = 30,
148         dd_weight = 0,
149         dd_crackiness = 0,
150         dd_crumbliness = 0,
151         dd_cuttability = 0,
152 })
153 minetest.register_tool("STShovel", {
154         image = "tool_stoneshovel.png",
155         basetime = 1.5,
156         dt_weight = 0.5,
157         dt_crackiness = 2,
158         dt_crumbliness = -1.5,
159         dt_cuttability = 0.1,
160         basedurability = 100,
161         dd_weight = 0,
162         dd_crackiness = 0,
163         dd_crumbliness = 0,
164         dd_cuttability = 0,
165 })
166 minetest.register_tool("SteelShovel", {
167         image = "tool_steelshovel.png",
168         basetime = 1.0,
169         dt_weight = 0.5,
170         dt_crackiness = 2,
171         dt_crumbliness = -1.5,
172         dt_cuttability = 0.0,
173         basedurability = 330,
174         dd_weight = 0,
175         dd_crackiness = 0,
176         dd_crumbliness = 0,
177         dd_cuttability = 0,
178 })
179 minetest.register_tool("WAxe", {
180         image = "tool_woodaxe.png",
181         basetime = 2.0,
182         dt_weight = 0.5,
183         dt_crackiness = -0.2,
184         dt_crumbliness = 1,
185         dt_cuttability = -0.5,
186         basedurability = 30,
187         dd_weight = 0,
188         dd_crackiness = 0,
189         dd_crumbliness = 0,
190         dd_cuttability = 0,
191 })
192 minetest.register_tool("STAxe", {
193         image = "tool_stoneaxe.png",
194         basetime = 1.5,
195         dt_weight = 0.5,
196         dt_crackiness = -0.2,
197         dt_crumbliness = 1,
198         dt_cuttability = -0.5,
199         basedurability = 100,
200         dd_weight = 0,
201         dd_crackiness = 0,
202         dd_crumbliness = 0,
203         dd_cuttability = 0,
204 })
205 minetest.register_tool("SteelAxe", {
206         image = "tool_steelaxe.png",
207         basetime = 1.0,
208         dt_weight = 0.5,
209         dt_crackiness = -0.2,
210         dt_crumbliness = 1,
211         dt_cuttability = -0.5,
212         basedurability = 330,
213         dd_weight = 0,
214         dd_crackiness = 0,
215         dd_crumbliness = 0,
216         dd_cuttability = 0,
217 })
218 minetest.register_tool("WSword", {
219         image = "tool_woodsword.png",
220         basetime = 3.0,
221         dt_weight = 3,
222         dt_crackiness = 0,
223         dt_crumbliness = 1,
224         dt_cuttability = -1,
225         basedurability = 30,
226         dd_weight = 0,
227         dd_crackiness = 0,
228         dd_crumbliness = 0,
229         dd_cuttability = 0,
230 })
231 minetest.register_tool("STSword", {
232         image = "tool_stonesword.png",
233         basetime = 2.5,
234         dt_weight = 3,
235         dt_crackiness = 0,
236         dt_crumbliness = 1,
237         dt_cuttability = -1,
238         basedurability = 100,
239         dd_weight = 0,
240         dd_crackiness = 0,
241         dd_crumbliness = 0,
242         dd_cuttability = 0,
243 })
244 minetest.register_tool("SteelSword", {
245         image = "tool_steelsword.png",
246         basetime = 2.0,
247         dt_weight = 3,
248         dt_crackiness = 0,
249         dt_crumbliness = 1,
250         dt_cuttability = -1,
251         basedurability = 330,
252         dd_weight = 0,
253         dd_crackiness = 0,
254         dd_crumbliness = 0,
255         dd_cuttability = 0,
256 })
257 minetest.register_tool("", {
258         image = "",
259         basetime = 0.5,
260         dt_weight = 1,
261         dt_crackiness = 0,
262         dt_crumbliness = -1,
263         dt_cuttability = 0,
264         basedurability = 50,
265         dd_weight = 0,
266         dd_crackiness = 0,
267         dd_crumbliness = 0,
268         dd_cuttability = 0,
269 })
270
271 --[[
272 minetest.register_tool("horribletool", {
273         image = "lava.png",
274         basetime = 2.0
275         dt_weight = 0.2
276         dt_crackiness = 0.2
277         dt_crumbliness = 0.2
278         dt_cuttability = 0.2
279         basedurability = 50
280         dd_weight = -5
281         dd_crackiness = -5
282         dd_crumbliness = -5
283         dd_cuttability = -5
284 })
285 --]]
286
287 --
288 -- Crafting definition
289 --
290
291 minetest.register_craft({
292         output = 'NodeItem "wood" 4',
293         recipe = {
294                 {'NodeItem "tree"'},
295         }
296 })
297
298 minetest.register_craft({
299         output = 'CraftItem "Stick" 4',
300         recipe = {
301                 {'NodeItem "wood"'},
302         }
303 })
304
305 minetest.register_craft({
306         output = 'NodeItem "wooden_fence" 2',
307         recipe = {
308                 {'CraftItem "Stick"', 'CraftItem "Stick"', 'CraftItem "Stick"'},
309                 {'CraftItem "Stick"', 'CraftItem "Stick"', 'CraftItem "Stick"'},
310         }
311 })
312
313 minetest.register_craft({
314         output = 'NodeItem "sign_wall" 1',
315         recipe = {
316                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
317                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
318                 {'', 'CraftItem "Stick"', ''},
319         }
320 })
321
322 minetest.register_craft({
323         output = 'NodeItem "torch" 4',
324         recipe = {
325                 {'CraftItem "lump_of_coal"'},
326                 {'CraftItem "Stick"'},
327         }
328 })
329
330 minetest.register_craft({
331         output = 'ToolItem "WPick"',
332         recipe = {
333                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
334                 {'', 'CraftItem "Stick"', ''},
335                 {'', 'CraftItem "Stick"', ''},
336         }
337 })
338
339 minetest.register_craft({
340         output = 'ToolItem "STPick"',
341         recipe = {
342                 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
343                 {'', 'CraftItem "Stick"', ''},
344                 {'', 'CraftItem "Stick"', ''},
345         }
346 })
347
348 minetest.register_craft({
349         output = 'ToolItem "SteelPick"',
350         recipe = {
351                 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
352                 {'', 'CraftItem "Stick"', ''},
353                 {'', 'CraftItem "Stick"', ''},
354         }
355 })
356
357 minetest.register_craft({
358         output = 'ToolItem "MesePick"',
359         recipe = {
360                 {'NodeItem "mese"', 'NodeItem "mese"', 'NodeItem "mese"'},
361                 {'', 'CraftItem "Stick"', ''},
362                 {'', 'CraftItem "Stick"', ''},
363         }
364 })
365
366 minetest.register_craft({
367         output = 'ToolItem "WShovel"',
368         recipe = {
369                 {'NodeItem "wood"'},
370                 {'CraftItem "Stick"'},
371                 {'CraftItem "Stick"'},
372         }
373 })
374
375 minetest.register_craft({
376         output = 'ToolItem "STShovel"',
377         recipe = {
378                 {'NodeItem "cobble"'},
379                 {'CraftItem "Stick"'},
380                 {'CraftItem "Stick"'},
381         }
382 })
383
384 minetest.register_craft({
385         output = 'ToolItem "SteelShovel"',
386         recipe = {
387                 {'CraftItem "steel_ingot"'},
388                 {'CraftItem "Stick"'},
389                 {'CraftItem "Stick"'},
390         }
391 })
392
393 minetest.register_craft({
394         output = 'ToolItem "WAxe"',
395         recipe = {
396                 {'NodeItem "wood"', 'NodeItem "wood"'},
397                 {'NodeItem "wood"', 'CraftItem "Stick"'},
398                 {'', 'CraftItem "Stick"'},
399         }
400 })
401
402 minetest.register_craft({
403         output = 'ToolItem "STAxe"',
404         recipe = {
405                 {'NodeItem "cobble"', 'NodeItem "cobble"'},
406                 {'NodeItem "cobble"', 'CraftItem "Stick"'},
407                 {'', 'CraftItem "Stick"'},
408         }
409 })
410
411 minetest.register_craft({
412         output = 'ToolItem "SteelAxe"',
413         recipe = {
414                 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
415                 {'CraftItem "steel_ingot"', 'CraftItem "Stick"'},
416                 {'', 'CraftItem "Stick"'},
417         }
418 })
419
420 minetest.register_craft({
421         output = 'ToolItem "WSword"',
422         recipe = {
423                 {'NodeItem "wood"'},
424                 {'NodeItem "wood"'},
425                 {'CraftItem "Stick"'},
426         }
427 })
428
429 minetest.register_craft({
430         output = 'ToolItem "STSword"',
431         recipe = {
432                 {'NodeItem "cobble"'},
433                 {'NodeItem "cobble"'},
434                 {'CraftItem "Stick"'},
435         }
436 })
437
438 minetest.register_craft({
439         output = 'ToolItem "SteelSword"',
440         recipe = {
441                 {'CraftItem "steel_ingot"'},
442                 {'CraftItem "steel_ingot"'},
443                 {'CraftItem "Stick"'},
444         }
445 })
446
447 minetest.register_craft({
448         output = 'NodeItem "rail" 15',
449         recipe = {
450                 {'CraftItem "steel_ingot"', '', 'CraftItem "steel_ingot"'},
451                 {'CraftItem "steel_ingot"', 'CraftItem "Stick"', 'CraftItem "steel_ingot"'},
452                 {'CraftItem "steel_ingot"', '', 'CraftItem "steel_ingot"'},
453         }
454 })
455
456 minetest.register_craft({
457         output = 'NodeItem "chest" 1',
458         recipe = {
459                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
460                 {'NodeItem "wood"', '', 'NodeItem "wood"'},
461                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
462         }
463 })
464
465 minetest.register_craft({
466         output = 'NodeItem "locked_chest" 1',
467         recipe = {
468                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
469                 {'NodeItem "wood"', 'CraftItem "steel_ingot"', 'NodeItem "wood"'},
470                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
471         }
472 })
473
474 minetest.register_craft({
475         output = 'NodeItem "furnace" 1',
476         recipe = {
477                 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
478                 {'NodeItem "cobble"', '', 'NodeItem "cobble"'},
479                 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
480         }
481 })
482
483 minetest.register_craft({
484         output = 'NodeItem "steelblock" 1',
485         recipe = {
486                 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
487                 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
488                 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
489         }
490 })
491
492 minetest.register_craft({
493         output = 'NodeItem "sandstone" 1',
494         recipe = {
495                 {'NodeItem "sand"', 'NodeItem "sand"'},
496                 {'NodeItem "sand"', 'NodeItem "sand"'},
497         }
498 })
499
500 minetest.register_craft({
501         output = 'NodeItem "clay" 1',
502         recipe = {
503                 {'CraftItem "lump_of_clay"', 'CraftItem "lump_of_clay"'},
504                 {'CraftItem "lump_of_clay"', 'CraftItem "lump_of_clay"'},
505         }
506 })
507
508 minetest.register_craft({
509         output = 'NodeItem "brick" 1',
510         recipe = {
511                 {'CraftItem "clay_brick"', 'CraftItem "clay_brick"'},
512                 {'CraftItem "clay_brick"', 'CraftItem "clay_brick"'},
513         }
514 })
515
516 minetest.register_craft({
517         output = 'CraftItem "paper" 1',
518         recipe = {
519                 {'NodeItem "papyrus"', 'NodeItem "papyrus"', 'NodeItem "papyrus"'},
520         }
521 })
522
523 minetest.register_craft({
524         output = 'CraftItem "book" 1',
525         recipe = {
526                 {'CraftItem "paper"'},
527                 {'CraftItem "paper"'},
528                 {'CraftItem "paper"'},
529         }
530 })
531
532 minetest.register_craft({
533         output = 'NodeItem "bookshelf" 1',
534         recipe = {
535                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
536                 {'CraftItem "book"', 'CraftItem "book"', 'CraftItem "book"'},
537                 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
538         }
539 })
540
541 minetest.register_craft({
542         output = 'NodeItem "ladder" 1',
543         recipe = {
544                 {'CraftItem "Stick"', '', 'CraftItem "Stick"'},
545                 {'CraftItem "Stick"', 'CraftItem "Stick"', 'CraftItem "Stick"'},
546                 {'CraftItem "Stick"', '', 'CraftItem "Stick"'},
547         }
548 })
549
550 minetest.register_craft({
551         output = 'CraftItem "apple_iron" 1',
552         recipe = {
553                 {'', 'CraftItem "steel_ingot"', ''},
554                 {'CraftItem "steel_ingot"', 'CraftItem "apple"', 'CraftItem "steel_ingot"'},
555                 {'', 'CraftItem "steel_ingot"', ''},
556         }
557 })
558
559 minetest.register_craft({
560         output = 'NodeItem "TNT" 4',
561         recipe = {
562                 {'NodeItem "wood" 1'},
563                 {'CraftItem "lump_of_coal" 1'},
564                 {'NodeItem "wood" 1'}
565         }
566 })
567
568 minetest.register_craft({
569         output = 'NodeItem "somenode" 4',
570         recipe = {
571                 {'CraftItem "Stick" 1'},
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 -- New nodes
1117
1118 minetest.register_node("somenode", {
1119         tile_images = {"lava.png", "mese.png", "stone.png", "grass.png", "cobble.png", "tree_top.png"},
1120         inventory_image = "treeprop.png",
1121         material = {
1122                 diggability = "normal",
1123                 weight = 0,
1124                 crackiness = 0,
1125                 crumbliness = 0,
1126                 cuttability = 0,
1127                 flammability = 0
1128         },
1129         metadata_name = "chest",
1130 })
1131
1132 minetest.register_node("TNT", {
1133         tile_images = {"tnt_top.png", "tnt_bottom.png", "tnt_side.png", "tnt_side.png", "tnt_side.png", "tnt_side.png"},
1134         inventory_image = "tnt_side.png",
1135         dug_item = '', -- Get nothing
1136         material = {
1137                 diggability = "not",
1138         },
1139 })
1140
1141 --
1142 -- Some common functions
1143 --
1144
1145 function nodeupdate_single(p)
1146         n = minetest.env:get_node(p)
1147         if n.name == "sand" or n.name == "gravel" then
1148                 p_bottom = {x=p.x, y=p.y-1, z=p.z}
1149                 n_bottom = minetest.env:get_node(p_bottom)
1150                 if n_bottom.name == "air" then
1151                         minetest.env:remove_node(p)
1152                         minetest.env:add_luaentity(p, "falling_"..n.name)
1153                         nodeupdate(p)
1154                 end
1155         end
1156 end
1157
1158 function nodeupdate(p)
1159         for x = -1,1 do
1160         for y = -1,1 do
1161         for z = -1,1 do
1162                 p2 = {x=p.x+x, y=p.y+y, z=p.z+z}
1163                 nodeupdate_single(p2)
1164         end
1165         end
1166         end
1167 end
1168
1169 --
1170 -- TNT (not functional)
1171 --
1172
1173 local TNT = {
1174         -- Static definition
1175         physical = true, -- Collides with things
1176         -- weight = 5,
1177         collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
1178         visual = "cube",
1179         textures = {"tnt_top.png","tnt_bottom.png","tnt_side.png","tnt_side.png","tnt_side.png","tnt_side.png"},
1180         -- Initial value for our timer
1181         timer = 0,
1182         -- Number of punches required to defuse
1183         health = 1,
1184         blinktimer = 0,
1185         blinkstatus = true,
1186 }
1187
1188 -- Called when a TNT object is created
1189 function TNT:on_activate(staticdata)
1190         print("TNT:on_activate()")
1191         self.object:setvelocity({x=0, y=4, z=0})
1192         self.object:setacceleration({x=0, y=-10, z=0})
1193         self.object:settexturemod("^[brighten")
1194 end
1195
1196 -- Called periodically
1197 function TNT:on_step(dtime)
1198         --print("TNT:on_step()")
1199         self.timer = self.timer + dtime
1200         self.blinktimer = self.blinktimer + dtime
1201         if self.blinktimer > 0.5 then
1202                 self.blinktimer = self.blinktimer - 0.5
1203                 if self.blinkstatus then
1204                         self.object:settexturemod("")
1205                 else
1206                         self.object:settexturemod("^[brighten")
1207                 end
1208                 self.blinkstatus = not self.blinkstatus
1209         end
1210 end
1211
1212 -- Called when object is punched
1213 function TNT:on_punch(hitter)
1214         print("TNT:on_punch()")
1215         self.health = self.health - 1
1216         if self.health <= 0 then
1217                 self.object:remove()
1218                 hitter:add_to_inventory("NodeItem TNT 1")
1219         end
1220 end
1221
1222 -- Called when object is right-clicked
1223 function TNT:on_rightclick(clicker)
1224         --pos = self.object:getpos()
1225         --pos = {x=pos.x, y=pos.y+0.1, z=pos.z}
1226         --self.object:moveto(pos, false)
1227 end
1228
1229 print("TNT dump: "..dump(TNT))
1230
1231 print("Registering TNT");
1232 minetest.register_entity("TNT", TNT)
1233
1234
1235 minetest.register_entity("testentity", {
1236         -- Static definition
1237         physical = true, -- Collides with things
1238         -- weight = 5,
1239         collisionbox = {-0.7,-1.35,-0.7, 0.7,1.0,0.7},
1240         --collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
1241         visual = "sprite",
1242         visual_size = {x=2, y=3},
1243         textures = {"dungeon_master.png^[makealpha:128,0,0^[makealpha:128,128,0"},
1244         spritediv = {x=6, y=5},
1245         initial_sprite_basepos = {x=0, y=0},
1246
1247         on_activate = function(self, staticdata)
1248                 print("testentity.on_activate")
1249                 self.object:setsprite({x=0,y=0}, 1, 0, true)
1250                 --self.object:setsprite({x=0,y=0}, 4, 0.3, true)
1251
1252                 -- Set gravity
1253                 self.object:setacceleration({x=0, y=-10, z=0})
1254                 -- Jump a bit upwards
1255                 self.object:setvelocity({x=0, y=10, z=0})
1256         end,
1257
1258         on_punch = function(self, hitter)
1259                 self.object:remove()
1260                 hitter:add_to_inventory('CraftItem testobject1 1')
1261         end,
1262 })
1263
1264 --
1265 -- Falling stuff
1266 --
1267
1268 function register_falling_node(nodename, texture)
1269         minetest.register_entity("falling_"..nodename, {
1270                 -- Static definition
1271                 physical = true,
1272                 collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
1273                 visual = "cube",
1274                 textures = {texture,texture,texture,texture,texture,texture},
1275                 -- State
1276                 -- Methods
1277                 on_step = function(self, dtime)
1278                         -- Set gravity
1279                         self.object:setacceleration({x=0, y=-10, z=0})
1280                         -- Turn to actual sand when collides to ground or just move
1281                         local pos = self.object:getpos()
1282                         local bcp = {x=pos.x, y=pos.y-0.7, z=pos.z} -- Position of bottom center point
1283                         local bcn = minetest.env:get_node(bcp)
1284                         if bcn.name ~= "air" then
1285                                 -- Turn to a sand node
1286                                 local np = {x=bcp.x, y=bcp.y+1, z=bcp.z}
1287                                 minetest.env:add_node(np, {name=nodename})
1288                                 self.object:remove()
1289                         else
1290                                 -- Do nothing
1291                         end
1292                 end
1293         })
1294 end
1295
1296 register_falling_node("sand", "sand.png")
1297 register_falling_node("gravel", "gravel.png")
1298
1299 --
1300 -- Global callbacks
1301 --
1302
1303 -- Global environment step function
1304 function on_step(dtime)
1305         -- print("on_step")
1306 end
1307 minetest.register_globalstep(on_step)
1308
1309 function on_placenode(p, node)
1310         print("on_placenode")
1311         nodeupdate(p)
1312 end
1313 minetest.register_on_placenode(on_placenode)
1314
1315 function on_dignode(p, node)
1316         print("on_dignode")
1317         nodeupdate(p)
1318 end
1319 minetest.register_on_dignode(on_dignode)
1320
1321 function on_punchnode(p, node)
1322         print("on_punchnode")
1323         if node.name == "TNT" then
1324                 minetest.env:remove_node(p)
1325                 minetest.env:add_luaentity(p, "TNT")
1326                 nodeupdate(p)
1327         end
1328 end
1329 minetest.register_on_punchnode(on_punchnode)
1330
1331 minetest.register_on_respawnplayer(function(player)
1332         print("on_respawnplayer")
1333         -- player:setpos({x=0, y=30, z=0})
1334         -- return true
1335 end)
1336
1337 minetest.register_on_generated(function(minp, maxp)
1338         --print("on_generated: minp="..dump(minp).." maxp="..dump(maxp))
1339         --cp = {x=(minp.x+maxp.x)/2, y=(minp.y+maxp.y)/2, z=(minp.z+maxp.z)/2}
1340         --minetest.env:add_node(cp, {name="sand"})
1341 end)
1342
1343 -- Example setting get
1344 print("setting max_users = " .. dump(minetest.setting_get("max_users")))
1345 print("setting asdf = " .. dump(minetest.setting_get("asdf")))
1346
1347 minetest.register_on_chat_message(function(name, message)
1348         print("on_chat_message: name="..dump(name).." message="..dump(message))
1349         local cmd = "/testcommand"
1350         if message:sub(0, #cmd) == cmd then
1351                 print(cmd.." invoked")
1352                 return true
1353         end
1354         local cmd = "/help"
1355         if message:sub(0, #cmd) == cmd then
1356                 print("script-overridden help command")
1357                 minetest.chat_send_all("script-overridden help command")
1358                 return true
1359         end
1360 end)
1361
1362 minetest.register_abm({
1363         nodenames = {"TNT"},
1364         interval = 10.0,
1365         chance = 1,
1366         action = function(pos, node, active_object_count, active_object_count_wider)
1367                 print("TNT ABM action")
1368                 pos.y = pos.y + 1
1369                 minetest.env:add_node(pos, {name="papyrus"})
1370         end,
1371 })
1372
1373 --
1374 -- Done, print some random stuff
1375 --
1376
1377 print("minetest.registered_entities:")
1378 dump2(minetest.registered_entities)
1379
1380 -- END