Make node definitions available to Lua
[oweals/minetest.git] / data / builtin.lua
1 function basic_dump2(o)
2         if type(o) == "number" then
3                 return tostring(o)
4         elseif type(o) == "string" then
5                 return string.format("%q", o)
6         elseif type(o) == "boolean" then
7                 return tostring(o)
8         elseif type(o) == "function" then
9                 return "<function>"
10         elseif type(o) == "userdata" then
11                 return "<userdata>"
12         elseif type(o) == "nil" then
13                 return "nil"
14         else
15                 error("cannot dump a " .. type(o))
16                 return nil
17         end
18 end
19
20 function dump2(o, name, dumped)
21         name = name or "_"
22         dumped = dumped or {}
23         io.write(name, " = ")
24         if type(o) == "number" or type(o) == "string" or type(o) == "boolean"
25                         or type(o) == "function" or type(o) == "nil"
26                         or type(o) == "userdata" then
27                 io.write(basic_dump2(o), "\n")
28         elseif type(o) == "table" then
29                 if dumped[o] then
30                         io.write(dumped[o], "\n")
31                 else
32                         dumped[o] = name
33                         io.write("{}\n") -- new table
34                         for k,v in pairs(o) do
35                                 local fieldname = string.format("%s[%s]", name, basic_dump2(k))
36                                 dump2(v, fieldname, dumped)
37                         end
38                 end
39         else
40                 error("cannot dump a " .. type(o))
41                 return nil
42         end
43 end
44
45 function dump(o, dumped)
46         dumped = dumped or {}
47         if type(o) == "number" then
48                 return tostring(o)
49         elseif type(o) == "string" then
50                 return string.format("%q", o)
51         elseif type(o) == "table" then
52                 if dumped[o] then
53                         return "<circular reference>"
54                 end
55                 dumped[o] = true
56                 local t = {}
57                 for k,v in pairs(o) do
58                         t[#t+1] = "" .. k .. " = " .. dump(v, dumped)
59                 end
60                 return "{" .. table.concat(t, ", ") .. "}"
61         elseif type(o) == "boolean" then
62                 return tostring(o)
63         elseif type(o) == "function" then
64                 return "<function>"
65         elseif type(o) == "userdata" then
66                 return "<userdata>"
67         elseif type(o) == "nil" then
68                 return "nil"
69         else
70                 error("cannot dump a " .. type(o))
71                 return nil
72         end
73 end
74
75 --
76 -- Built-in node definitions. Also defined in C.
77 --
78
79 minetest.register_nodedef_defaults({
80         -- name intentionally not defined here
81         drawtype = "normal",
82         visual_scale = 1.0,
83         tile_images = {"unknown_block.png"},
84         inventory_image = "unknown_block.png",
85         special_materials = {
86                 {image="", backface_culling=true},
87                 {image="", backface_culling=true},
88         },
89         alpha = 255,
90         post_effect_color = {a=0, r=0, g=0, b=0},
91         paramtype = "none",
92         is_ground_content = false,
93         light_propagates = false,
94         sunlight_propagates = false,
95         walkable = true,
96         pointable = true,
97         diggable = true,
98         climbable = false,
99         buildable_to = false,
100         wall_mounted = false,
101         often_contains_mineral = false,
102         dug_item = "",
103         extra_dug_item = "",
104         extra_dug_item_rarity = 2,
105         metadata_name = "",
106         liquid_type = "none",
107         liquid_alternative_flowing = "",
108         liquid_alternative_source = "",
109         liquid_viscosity = 0,
110         light_source = 0,
111         damage_per_second = 0,
112         selection_box = {type="regular"},
113         material = {
114                 diggablity = "normal",
115                 weight = 0,
116                 crackiness = 0,
117                 crumbliness = 0,
118                 cuttability = 0,
119                 flammability = 0,
120         },
121         cookresult_item = "", -- Cannot be cooked
122         furnace_cooktime = 3.0,
123         furnace_burntime = -1, -- Cannot be used as fuel
124 })
125
126 minetest.register_node("air", {
127         drawtype = "airlike",
128         paramtype = "light",
129         light_propagates = true,
130         sunlight_propagates = true,
131         walkable = false,
132         pointable = false,
133         diggable = false,
134         buildable_to = true,
135         air_equivalent = true,
136 })
137
138 minetest.register_node("ignore", {
139         drawtype = "airlike",
140         paramtype = "none",
141         light_propagates = false,
142         sunlight_propagates = false,
143         walkable = false,
144         pointable = false,
145         diggable = false,
146         buildable_to = true, -- A way to remove accidentally placed ignores
147         air_equivalent = true,
148 })
149