Change license to MIT License
[minetest_colorcubes.git] / init.lua
blob3c26f96fdf59e7397101f8cd97aca297a476d9f1
1 local S = minetest.get_translator("colorcubes")
3 local cc = {}
4 cc.colors = { "white", "yellow", "orange", "red", "redviolet", "magenta", "violet", "blue", "skyblue", "cyan", "aqua", "green", "lime", "pink", "brown", "dark_green", "light_gray", "dark_gray", "black" }
5 cc.dye_colors = {
6 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" }
7 cc.human_colors = {
8 single = {
9 white = S("White basic color cube"),
10 yellow = S("Yellow basic color cube"),
11 orange = S("Orange basic color cube"),
12 red = S("Red basic color cube"),
13 redviolet = S("Red-violet basic color cube"),
14 magenta = S("Magenta basic color cube"),
15 violet = S("Violet basic color cube"),
16 blue = S("Blue basic color cube"),
17 skyblue = S("Skyblue basic color cube"),
18 cyan = S("Cyan basic color cube"),
19 aqua = S("Aqua basic color cube"),
20 green = S("Green basic color cube"),
21 lime = S("Lime basic color cube"),
22 pink = S("Pink basic color cube"),
23 brown = S("Brown basic color cube"),
24 dark_green = S("Dark green basic color cube"),
25 light_gray = S("Light gray basic color cube"),
26 dark_gray = S("Dark gray basic color cube"),
27 black = S("Black basic color cube"),
29 window = {
30 white = S("White window color cube"),
31 yellow = S("Yellow window color cube"),
32 orange = S("Orange window color cube"),
33 red = S("Red window color cube"),
34 redviolet = S("Red-violet window color cube"),
35 magenta = S("Magenta window color cube"),
36 violet = S("Violet window color cube"),
37 blue = S("Blue window color cube"),
38 skyblue = S("Skyblue window color cube"),
39 cyan = S("Cyan window color cube"),
40 aqua = S("Aqua window color cube"),
41 green = S("Green window color cube"),
42 lime = S("Lime window color cube"),
43 pink = S("Pink window color cube"),
44 brown = S("Brown window color cube"),
45 dark_green = S("Dark green window color cube"),
46 light_gray = S("Light gray window color cube"),
47 dark_gray = S("Dark gray window color cube"),
48 black = S("Black window color cube"),
50 tiled = {
51 white = S("White tiled color cube"),
52 yellow = S("Yellow tiled color cube"),
53 orange = S("Orange tiled color cube"),
54 red = S("Red tiled color cube"),
55 redviolet = S("Red-violet tiled color cube"),
56 magenta = S("Magenta tiled color cube"),
57 violet = S("Violet tiled color cube"),
58 blue = S("Blue tiled color cube"),
59 skyblue = S("Skyblue tiled color cube"),
60 cyan = S("Cyan tiled color cube"),
61 aqua = S("Aqua tiled color cube"),
62 green = S("Green tiled color cube"),
63 lime = S("Lime tiled color cube"),
64 pink = S("Pink tiled color cube"),
65 brown = S("Brown tiled color cube"),
66 dark_green = S("Dark green tiled color cube"),
67 light_gray = S("Light gray tiled color cube"),
68 dark_gray = S("Dark gray tiled color cube"),
69 black = S("Black tiled color cube"),
71 inward = {
72 white = S("White concentric color cube"),
73 yellow = S("Yellow concentric color cube"),
74 orange = S("Orange concentric color cube"),
75 red = S("Red concentric color cube"),
76 redviolet = S("Red-violet concentric color cube"),
77 magenta = S("Magenta concentric color cube"),
78 violet = S("Violet concentric color cube"),
79 blue = S("Blue concentric color cube"),
80 skyblue = S("Skyblue concentric color cube"),
81 cyan = S("Cyan concentric color cube"),
82 aqua = S("Aqua concentric color cube"),
83 green = S("Green concentric color cube"),
84 lime = S("Lime concentric color cube"),
85 pink = S("Pink concentric color cube"),
86 brown = S("Brown concentric color cube"),
87 dark_green = S("Dark green concentric color cube"),
88 light_gray = S("Light gray concentric color cube"),
89 dark_gray = S("Dark gray concentric color cube"),
90 black = S("Black concentric color cube"),
92 light = {
93 white = S("White light color cube"),
94 yellow = S("Yellow light color cube"),
95 orange = S("Orange light color cube"),
96 red = S("Red light color cube"),
97 redviolet = S("Red-violet light color cube"),
98 magenta = S("Magenta light color cube"),
99 violet = S("Violet light color cube"),
100 blue = S("Blue light color cube"),
101 skyblue = S("Skyblue light color cube"),
102 cyan = S("Cyan light color cube"),
103 aqua = S("Aqua light color cube"),
104 green = S("Green light color cube"),
105 lime = S("Lime light color cube"),
109 local light_level = 14
111 local soundmaker = function (mod)
112 if mod == nil then mod = 0 end
114 local scrub = function(value)
115 return math.min(1, math.max(value, 0))
118 return { footstep = { name = "colorcubes_block_footstep", gain = scrub(0.25 + mod) },
119 dig = { name = "colorcubes_block_dig", gain = scrub(1) },
120 dug = { name = "colorcubes_block_dug", gain = scrub(0.7 + mod) },
121 place = { name = "colorcubes_block_place", gain = 0.5 }, }
124 --[[
125 Color Cubes groups for better identification:
126 colorcube=1: this item is a color cube
127 colorcube_single=1: basic color cube
128 colorcube_window=1: window color cube
129 colorcube_tiled=1: tiled color cube (1 color)
130 colorcube_tiled=2: tiled color cube (2 colors)
131 colorcube_inward=1: concentric color cube
132 colorcube_light=1: light color cube
135 for i=1,#cc.colors do
136 local c = cc.colors[i]
137 local d = cc.dye_colors[c]
138 -- Blocks with a simple square pattern
139 local nodedef1 = {
140 description = cc.human_colors.single[c],
141 tiles = { "colorcubes_1_"..c..".png" },
142 groups = { dig_immediate = 2, colorcube = 1, colorcube_single = 1 },
143 sounds = soundmaker(0),
145 minetest.register_node("colorcubes:"..c.."_single", nodedef1)
146 -- Windows
147 local nodedef_window = {
148 description = cc.human_colors.window[c],
149 tiles = { "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 = {
260 S("Yellow/blue tiled color cube"),
261 S("Aqua/red-violet tiled color cube"),
262 S("Red/cyan tiled color cube"),
263 S("Light/dark gray tiled color cube"),
264 S("Green/magenta tiled color cube"),
265 S("Orange/skyblue tiled color cube"),
266 S("Lime/violet tiled color cube"),
267 S("Black/white tiled color cube"),
268 S("Orange/brown tiled color cube"),
271 for i=1,#complementary do
272 local c1, c2
273 c1 = complementary[i][1]
274 c2 = complementary[i][2]
275 local nodeid = "colorcubes:"..c1.."_"..c2.."_tiled"
276 local tex = "colorcubes_4c_"..c1.."_"..c2..".png"
277 local texR90 = tex .. "^[transformR90"
278 minetest.register_node(nodeid, {
279 description = complementary_names[i],
280 tiles = { tex, tex, tex, tex, texR90, texR90 },
281 groups = { dig_immediate = 2, colorcube = 1, colorcube_tiled = 2 },
282 sounds = soundmaker(0.1),
285 minetest.register_craft({
286 output = nodeid,
287 recipe = {
288 {"colorcubes:"..c1.."_single", "colorcubes:"..c2.."_single" },
289 {"colorcubes:"..c2.."_single", "colorcubes:"..c1.."_single" },
292 minetest.register_craft({
293 output = nodeid,
294 recipe = {
295 {"colorcubes:"..c2.."_single", "colorcubes:"..c1.."_single" },
296 {"colorcubes:"..c1.."_single", "colorcubes:"..c2.."_single" },
300 --[[ This register the block to the paint roller mod. Note that this block can
301 only be painted, but it can not be reversed; it will not be possible to paint a
302 tiled block so that it becomes a 2-color block. Thus, we use minor hack by using
303 a fake dye group called “none” to make sure there is no dye to turn a tiled block
304 into a 2-color tiled block. ]]
305 if(minetest.get_modpath("paint_roller") ~= nil) then
306 paint_roller.register_one(nodeid, "none", "tiled color cubes" )