Define all node names explicitly
[minetest_colorcubes.git] / init.lua
blob13a0e871de2b06a9fc745b84a9d22f3de3ce0075
1 local cc = {}
2 cc.colors = { "white", "yellow", "orange", "red", "redviolet", "magenta", "violet", "blue", "skyblue", "cyan", "aqua", "green", "lime", "pink", "brown", "dark_green", "light_gray", "dark_gray", "black" }
3 cc.dye_colors = {
4 white = "unicolor_white", yellow = "unicolor_yellow", orange = "unicolor_orange", red = "unicolor_red", redviolet = "unicolor_red_violet", magenta = "unicolor_magenta", violet = "unicolor_violet", blue = "unicolor_blue", skyblue = "unicolor_sky_blue", cyan = "unicolor_cyan", aqua = "unicolor_aqua", green = "unicolor_green", lime = "unicolor_lime", pink = "unicolor_light_red", brown = "unicolor_dark_orange", dark_green = "unicolor_dark_green", light_gray = "unicolor_grey", dark_gray = "unicolor_darkgrey", black = "unicolor_black" }
5 cc.human_colors = {
6 single = {
7 white = "White basic color cube",
8 yellow = "Yellow basic color cube",
9 orange = "Orange basic color cube",
10 red = "Red basic color cube",
11 redviolet = "Red-violet basic color cube",
12 magenta = "Magenta basic color cube",
13 violet = "Violet basic color cube",
14 blue = "Blue basic color cube",
15 skyblue = "Skyblue basic color cube",
16 cyan = "Cyan basic color cube",
17 aqua = "Aqua basic color cube",
18 green = "Green basic color cube",
19 lime = "Lime basic color cube",
20 pink = "Pink basic color cube",
21 brown = "Brown basic color cube",
22 dark_green = "Dark green basic color cube",
23 light_gray = "Light gray basic color cube",
24 dark_gray = "Dark gray basic color cube",
25 black = "Black basic color cube",
27 window = {
28 white = "White window color cube",
29 yellow = "Yellow window color cube",
30 orange = "Orange window color cube",
31 red = "Red window color cube",
32 redviolet = "Red-violet window color cube",
33 magenta = "Magenta window color cube",
34 violet = "Violet window color cube",
35 blue = "Blue window color cube",
36 skyblue = "Skyblue window color cube",
37 cyan = "Cyan window color cube",
38 aqua = "Aqua window color cube",
39 green = "Green window color cube",
40 lime = "Lime window color cube",
41 pink = "Pink window color cube",
42 brown = "Brown window color cube",
43 dark_green = "Dark green window color cube",
44 light_gray = "Light gray window color cube",
45 dark_gray = "Dark gray window color cube",
46 black = "Black window color cube",
48 tiled = {
49 white = "White tiled color cube",
50 yellow = "Yellow tiled color cube",
51 orange = "Orange tiled color cube",
52 red = "Red tiled color cube",
53 redviolet = "Red-violet tiled color cube",
54 magenta = "Magenta tiled color cube",
55 violet = "Violet tiled color cube",
56 blue = "Blue tiled color cube",
57 skyblue = "Skyblue tiled color cube",
58 cyan = "Cyan tiled color cube",
59 aqua = "Aqua tiled color cube",
60 green = "Green tiled color cube",
61 lime = "Lime tiled color cube",
62 pink = "Pink tiled color cube",
63 brown = "Brown tiled color cube",
64 dark_green = "Dark green tiled color cube",
65 light_gray = "Light gray tiled color cube",
66 dark_gray = "Dark gray tiled color cube",
67 black = "Black tiled color cube",
69 inward = {
70 white = "White concentric color cube",
71 yellow = "Yellow concentric color cube",
72 orange = "Orange concentric color cube",
73 red = "Red concentric color cube",
74 redviolet = "Red-violet concentric color cube",
75 magenta = "Magenta concentric color cube",
76 violet = "Violet concentric color cube",
77 blue = "Blue concentric color cube",
78 skyblue = "Skyblue concentric color cube",
79 cyan = "Cyan concentric color cube",
80 aqua = "Aqua concentric color cube",
81 green = "Green concentric color cube",
82 lime = "Lime concentric color cube",
83 pink = "Pink concentric color cube",
84 brown = "Brown concentric color cube",
85 dark_green = "Dark green concentric color cube",
86 light_gray = "Light gray concentric color cube",
87 dark_gray = "Dark gray concentric color cube",
88 black = "Black concentric color cube",
90 light = {
91 white = "White light color cube",
92 yellow = "Yellow light color cube",
93 orange = "Orange light color cube",
94 red = "Red light color cube",
95 redviolet = "Red-violet light color cube",
96 magenta = "Magenta light color cube",
97 violet = "Violet light color cube",
98 blue = "Blue light color cube",
99 skyblue = "Skyblue light color cube",
100 cyan = "Cyan light color cube",
101 aqua = "Aqua light color cube",
102 green = "Green light color cube",
103 lime = "Lime light color cube",
108 local light_level = 14
110 local soundmaker = function (mod)
111 if mod == nil then mod = 0 end
113 local scrub = function(value)
114 return math.min(1, math.max(value, 0))
117 return { footstep = { name = "colorcubes_block_footstep", gain = scrub(0.25 + mod) },
118 dig = { name = "colorcubes_block_dig", gain = scrub(1) },
119 dug = { name = "colorcubes_block_dug", gain = scrub(0.7 + mod) },
120 place = { name = "colorcubes_block_place", gain = 0.5 }, }
123 --[[
124 Color Cubes groups for better identification:
125 colorcube=1: this item is a color cube
126 colorcube_single=1: basic color cube
127 colorcube_window=1: window color cube
128 colorcube_tiled=1: tiled color cube (1 color)
129 colorcube_tiled=2: tiled color cube (2 colors)
130 colorcube_inward=1: concentric color cube
131 colorcube_light=1: light color cube
134 for i=1,#cc.colors do
135 local c = cc.colors[i]
136 local d = cc.dye_colors[c]
137 -- Blocks with a simple square pattern
138 local nodedef1 = {
139 description = cc.human_colors.single[c],
140 tiles = { "colorcubes_1_"..c..".png" },
141 groups = { dig_immediate = 2, colorcube = 1, colorcube_single = 1 },
142 sounds = soundmaker(0),
144 minetest.register_node("colorcubes:"..c.."_single", nodedef1)
145 -- Windows
146 local nodedef_window = {
147 description = cc.human_colors.window[c],
148 tiles = { "colorcubes_window_"..c..".png" },
149 inventory_image = minetest.inventorycube("colorcubes_window_"..c..".png"),
150 groups = { dig_immediate = 2, colorcube = 1, colorcube_window = 1 },
151 use_texture_alpha = true,
152 drawtype = "glasslike",
153 sunlight_propagates = true,
154 paramtype = "light",
155 sounds = soundmaker(-0.1),
157 minetest.register_node("colorcubes:"..c.."_window", nodedef_window)
158 -- Blocks with a tile pattern (4 tiles)
159 local nodedef4 = {
160 description = cc.human_colors.tiled[c],
161 tiles = { "colorcubes_4_"..c..".png" },
162 groups = { dig_immediate = 2, colorcube = 1, colorcube_tiled = 1 },
163 sounds = soundmaker(0.1),
165 minetest.register_node("colorcubes:"..c.."_tiled", nodedef4)
166 -- Blocks with a concentric square pattern
167 local nodedef_inward = {
168 description = cc.human_colors.inward[c],
169 tiles = { "colorcubes_inward_"..c..".png" },
170 groups = { dig_immediate = 2, colorcube = 1, colorcube_inward = 1},
171 sounds = soundmaker(0.15),
173 minetest.register_node("colorcubes:"..c.."_inward", nodedef_inward)
174 -- Lamps in different brightness levels
175 if light_level > 1 then
176 local nodedef_light = {
177 description = cc.human_colors.light[c],
178 tiles = { "colorcubes_light_"..c..".png" },
179 groups = { dig_immediate = 2, colorcube = 1, colorcube_light = 1 },
180 sounds = soundmaker(-0.05),
181 light_source = light_level,
183 minetest.register_node("colorcubes:"..c.."_light", nodedef_light)
184 if(minetest.get_modpath("paint_roller") ~= nil) then
185 paint_roller.register_one("colorcubes:"..c.."_light", d, "light color cubes" )
187 light_level = light_level - 1
190 --[[ If the paint_roller mod is installed, register the nodes to it ]]
191 if(minetest.get_modpath("paint_roller") ~= nil) then
192 paint_roller.register_one("colorcubes:"..c.."_single", d, "basic color cubes" )
193 paint_roller.register_one("colorcubes:"..c.."_tiled", d, "tiled color cubes" )
194 paint_roller.register_one("colorcubes:"..c.."_inward", d, "concentric color cubes" )
195 paint_roller.register_one("colorcubes:"..c.."_window", d, "window color cubes" )
198 -- Register various crafting recipes for convenience
199 minetest.register_craft({
200 output = "colorcubes:"..c.."_tiled",
201 recipe = {
202 {"colorcubes:"..c.."_single", "colorcubes:"..c.."_single" },
203 {"colorcubes:"..c.."_single", "colorcubes:"..c.."_single" },
206 minetest.register_craft({
207 output = "colorcubes:"..c.."_inward",
208 recipe = {
209 {"colorcubes:"..c.."_single", "colorcubes:"..c.."_single", "colorcubes:"..c.."_single" },
210 {"colorcubes:"..c.."_single", "", "colorcubes:"..c.."_single" },
211 {"colorcubes:"..c.."_single", "colorcubes:"..c.."_single", "colorcubes:"..c.."_single" },
214 minetest.register_craft({
215 output = "colorcubes:"..c.."_single 8",
216 recipe = {
217 {"colorcubes:"..c.."_inward" }
220 minetest.register_craft({
221 output = "colorcubes:"..c.."_single 4",
222 recipe = {
223 {"colorcubes:"..c.."_tiled" }
227 -- Color recipes (dye + color cube)
228 minetest.register_craft({
229 type = "shapeless",
230 output = "colorcubes:"..c.."_single",
231 recipe = { "group:dye,"..d, "group:colorcube_single" },
233 minetest.register_craft({
234 type = "shapeless",
235 output = "colorcubes:"..c.."_tiled",
236 recipe = { "group:dye,"..d, "group:colorcube_tiled" },
238 minetest.register_craft({
239 type = "shapeless",
240 output = "colorcubes:"..c.."_inward",
241 recipe = { "group:dye,"..d, "group:colorcube_inward" },
243 minetest.register_craft({
244 type = "shapeless",
245 output = "colorcubes:"..c.."_light",
246 recipe = { "group:dye,"..d, "group:colorcube_light" },
248 minetest.register_craft({
249 type = "shapeless",
250 output = "colorcubes:"..c.."_window",
251 recipe = { "group:dye,"..d, "group:colorcube_window" },
256 --[[ Tiled blocks with 2 different colors (usuall complementary colors) ]]
258 local complementary = { { "yellow", "blue"}, {"aqua", "redviolet"}, {"red", "cyan"}, {"light_gray", "dark_gray"}, {"green", "magenta"}, {"orange", "skyblue"}, {"lime", "violet"}, {"black", "white"}, {"orange", "brown"} }
259 local complementary_names = { "Yellow/blue tiled color cube", "Aqua/red-violet tiled color cube", "Red/cyan tiled color cube", "Light/dark gray tiled color cube", "Green/magenta tiled color cube", "Orange/skyblue tiled color cube", "Lime/violet tiled color cube", "Black/white tiled color cube", "Orange/brown tiled color cube" }
261 for i=1,#complementary do
262 local c1, c2
263 c1 = complementary[i][1]
264 c2 = complementary[i][2]
265 local nodeid = "colorcubes:"..c1.."_"..c2.."_tiled"
266 local tex = "colorcubes_4c_"..c1.."_"..c2..".png"
267 local texR90 = tex .. "^[transformR90"
268 minetest.register_node(nodeid, {
269 description = complementary_names[i],
270 tiles = { tex, tex, tex, tex, texR90, texR90 },
271 groups = { dig_immediate = 2, colorcube = 1, colorcube_tiled = 2 },
272 sounds = soundmaker(0.1),
275 minetest.register_craft({
276 output = nodeid,
277 recipe = {
278 {"colorcubes:"..c1.."_single", "colorcubes:"..c2.."_single" },
279 {"colorcubes:"..c2.."_single", "colorcubes:"..c1.."_single" },
282 minetest.register_craft({
283 output = nodeid,
284 recipe = {
285 {"colorcubes:"..c2.."_single", "colorcubes:"..c1.."_single" },
286 {"colorcubes:"..c1.."_single", "colorcubes:"..c2.."_single" },
290 --[[ This register the block to the paint roller mod. Note that this block can
291 only be painted, but it can not be reversed; it will not be possible to paint a
292 tiled block so that it becomes a 2-color block. Thus, we use minor hack by using
293 a fake dye group called “none” to make sure there is no dye to turn a tiled block
294 into a 2-color tiled block. ]]
295 if(minetest.get_modpath("paint_roller") ~= nil) then
296 paint_roller.register_one(nodeid, "none", "tiled color cubes" )