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