1 -- Helper functions defined by builtin.lua:
2 -- dump2(obj, name="_", dumped={})
3 -- dump(obj, dumped={})
6 -- Mods should prefix their textures with modname_, eg. given the mod
7 -- name "foomod", a texture could be called "foomod_superfurnace.png"
8 -- Due to historical reasons, the default mod does not follow this rule.
11 -- minetest.register_entity(name, prototype_table)
12 -- minetest.register_tool(name, {lots of stuff})
13 -- minetest.register_node(name, {lots of stuff})
14 -- minetest.register_craftitem(name, {lots of stuff})
15 -- minetest.register_craft({output=item, recipe={...})
16 -- minetest.register_globalstep(func)
17 -- minetest.register_on_placenode(func(pos, newnode, placer))
18 -- minetest.register_on_dignode(func(pos, oldnode, digger))
19 -- minetest.register_on_punchnode(func(pos, node, puncher))
20 -- minetest.register_on_generated(func(minp, maxp))
21 -- minetest.register_on_newplayer(func(ObjectRef))
22 -- minetest.register_on_respawnplayer(func(ObjectRef))
23 -- ^ return true in func to disable regular player placement
24 -- minetest.register_on_chat_message(func(name, message))
25 -- minetest.setting_get(name)
26 -- minetest.setting_getbool(name)
27 -- minetest.chat_send_all(text)
28 -- minetest.chat_send_player(name, text)
29 -- minetest.get_player_privs(name)
32 -- minetest.env - environment reference
35 -- minetest.registered_nodes
36 -- ^ List of registered node definitions, indexed by name
37 -- minetest.registered_craftitems
38 -- ^ List of registered craft item definitions, indexed by name
39 -- minetest.registered_entities
40 -- ^ List of registered entity prototypes, indexed by name
41 -- minetest.object_refs
42 -- ^ List of object references, indexed by active object id
43 -- minetest.luaentities
44 -- ^ List of lua entities, indexed by active object id
46 -- EnvRef is basically ServerEnvironment and ServerMap combined.
48 -- - add_node(pos, node)
51 -- - add_luaentity(pos, name)
52 -- - add_item(pos, itemstring)
55 -- - get_meta(pos) -- Get a NodeMetaRef at that position
56 -- - get_player_by_name(name) -- Get an ObjectRef to a player
60 -- - allows_text_input()
61 -- - set_text(text) -- eg. set the text of a sign
64 -- - set_infotext(infotext)
65 -- - inventory_set_list(name, {item1, item2, ...})
66 -- - inventory_get_list(name)
67 -- - set_inventory_draw_spec(string)
68 -- - set_allow_text_input(bool)
69 -- - set_allow_removal(bool)
70 -- - set_enforce_owner(bool)
71 -- - is_inventory_modified()
72 -- - reset_inventory_modified()
73 -- - is_text_modified()
74 -- - reset_text_modified()
75 -- - set_string(name, value)
78 -- ObjectRef is basically ServerActiveObject.
80 -- - remove(): remove object (after returning from Lua)
81 -- - getpos(): returns {x=num, y=num, z=num}
82 -- - setpos(pos); pos={x=num, y=num, z=num}
83 -- - moveto(pos, continuous=false): interpolated move
84 -- - add_to_inventory(itemstring): add an item to object inventory
85 -- - add_to_inventory_later(itemstring): like above, but after callback returns (only allowed for craftitem callbacks)
86 -- - get_hp(): returns number of hitpoints (2 * number of hearts)
87 -- - set_hp(hp): set number of hitpoints (2 * number of hearts)
88 -- - settexturemod(mod)
89 -- - setsprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
90 -- - select_horiz_by_yawpitch=false)
92 -- Registered entities:
93 -- - Functions receive a "luaentity" as self:
94 -- - It has the member .object, which is an ObjectRef pointing to the object
95 -- - The original prototype stuff is visible directly via a metatable
97 -- - on_activate(self, staticdata)
98 -- - on_step(self, dtime)
99 -- - on_punch(self, hitter)
100 -- - on_rightclick(self, clicker)
101 -- - get_staticdata(self): return string
103 -- MapNode representation:
104 -- {name="name", param1=num, param2=num}
106 -- Position representation:
107 -- {x=num, y=num, z=num}
110 -- print("minetest dump: "..dump(minetest))
121 minetest.register_tool("WPick", {
122 image = "tool_woodpick.png",
125 dt_crackiness = -0.5,
134 minetest.register_tool("STPick", {
135 image = "tool_stonepick.png",
138 dt_crackiness = -0.5,
141 basedurability = 100,
147 minetest.register_tool("SteelPick", {
148 image = "tool_steelpick.png",
151 dt_crackiness = -0.5,
154 basedurability = 333,
160 minetest.register_tool("MesePick", {
161 image = "tool_mesepick.png",
167 basedurability = 1337,
173 minetest.register_tool("WShovel", {
174 image = "tool_woodshovel.png",
178 dt_crumbliness = -1.5,
179 dt_cuttability = 0.3,
186 minetest.register_tool("STShovel", {
187 image = "tool_stoneshovel.png",
191 dt_crumbliness = -1.5,
192 dt_cuttability = 0.1,
193 basedurability = 100,
199 minetest.register_tool("SteelShovel", {
200 image = "tool_steelshovel.png",
204 dt_crumbliness = -1.5,
205 dt_cuttability = 0.0,
206 basedurability = 330,
212 minetest.register_tool("WAxe", {
213 image = "tool_woodaxe.png",
216 dt_crackiness = -0.2,
218 dt_cuttability = -0.5,
225 minetest.register_tool("STAxe", {
226 image = "tool_stoneaxe.png",
229 dt_crackiness = -0.2,
231 dt_cuttability = -0.5,
232 basedurability = 100,
238 minetest.register_tool("SteelAxe", {
239 image = "tool_steelaxe.png",
242 dt_crackiness = -0.2,
244 dt_cuttability = -0.5,
245 basedurability = 330,
251 minetest.register_tool("WSword", {
252 image = "tool_woodsword.png",
264 minetest.register_tool("STSword", {
265 image = "tool_stonesword.png",
271 basedurability = 100,
277 minetest.register_tool("SteelSword", {
278 image = "tool_steelsword.png",
284 basedurability = 330,
291 minetest.register_tool("", {
306 -- Crafting definition
309 minetest.register_craft({
310 output = 'NodeItem "wood" 4',
316 minetest.register_craft({
317 output = 'CraftItem "Stick" 4',
323 minetest.register_craft({
324 output = 'NodeItem "wooden_fence" 2',
326 {'CraftItem "Stick"', 'CraftItem "Stick"', 'CraftItem "Stick"'},
327 {'CraftItem "Stick"', 'CraftItem "Stick"', 'CraftItem "Stick"'},
331 minetest.register_craft({
332 output = 'NodeItem "sign_wall" 1',
334 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
335 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
336 {'', 'CraftItem "Stick"', ''},
340 minetest.register_craft({
341 output = 'NodeItem "torch" 4',
343 {'CraftItem "lump_of_coal"'},
344 {'CraftItem "Stick"'},
348 minetest.register_craft({
349 output = 'ToolItem "WPick"',
351 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
352 {'', 'CraftItem "Stick"', ''},
353 {'', 'CraftItem "Stick"', ''},
357 minetest.register_craft({
358 output = 'ToolItem "STPick"',
360 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
361 {'', 'CraftItem "Stick"', ''},
362 {'', 'CraftItem "Stick"', ''},
366 minetest.register_craft({
367 output = 'ToolItem "SteelPick"',
369 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
370 {'', 'CraftItem "Stick"', ''},
371 {'', 'CraftItem "Stick"', ''},
375 minetest.register_craft({
376 output = 'ToolItem "MesePick"',
378 {'NodeItem "mese"', 'NodeItem "mese"', 'NodeItem "mese"'},
379 {'', 'CraftItem "Stick"', ''},
380 {'', 'CraftItem "Stick"', ''},
384 minetest.register_craft({
385 output = 'ToolItem "WShovel"',
388 {'CraftItem "Stick"'},
389 {'CraftItem "Stick"'},
393 minetest.register_craft({
394 output = 'ToolItem "STShovel"',
396 {'NodeItem "cobble"'},
397 {'CraftItem "Stick"'},
398 {'CraftItem "Stick"'},
402 minetest.register_craft({
403 output = 'ToolItem "SteelShovel"',
405 {'CraftItem "steel_ingot"'},
406 {'CraftItem "Stick"'},
407 {'CraftItem "Stick"'},
411 minetest.register_craft({
412 output = 'ToolItem "WAxe"',
414 {'NodeItem "wood"', 'NodeItem "wood"'},
415 {'NodeItem "wood"', 'CraftItem "Stick"'},
416 {'', 'CraftItem "Stick"'},
420 minetest.register_craft({
421 output = 'ToolItem "STAxe"',
423 {'NodeItem "cobble"', 'NodeItem "cobble"'},
424 {'NodeItem "cobble"', 'CraftItem "Stick"'},
425 {'', 'CraftItem "Stick"'},
429 minetest.register_craft({
430 output = 'ToolItem "SteelAxe"',
432 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
433 {'CraftItem "steel_ingot"', 'CraftItem "Stick"'},
434 {'', 'CraftItem "Stick"'},
438 minetest.register_craft({
439 output = 'ToolItem "WSword"',
443 {'CraftItem "Stick"'},
447 minetest.register_craft({
448 output = 'ToolItem "STSword"',
450 {'NodeItem "cobble"'},
451 {'NodeItem "cobble"'},
452 {'CraftItem "Stick"'},
456 minetest.register_craft({
457 output = 'ToolItem "SteelSword"',
459 {'CraftItem "steel_ingot"'},
460 {'CraftItem "steel_ingot"'},
461 {'CraftItem "Stick"'},
465 minetest.register_craft({
466 output = 'NodeItem "rail" 15',
468 {'CraftItem "steel_ingot"', '', 'CraftItem "steel_ingot"'},
469 {'CraftItem "steel_ingot"', 'CraftItem "Stick"', 'CraftItem "steel_ingot"'},
470 {'CraftItem "steel_ingot"', '', 'CraftItem "steel_ingot"'},
474 minetest.register_craft({
475 output = 'NodeItem "chest" 1',
477 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
478 {'NodeItem "wood"', '', 'NodeItem "wood"'},
479 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
483 minetest.register_craft({
484 output = 'NodeItem "locked_chest" 1',
486 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
487 {'NodeItem "wood"', 'CraftItem "steel_ingot"', 'NodeItem "wood"'},
488 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
492 minetest.register_craft({
493 output = 'NodeItem "furnace" 1',
495 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
496 {'NodeItem "cobble"', '', 'NodeItem "cobble"'},
497 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
501 minetest.register_craft({
502 output = 'NodeItem "steelblock" 1',
504 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
505 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
506 {'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"', 'CraftItem "steel_ingot"'},
510 minetest.register_craft({
511 output = 'NodeItem "sandstone" 1',
513 {'NodeItem "sand"', 'NodeItem "sand"'},
514 {'NodeItem "sand"', 'NodeItem "sand"'},
518 minetest.register_craft({
519 output = 'NodeItem "clay" 1',
521 {'CraftItem "lump_of_clay"', 'CraftItem "lump_of_clay"'},
522 {'CraftItem "lump_of_clay"', 'CraftItem "lump_of_clay"'},
526 minetest.register_craft({
527 output = 'NodeItem "brick" 1',
529 {'CraftItem "clay_brick"', 'CraftItem "clay_brick"'},
530 {'CraftItem "clay_brick"', 'CraftItem "clay_brick"'},
534 minetest.register_craft({
535 output = 'CraftItem "paper" 1',
537 {'NodeItem "papyrus"', 'NodeItem "papyrus"', 'NodeItem "papyrus"'},
541 minetest.register_craft({
542 output = 'CraftItem "book" 1',
544 {'CraftItem "paper"'},
545 {'CraftItem "paper"'},
546 {'CraftItem "paper"'},
550 minetest.register_craft({
551 output = 'NodeItem "bookshelf" 1',
553 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
554 {'CraftItem "book"', 'CraftItem "book"', 'CraftItem "book"'},
555 {'NodeItem "wood"', 'NodeItem "wood"', 'NodeItem "wood"'},
559 minetest.register_craft({
560 output = 'NodeItem "ladder" 1',
562 {'CraftItem "Stick"', '', 'CraftItem "Stick"'},
563 {'CraftItem "Stick"', 'CraftItem "Stick"', 'CraftItem "Stick"'},
564 {'CraftItem "Stick"', '', 'CraftItem "Stick"'},
568 minetest.register_craft({
569 output = 'CraftItem "apple_iron" 1',
571 {'', 'CraftItem "steel_ingot"', ''},
572 {'CraftItem "steel_ingot"', 'CraftItem "apple"', 'CraftItem "steel_ingot"'},
573 {'', 'CraftItem "steel_ingot"', ''},
581 function digprop_constanttime(time)
583 diggability = "constant",
584 constant_time = time,
588 function digprop_stonelike(toughness)
590 diggablity = "normal",
591 weight = toughness * 5,
598 function digprop_dirtlike(toughness)
600 diggablity = "normal",
601 weight = toughness * 1.2,
608 function digprop_gravellike(toughness)
610 diggablity = "normal",
611 weight = toughness * 2,
618 function digprop_woodlike(toughness)
620 diggablity = "normal",
621 weight = toughness * 1.0,
628 function digprop_leaveslike(toughness)
630 diggablity = "normal",
631 weight = toughness * (-0.5),
638 function digprop_glasslike(toughness)
640 diggablity = "normal",
641 weight = toughness * 0.1,
648 function inventorycube(img1, img2, img3)
651 return "[inventorycube"
652 .. "{" .. img1:gsub("%^", "&")
653 .. "{" .. img2:gsub("%^", "&")
654 .. "{" .. img3:gsub("%^", "&")
659 minetest.register_node("stone", {
660 tile_images = {"stone.png"},
661 inventory_image = inventorycube("stone.png"),
662 paramtype = "mineral",
663 is_ground_content = true,
664 often_contains_mineral = true, -- Texture atlas hint
665 material = digprop_stonelike(1.0),
666 dug_item = 'NodeItem "cobble" 1',
669 minetest.register_node("dirt_with_grass", {
670 tile_images = {"grass.png", "mud.png", "mud.png^grass_side.png"},
671 inventory_image = inventorycube("mud.png^grass_side.png"),
672 is_ground_content = true,
673 material = digprop_dirtlike(1.0),
674 dug_item = 'NodeItem "dirt" 1',
677 minetest.register_node("dirt_with_grass_footsteps", {
678 tile_images = {"grass_footsteps.png", "mud.png", "mud.png^grass_side.png"},
679 inventory_image = "grass_footsteps.png",
680 is_ground_content = true,
681 material = digprop_dirtlike(1.0),
682 dug_item = 'NodeItem "dirt" 1',
685 minetest.register_node("dirt", {
686 tile_images = {"mud.png"},
687 inventory_image = inventorycube("mud.png"),
688 is_ground_content = true,
689 material = digprop_dirtlike(1.0),
692 minetest.register_node("sand", {
693 tile_images = {"sand.png"},
694 inventory_image = inventorycube("sand.png"),
695 is_ground_content = true,
696 material = digprop_dirtlike(1.0),
699 minetest.register_node("gravel", {
700 tile_images = {"gravel.png"},
701 inventory_image = inventorycube("gravel.png"),
702 is_ground_content = true,
703 material = digprop_gravellike(1.0),
706 minetest.register_node("sandstone", {
707 tile_images = {"sandstone.png"},
708 inventory_image = inventorycube("sandstone.png"),
709 is_ground_content = true,
710 material = digprop_dirtlike(1.0), -- FIXME should this be stonelike?
711 dug_item = 'NodeItem "sand" 1', -- FIXME is this intentional?
714 minetest.register_node("clay", {
715 tile_images = {"clay.png"},
716 inventory_image = inventorycube("clay.png"),
717 is_ground_content = true,
718 material = digprop_dirtlike(1.0),
719 dug_item = 'CraftItem "lump_of_clay" 4',
722 minetest.register_node("brick", {
723 tile_images = {"brick.png"},
724 inventory_image = inventorycube("brick.png"),
725 is_ground_content = true,
726 material = digprop_stonelike(1.0),
727 dug_item = 'CraftItem "clay_brick" 4',
730 minetest.register_node("tree", {
731 tile_images = {"tree_top.png", "tree_top.png", "tree.png"},
732 inventory_image = inventorycube("tree_top.png", "tree.png", "tree.png"),
733 is_ground_content = true,
734 material = digprop_woodlike(1.0),
735 cookresult_item = 'CraftItem "lump_of_coal" 1',
736 furnace_burntime = 30,
739 minetest.register_node("jungletree", {
740 tile_images = {"jungletree_top.png", "jungletree_top.png", "jungletree.png"},
741 inventory_image = inventorycube("jungletree_top.png", "jungletree.png", "jungletree.png"),
742 is_ground_content = true,
743 material = digprop_woodlike(1.0),
744 cookresult_item = 'CraftItem "lump_of_coal" 1',
745 furnace_burntime = 30,
748 minetest.register_node("junglegrass", {
749 drawtype = "plantlike",
751 tile_images = {"junglegrass.png"},
752 inventory_image = "junglegrass.png",
753 light_propagates = true,
756 material = digprop_leaveslike(1.0),
757 furnace_burntime = 2,
760 minetest.register_node("leaves", {
761 drawtype = "allfaces_optional",
763 tile_images = {"leaves.png"},
764 inventory_image = "leaves.png",
765 light_propagates = true,
767 material = digprop_leaveslike(1.0),
768 extra_dug_item = 'NodeItem "sapling" 1',
769 extra_dug_item_rarity = 20,
770 furnace_burntime = 1,
773 minetest.register_node("cactus", {
774 tile_images = {"cactus_top.png", "cactus_top.png", "cactus_side.png"},
775 inventory_image = inventorycube("cactus_top.png", "cactus_side.png", "cactus_side.png"),
776 is_ground_content = true,
777 material = digprop_woodlike(0.75),
778 furnace_burntime = 15,
781 minetest.register_node("papyrus", {
782 drawtype = "plantlike",
783 tile_images = {"papyrus.png"},
784 inventory_image = "papyrus.png",
785 light_propagates = true,
787 is_ground_content = true,
789 material = digprop_leaveslike(0.5),
790 furnace_burntime = 1,
793 minetest.register_node("bookshelf", {
794 tile_images = {"wood.png", "wood.png", "bookshelf.png"},
795 -- FIXME: inventorycube only cares for the first texture
796 --inventory_image = inventorycube("wood.png", "bookshelf.png", "bookshelf.png")
797 inventory_image = inventorycube("bookshelf.png"),
798 is_ground_content = true,
799 material = digprop_woodlike(0.75),
800 furnace_burntime = 30,
803 minetest.register_node("glass", {
804 drawtype = "glasslike",
805 tile_images = {"glass.png"},
806 inventory_image = inventorycube("glass.png"),
807 light_propagates = true,
809 sunlight_propagates = true,
810 is_ground_content = true,
811 material = digprop_glasslike(1.0),
814 minetest.register_node("wooden_fence", {
815 drawtype = "fencelike",
816 tile_images = {"wood.png"},
817 inventory_image = "fence.png",
818 light_propagates = true,
820 is_ground_content = true,
823 fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
825 furnace_burntime = 15,
826 material = digprop_woodlike(0.75),
829 minetest.register_node("rail", {
830 drawtype = "raillike",
831 tile_images = {"rail.png", "rail_curved.png", "rail_t_junction.png", "rail_crossing.png"},
832 inventory_image = "rail.png",
833 light_propagates = true,
835 is_ground_content = true,
841 material = digprop_dirtlike(0.75),
844 minetest.register_node("ladder", {
845 drawtype = "signlike",
846 tile_images = {"ladder.png"},
847 inventory_image = "ladder.png",
848 light_propagates = true,
850 is_ground_content = true,
855 type = "wallmounted",
856 --wall_top = = <default>
857 --wall_bottom = = <default>
858 --wall_side = = <default>
860 furnace_burntime = 5,
861 material = digprop_woodlike(0.5),
864 minetest.register_node("coalstone", {
865 tile_images = {"stone.png^mineral_coal.png"},
866 inventory_image = "stone.png^mineral_coal.png",
867 is_ground_content = true,
868 material = digprop_stonelike(1.5),
871 minetest.register_node("wood", {
872 tile_images = {"wood.png"},
873 inventory_image = inventorycube("wood.png"),
874 is_ground_content = true,
875 furnace_burntime = 7,
876 material = digprop_woodlike(0.75),
879 minetest.register_node("mese", {
880 tile_images = {"mese.png"},
881 inventory_image = inventorycube("mese.png"),
882 is_ground_content = true,
883 furnace_burntime = 30,
884 material = digprop_stonelike(0.5),
887 minetest.register_node("cloud", {
888 tile_images = {"cloud.png"},
889 inventory_image = inventorycube("cloud.png"),
890 is_ground_content = true,
893 minetest.register_node("water_flowing", {
894 drawtype = "flowingliquid",
895 tile_images = {"water.png"},
897 inventory_image = inventorycube("water.png"),
899 light_propagates = true,
904 liquidtype = "flowing",
905 liquid_alternative_flowing = "water_flowing",
906 liquid_alternative_source = "water_source",
907 liquid_viscosity = WATER_VISC,
908 post_effect_color = {a=64, r=100, g=100, b=200},
909 special_materials = {
910 {image="water.png", backface_culling=false},
911 {image="water.png", backface_culling=true},
915 minetest.register_node("water_source", {
917 tile_images = {"water.png"},
919 inventory_image = inventorycube("water.png"),
921 light_propagates = true,
926 liquidtype = "source",
927 liquid_alternative_flowing = "water_flowing",
928 liquid_alternative_source = "water_source",
929 liquid_viscosity = WATER_VISC,
930 post_effect_color = {a=64, r=100, g=100, b=200},
931 special_materials = {
932 -- New-style water source material (mostly unused)
933 {image="water.png", backface_culling=false},
937 minetest.register_node("lava_flowing", {
938 drawtype = "flowingliquid",
939 tile_images = {"lava.png"},
940 inventory_image = inventorycube("lava.png"),
942 light_propagates = false,
943 light_source = LIGHT_MAX - 1,
948 liquidtype = "flowing",
949 liquid_alternative_flowing = "lava_flowing",
950 liquid_alternative_source = "lava_source",
951 liquid_viscosity = LAVA_VISC,
952 damage_per_second = 4*2,
953 post_effect_color = {a=192, r=255, g=64, b=0},
954 special_materials = {
955 {image="lava.png", backface_culling=false},
956 {image="lava.png", backface_culling=true},
960 minetest.register_node("lava_source", {
962 tile_images = {"lava.png"},
963 inventory_image = inventorycube("lava.png"),
965 light_propagates = false,
966 light_source = LIGHT_MAX - 1,
971 liquidtype = "source",
972 liquid_alternative_flowing = "lava_flowing",
973 liquid_alternative_source = "lava_source",
974 liquid_viscosity = LAVA_VISC,
975 damage_per_second = 4*2,
976 post_effect_color = {a=192, r=255, g=64, b=0},
977 special_materials = {
978 -- New-style lava source material (mostly unused)
979 {image="lava.png", backface_culling=false},
981 furnace_burntime = 60,
984 minetest.register_node("torch", {
985 drawtype = "torchlike",
986 tile_images = {"torch_on_floor.png", "torch_on_ceiling.png", "torch.png"},
987 inventory_image = "torch_on_floor.png",
989 light_propagates = true,
990 sunlight_propagates = true,
993 light_source = LIGHT_MAX-1,
995 type = "wallmounted",
996 wall_top = {-0.1, 0.5-0.6, -0.1, 0.1, 0.5, 0.1},
997 wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
998 wall_side = {-0.5, -0.3, -0.1, -0.5+0.3, 0.3, 0.1},
1000 material = digprop_constanttime(0.0),
1001 furnace_burntime = 4,
1004 minetest.register_node("sign_wall", {
1005 drawtype = "signlike",
1006 tile_images = {"sign_wall.png"},
1007 inventory_image = "sign_wall.png",
1008 paramtype = "light",
1009 light_propagates = true,
1010 sunlight_propagates = true,
1012 wall_mounted = true,
1013 metadata_name = "sign",
1015 type = "wallmounted",
1016 --wall_top = <default>
1017 --wall_bottom = <default>
1018 --wall_side = <default>
1020 material = digprop_constanttime(0.5),
1021 furnace_burntime = 10,
1024 minetest.register_node("chest", {
1025 tile_images = {"chest_top.png", "chest_top.png", "chest_side.png",
1026 "chest_side.png", "chest_side.png", "chest_front.png"},
1027 inventory_image = "chest_top.png",
1028 --inventory_image = inventorycube("chest_top.png", "chest_side.png", "chest_front.png"),
1029 paramtype = "facedir_simple",
1030 metadata_name = "chest",
1031 material = digprop_woodlike(1.0),
1032 furnace_burntime = 30,
1035 minetest.register_node("locked_chest", {
1036 tile_images = {"chest_top.png", "chest_top.png", "chest_side.png",
1037 "chest_side.png", "chest_side.png", "chest_lock.png"},
1038 inventory_image = "chest_lock.png",
1039 paramtype = "facedir_simple",
1040 metadata_name = "locked_chest",
1041 material = digprop_woodlike(1.0),
1042 furnace_burntime = 30,
1045 minetest.register_node("furnace", {
1046 tile_images = {"furnace_side.png", "furnace_side.png", "furnace_side.png",
1047 "furnace_side.png", "furnace_side.png", "furnace_front.png"},
1048 inventory_image = "furnace_front.png",
1049 paramtype = "facedir_simple",
1050 metadata_name = "furnace",
1051 material = digprop_stonelike(3.0),
1054 minetest.register_node("cobble", {
1055 tile_images = {"cobble.png"},
1056 inventory_image = inventorycube("cobble.png"),
1057 is_ground_content = true,
1058 cookresult_item = 'NodeItem "stone" 1',
1059 material = digprop_stonelike(0.9),
1062 minetest.register_node("mossycobble", {
1063 tile_images = {"mossycobble.png"},
1064 inventory_image = inventorycube("mossycobble.png"),
1065 is_ground_content = true,
1066 material = digprop_stonelike(0.8),
1069 minetest.register_node("steelblock", {
1070 tile_images = {"steel_block.png"},
1071 inventory_image = inventorycube("steel_block.png"),
1072 is_ground_content = true,
1073 material = digprop_stonelike(5.0),
1076 minetest.register_node("nyancat", {
1077 tile_images = {"nc_side.png", "nc_side.png", "nc_side.png",
1078 "nc_side.png", "nc_back.png", "nc_front.png"},
1079 inventory_image = "nc_front.png",
1080 paramtype = "facedir_simple",
1081 material = digprop_stonelike(3.0),
1082 furnace_burntime = 1,
1085 minetest.register_node("nyancat_rainbow", {
1086 tile_images = {"nc_rb.png"},
1087 inventory_image = "nc_rb.png",
1088 material = digprop_stonelike(3.0),
1089 furnace_burntime = 1,
1092 minetest.register_node("sapling", {
1093 drawtype = "plantlike",
1095 tile_images = {"sapling.png"},
1096 inventory_image = "sapling.png",
1097 paramtype = "light",
1098 light_propagates = true,
1100 material = digprop_constanttime(0.0),
1101 furnace_burntime = 10,
1104 minetest.register_node("apple", {
1105 drawtype = "plantlike",
1107 tile_images = {"apple.png"},
1108 inventory_image = "apple.png",
1109 paramtype = "light",
1110 light_propagates = true,
1111 sunlight_propagates = true,
1113 dug_item = 'CraftItem "apple" 1',
1114 material = digprop_constanttime(0.0),
1115 furnace_burntime = 3,
1122 local craftitem_place_item = function(item, placer, pos)
1123 --print("craftitem_place_item")
1124 --print("item: " .. dump(item))
1125 --print("placer: " .. dump(placer))
1126 --print("pos: " .. dump(pos))
1127 minetest.env:add_item(pos, 'CraftItem "' .. item .. '" 1')
1131 local craftitem_eat = function(hp_change)
1132 return function(item, user, pointed_thing) -- closure
1133 --print("craftitem_eat(" .. hp_change .. ")")
1134 --print("item: " .. dump(item))
1135 --print("user: " .. dump(user))
1136 --print("pointed_thing: " .. dump(pointed_thing))
1137 user:set_hp(user:get_hp() + hp_change)
1142 minetest.register_craftitem("Stick", {
1143 image = "stick.png",
1144 --furnace_burntime = ...,
1145 on_place_on_ground = craftitem_place_item,
1148 minetest.register_craftitem("paper", {
1149 image = "paper.png",
1150 on_place_on_ground = craftitem_place_item,
1153 minetest.register_craftitem("book", {
1155 on_place_on_ground = craftitem_place_item,
1158 minetest.register_craftitem("lump_of_coal", {
1159 image = "lump_of_coal.png",
1160 furnace_burntime = 40;
1161 on_place_on_ground = craftitem_place_item,
1164 minetest.register_craftitem("lump_of_iron", {
1165 image = "lump_of_iron.png",
1166 cookresult_item = 'CraftItem "steel_ingot" 1',
1167 on_place_on_ground = craftitem_place_item,
1170 minetest.register_craftitem("lump_of_clay", {
1171 image = "lump_of_clay.png",
1172 cookresult_item = 'CraftItem "clay_brick" 1',
1173 on_place_on_ground = craftitem_place_item,
1176 minetest.register_craftitem("steel_ingot", {
1177 image = "steel_ingot.png",
1178 on_place_on_ground = craftitem_place_item,
1181 minetest.register_craftitem("clay_brick", {
1182 image = "clay_brick.png",
1183 on_place_on_ground = craftitem_place_item,
1186 minetest.register_craftitem("rat", {
1188 cookresult_item = 'CraftItem "cooked_rat" 1',
1189 on_drop = function(item, dropper, pos)
1190 minetest.env:add_rat(pos)
1195 minetest.register_craftitem("cooked_rat", {
1196 image = "cooked_rat.png",
1197 cookresult_item = 'CraftItem "scorched_stuff" 1',
1198 on_place_on_ground = craftitem_place_item,
1199 on_use = craftitem_eat(6),
1202 minetest.register_craftitem("scorched_stuff", {
1203 image = "scorched_stuff.png",
1204 on_place_on_ground = craftitem_place_item,
1207 minetest.register_craftitem("firefly", {
1208 image = "firefly.png",
1209 on_drop = function(item, dropper, pos)
1210 minetest.env:add_firefly(pos)
1215 minetest.register_craftitem("apple", {
1216 image = "apple.png",
1217 on_place_on_ground = craftitem_place_item,
1218 on_use = craftitem_eat(4),
1221 minetest.register_craftitem("apple_iron", {
1222 image = "apple_iron.png",
1223 on_place_on_ground = craftitem_place_item,
1224 on_use = craftitem_eat(8),
1227 print(dump(minetest.registered_craftitems))
1231 -- Some common functions
1234 function nodeupdate_single(p)
1235 n = minetest.env:get_node(p)
1236 if n.name == "sand" or n.name == "gravel" then
1237 p_bottom = {x=p.x, y=p.y-1, z=p.z}
1238 n_bottom = minetest.env:get_node(p_bottom)
1239 if n_bottom.name == "air" then
1240 minetest.env:remove_node(p)
1241 minetest.env:add_luaentity(p, "falling_"..n.name)
1247 function nodeupdate(p)
1251 p2 = {x=p.x+x, y=p.y+y, z=p.z+z}
1252 nodeupdate_single(p2)
1262 function register_falling_node(nodename, texture)
1263 minetest.register_entity("falling_"..nodename, {
1264 -- Static definition
1266 collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
1268 textures = {texture,texture,texture,texture,texture,texture},
1271 on_step = function(self, dtime)
1273 self.object:setacceleration({x=0, y=-10, z=0})
1274 -- Turn to actual sand when collides to ground or just move
1275 local pos = self.object:getpos()
1276 local bcp = {x=pos.x, y=pos.y-0.7, z=pos.z} -- Position of bottom center point
1277 local bcn = minetest.env:get_node(bcp)
1278 if bcn.name ~= "air" then
1279 -- Turn to a sand node
1280 local np = {x=bcp.x, y=bcp.y+1, z=bcp.z}
1281 minetest.env:add_node(np, {name=nodename})
1282 self.object:remove()
1290 register_falling_node("sand", "sand.png")
1291 register_falling_node("gravel", "gravel.png")
1297 -- Global environment step function
1298 function on_step(dtime)
1301 minetest.register_globalstep(on_step)
1303 function on_placenode(p, node)
1304 print("on_placenode")
1307 minetest.register_on_placenode(on_placenode)
1309 function on_dignode(p, node)
1313 minetest.register_on_dignode(on_dignode)
1315 function on_punchnode(p, node)
1316 print("on_punchnode")
1317 if node.name == "TNT" then
1318 minetest.env:remove_node(p)
1319 minetest.env:add_luaentity(p, "TNT")
1320 --minetest.env:add_luaentity(p, "testentity")
1321 --minetest.env:add_firefly(p)
1325 minetest.register_on_punchnode(on_punchnode)
1327 minetest.register_on_chat_message(function(name, message)
1328 print("default on_chat_message: name="..dump(name).." message="..dump(message))
1329 local cmd = "/giveme"
1330 if message:sub(0, #cmd) == cmd then
1331 if not minetest.get_player_privs(name)["give"] then
1332 minetest.chat_send_player(name, "you don't have permission to give")
1333 return true -- Handled chat message
1335 stackstring = string.match(message, cmd.." (.*)")
1336 if stackstring == nil then
1337 minetest.chat_send_player(name, 'usage: '..cmd..' stackstring')
1338 return true -- Handled chat message
1340 print(cmd..' invoked, stackstring="'..stackstring..'"')
1341 player = minetest.env:get_player_by_name(name)
1342 added, error_msg = player:add_to_inventory(stackstring)
1344 minetest.chat_send_player(name, '"'..stackstring
1345 ..'" added to inventory.');
1347 minetest.chat_send_player(name, 'Could not give "'..stackstring
1348 ..'": '..error_msg);
1350 return true -- Handled chat message
1353 if message:sub(0, #cmd) == cmd then
1354 print("minetest.get_player_privs(name)="
1355 ..dump(minetest.get_player_privs(name)))
1356 if not minetest.get_player_privs(name)["give"] then
1357 minetest.chat_send_player(name, "you don't have permission to give")
1358 return true -- Handled chat message
1360 name2, stackstring = string.match(message, cmd.." ([%a%d_-]+) (.*)")
1361 if name == nil or stackstring == nil then
1362 minetest.chat_send_player(name, 'usage: '..cmd..' name stackstring')
1363 return true -- Handled chat message
1365 print(cmd..' invoked, name2="'..name2
1366 ..'" stackstring="'..stackstring..'"')
1367 player = minetest.env:get_player_by_name(name2)
1368 if player == nil then
1369 minetest.chat_send_player(name, name2..' is not a known player')
1370 return true -- Handled chat message
1372 added, error_msg = player:add_to_inventory(stackstring)
1374 minetest.chat_send_player(name, '"'..stackstring
1375 ..'" added to '..name2..'\'s inventory.');
1376 minetest.chat_send_player(name2, '"'..stackstring
1377 ..'" added to inventory.');
1379 minetest.chat_send_player(name, 'Could not give "'..stackstring
1380 ..'": '..error_msg);
1382 return true -- Handled chat message
1387 -- Done, print some random stuff
1390 --print("minetest.registered_entities:")
1391 --dump2(minetest.registered_entities)