Add all nodes to new colorcube group
[minetest_colorcubes.git] / init.lua
blob413f4becc67d7b98f818c1109e1bab1f1b9abdd4
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 = { white = "white", yellow = "yellow", orange = "orange", red = "red", redviolet = "red-violet", magenta = "magenta", violet = "violet", blue = "blue", skyblue = "skyblue", cyan = "cyan", aqua = "aqua", green = "green", lime = "lime", pink = "pink", brown = "brown", dark_green = "dark green", light_gray = "light gray", dark_gray = "dark gray", black = "black" }
7 local light_level = 14
9 local soundmaker = function (mod)
10 if mod == nil then mod = 0 end
12 local scrub = function(value)
13 return math.min(1, math.max(value, 0))
14 end
16 return { footstep = { name = "colorcubes_block_footstep", gain = scrub(0.25 + mod) },
17 dig = { name = "colorcubes_block_dig", gain = scrub(1) },
18 dug = { name = "colorcubes_block_dug", gain = scrub(0.7 + mod) },
19 place = { name = "colorcubes_block_place", gain = 0.5 }, }
20 end
22 --[[
23 Color Cubes groups for better identification:
24 colorcube~=0: this item is a color cube
25 colorcube=1: basic
26 colorcube=2: window
27 colorcube=3: tile
28 colorcube=4: concentric
29 colorcube=5: light
32 for i=1,#cc.colors do
33 local c = cc.colors[i]
34 local h = cc.human_colors[c]
35 local d = cc.dye_colors[c]
36 -- Blocks with a simple square pattern
37 local nodedef1 = {
38 description = h.." basic color cube",
39 tiles = { "colorcubes_1_"..c..".png" },
40 groups = { dig_immediate = 2, colorcube = 1 },
41 sounds = soundmaker(0),
43 minetest.register_node("colorcubes:"..c.."_single", nodedef1)
44 -- Windows
45 local nodedef_window = {
46 description = h.." window color cube",
47 tiles = { "colorcubes_window_"..c..".png" },
48 inventory_image = minetest.inventorycube("colorcubes_window_"..c..".png"),
49 groups = { dig_immediate = 2, colorcube = 2 },
50 use_texture_alpha = true,
51 drawtype = "glasslike",
52 sunlight_propagates = true,
53 paramtype = "light",
54 sounds = soundmaker(-0.1),
56 minetest.register_node("colorcubes:"..c.."_window", nodedef_window)
57 -- Blocks with a tile pattern (4 tiles)
58 local nodedef4 = {
59 description = h.." tiled color cube",
60 tiles = { "colorcubes_4_"..c..".png" },
61 groups = { dig_immediate = 2, colorcube = 3 },
62 sounds = soundmaker(0.1),
64 minetest.register_node("colorcubes:"..c.."_tiled", nodedef4)
65 -- Blocks with a concentric square pattern
66 local nodedef_inward = {
67 description = h.." concentric color cube",
68 tiles = { "colorcubes_inward_"..c..".png" },
69 groups = { dig_immediate = 2, colorcube = 4 },
70 sounds = soundmaker(0.15),
72 minetest.register_node("colorcubes:"..c.."_inward", nodedef_inward)
73 -- Lamps in different brightness levels
74 if light_level > 1 then
75 local nodedef_light = {
76 description = h.." light color cube",
77 tiles = { "colorcubes_light_"..c..".png" },
78 groups = { dig_immediate = 2, colorcube = 5 },
79 sounds = soundmaker(-0.05),
80 light_source = light_level,
82 minetest.register_node("colorcubes:"..c.."_light", nodedef_light)
83 if(minetest.get_modpath("paint_roller") ~= nil) then
84 paint_roller.register_one("colorcubes:"..c.."_light", d, "light color cubes" )
85 end
86 light_level = light_level - 1
87 end
89 --[[ If the paint_roller mod is installed, register the nodes to it ]]
90 if(minetest.get_modpath("paint_roller") ~= nil) then
91 paint_roller.register_one("colorcubes:"..c.."_single", d, "basic color cubes" )
92 paint_roller.register_one("colorcubes:"..c.."_tiled", d, "tiled color cubes" )
93 paint_roller.register_one("colorcubes:"..c.."_inward", d, "concentric color cubes" )
94 paint_roller.register_one("colorcubes:"..c.."_window", d, "window color cubes" )
95 end
97 -- Register various crafting recipes for convenience
98 minetest.register_craft({
99 output = "colorcubes:"..c.."_tiled",
100 recipe = {
101 {"colorcubes:"..c.."_single", "colorcubes:"..c.."_single" },
102 {"colorcubes:"..c.."_single", "colorcubes:"..c.."_single" },
105 minetest.register_craft({
106 output = "colorcubes:"..c.."_inward",
107 recipe = {
108 {"colorcubes:"..c.."_single", "colorcubes:"..c.."_single", "colorcubes:"..c.."_single" },
109 {"colorcubes:"..c.."_single", "", "colorcubes:"..c.."_single" },
110 {"colorcubes:"..c.."_single", "colorcubes:"..c.."_single", "colorcubes:"..c.."_single" },
113 minetest.register_craft({
114 output = "colorcubes:"..c.."_single 8",
115 recipe = {
116 {"colorcubes:"..c.."_inward" }
119 minetest.register_craft({
120 output = "colorcubes:"..c.."_single 4",
121 recipe = {
122 {"colorcubes:"..c.."_tiled" }
128 --[[ Tiled blocks with 2 differend colors (usuall complementary colors) ]]
130 local complementary = { { "yellow", "blue"}, {"aqua", "redviolet"}, {"red", "cyan"}, {"light_gray", "dark_gray"}, {"green", "magenta"}, {"orange", "skyblue"}, {"lime", "violet"}, {"black", "white"}, {"orange", "brown"} }
131 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" }
133 for i=1,#complementary do
134 local c1, c2
135 c1 = complementary[i][1]
136 c2 = complementary[i][2]
137 local nodeid = "colorcubes:"..c1.."_"..c2.."_tiled"
138 local tex = "colorcubes_4c_"..c1.."_"..c2..".png"
139 local texR90 = tex .. "^[transformR90"
140 minetest.register_node(nodeid, {
141 description = complementary_names[i],
142 tiles = { tex, tex, tex, tex, texR90, texR90 },
143 groups = { dig_immediate = 2, colorcube = 3 },
144 sounds = soundmaker(0.1),
147 minetest.register_craft({
148 output = nodeid,
149 recipe = {
150 {"colorcubes:"..c1.."_single", "colorcubes:"..c2.."_single" },
151 {"colorcubes:"..c2.."_single", "colorcubes:"..c1.."_single" },
154 minetest.register_craft({
155 output = nodeid,
156 recipe = {
157 {"colorcubes:"..c2.."_single", "colorcubes:"..c1.."_single" },
158 {"colorcubes:"..c1.."_single", "colorcubes:"..c2.."_single" },
162 --[[ This register the block to the paint roller mod. Note that this block can
163 only be painted, but it can not be reversed; it will not be possible to paint a
164 tiled block so that it becomes a 2-color block. Thus, we use minor hack by using
165 a fake dye group called “none” to make sure there is no dye to turn a tiled block
166 into a 2-color tiled block. ]]
167 if(minetest.get_modpath("paint_roller") ~= nil) then
168 paint_roller.register_one(nodeid, "none", "tiled color cubes" )