Use hardware coloring for tallgrass and friends
[MineClone/MineClone2.git] / mods / ITEMS / mcl_dye / init.lua
blobc69befce6280e2c6ee095e01f7e7080ca969dbac
1 -- minetest/dye/init.lua
3 -- To make recipes that will work with any dye ever made by anybody, define
4 -- them based on groups.
5 -- You can select any group of groups, based on your need for amount of colors.
6 -- basecolor: 9, excolor: 17, unicolor: 89
7 --
8 -- Example of one shapeless recipe using a color group:
9 -- Note: As this uses basecolor_*, you'd need 9 of these.
10 -- minetest.register_craft({
11 -- type = "shapeless",
12 -- output = '<mod>:item_yellow',
13 -- recipe = {'<mod>:item_no_color', 'group:basecolor_yellow'},
14 -- })
16 -- Other mods can use these for looping through available colors
17 mcl_dye = {}
18 local dye = {}
19 dye.basecolors = {"white", "grey", "black", "red", "yellow", "green", "cyan", "blue", "magenta"}
20 dye.excolors = {"white", "lightgrey", "grey", "darkgrey", "black", "red", "orange", "yellow", "lime", "green", "aqua", "cyan", "sky_blue", "blue", "violet", "magenta", "red_violet"}
22 -- Base color groups:
23 -- - basecolor_white
24 -- - basecolor_grey
25 -- - basecolor_black
26 -- - basecolor_red
27 -- - basecolor_yellow
28 -- - basecolor_green
29 -- - basecolor_cyan
30 -- - basecolor_blue
31 -- - basecolor_magenta
33 -- Extended color groups (* = equal to a base color):
34 -- * excolor_white
35 -- - excolor_lightgrey
36 -- * excolor_grey
37 -- - excolor_darkgrey
38 -- * excolor_black
39 -- * excolor_red
40 -- - excolor_orange
41 -- * excolor_yellow
42 -- - excolor_lime
43 -- * excolor_green
44 -- - excolor_aqua
45 -- * excolor_cyan
46 -- - excolor_sky_blue
47 -- * excolor_blue
48 -- - excolor_violet
49 -- * excolor_magenta
50 -- - excolor_red_violet
52 -- The whole unifieddyes palette as groups:
53 -- - unicolor_<excolor>
54 -- For the following, no white/grey/black is allowed:
55 -- - unicolor_medium_<excolor>
56 -- - unicolor_dark_<excolor>
57 -- - unicolor_light_<excolor>
58 -- - unicolor_<excolor>_s50
59 -- - unicolor_medium_<excolor>_s50
60 -- - unicolor_dark_<excolor>_s50
62 -- Local stuff
63 local dyelocal = {}
65 -- This collection of colors is partly a historic thing, partly something else.
66 dyelocal.dyes = {
67 {"white", "Bone Meal", {dye=1, craftitem=1, basecolor_white=1, excolor_white=1, unicolor_white=1}},
68 {"grey", "Light Grey Dye", {dye=1, craftitem=1, basecolor_grey=1, excolor_grey=1, unicolor_grey=1}},
69 {"dark_grey", "Grey Dye", {dye=1, craftitem=1, basecolor_grey=1, excolor_darkgrey=1, unicolor_darkgrey=1}},
70 {"black", "Ink Sac", {dye=1, craftitem=1, basecolor_black=1, excolor_black=1, unicolor_black=1}},
71 {"violet", "Purple Dye", {dye=1, craftitem=1, basecolor_magenta=1, excolor_violet=1, unicolor_violet=1}},
72 {"blue", "Lapis Lazuli", {dye=1, craftitem=1, basecolor_blue=1, excolor_blue=1, unicolor_blue=1}},
73 {"lightblue", "Light Blue Dye", {dye=1, craftitem=1, basecolor_blue=1, excolor_blue=1, unicolor_light_blue=1}},
74 {"cyan", "Cyan Dye", {dye=1, craftitem=1, basecolor_cyan=1, excolor_cyan=1, unicolor_cyan=1}},
75 {"dark_green", "Cactus Green",{dye=1, craftitem=1, basecolor_green=1, excolor_green=1, unicolor_dark_green=1}},
76 {"green", "Lime Dye", {dye=1, craftitem=1, basecolor_green=1, excolor_green=1, unicolor_green=1}},
77 {"yellow", "Dandelion Yellow", {dye=1, craftitem=1, basecolor_yellow=1, excolor_yellow=1, unicolor_yellow=1}},
78 {"brown", "Cocoa Beans", {dye=1, craftitem=1, basecolor_brown=1, excolor_orange=1, unicolor_dark_orange=1}},
79 {"orange", "Orange Dye", {dye=1, craftitem=1, basecolor_orange=1, excolor_orange=1, unicolor_orange=1}},
80 {"red", "Rose Red", {dye=1, craftitem=1, basecolor_red=1, excolor_red=1, unicolor_red=1}},
81 {"magenta", "Magenta Dye", {dye=1, craftitem=1, basecolor_magenta=1, excolor_red_violet=1,unicolor_red_violet=1}},
82 {"pink", "Pink Dye", {dye=1, craftitem=1, basecolor_red=1, excolor_red=1, unicolor_light_red=1}},
85 -- Define items
86 for _, row in ipairs(dyelocal.dyes) do
87 local name = row[1]
88 -- White and brown dyes are defined explicitly below
89 if name ~= "white" and name ~= "brown" then
90 local description = row[2]
91 local groups = row[3]
92 local item_name = "mcl_dye:"..name
93 local item_image = "dye_"..name..".png"
94 minetest.register_craftitem(item_name, {
95 inventory_image = item_image,
96 description = description,
97 _doc_items_longdesc = "This item is a dye which is used for dyeing and crafting.",
98 _doc_items_usagehelp = "Rightclick on a sheep to dye its wool. Other things are dyed by crafting.",
99 groups = groups,
100 stack_max = 64,
105 -- Bone Meal
107 mcl_dye.apply_bone_meal = function(pointed_thing)
108 -- TODO: Only spawn flowers specific to the biome
110 -- Bone meal currently spawns all flowers found in the plains.
111 local flowers_table = {
112 "mcl_flowers:dandelion",
113 "mcl_flowers:dandelion",
114 "mcl_flowers:poppy",
116 "mcl_flowers:oxeye_daisy",
117 "mcl_flowers:tulip_orange",
118 "mcl_flowers:tulip_red",
119 "mcl_flowers:tulip_white",
120 "mcl_flowers:tulip_pink",
121 "mcl_flowers:azure_bluet",
123 -- Allium and blue orchid intentionally left out,
124 -- those must be found by the player.
126 -- Special case for dry lands
127 local flowers_table_dry = {
128 "mcl_flowers:dandelion",
129 "mcl_flowers:poppy",
132 local pos = pointed_thing.under
133 local n = minetest.get_node(pos)
134 if n.name == "" then return false end
135 if minetest.get_item_group(n.name, "sapling") >= 1 then
136 -- Saplings: 45% chance to advance growth stage
137 if math.random(1,100) <= 45 then
138 return mcl_core.grow_sapling(pos, n)
140 elseif minetest.get_item_group(n.name, "mushroom") == 1 then
141 -- Try to grow huge mushroom
143 -- Must be on a dirt-type block
144 local below = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
145 if below.name ~= "mcl_core:mycelium" and below.name ~= "mcl_core:dirt" and minetest.get_item_group(below.name, "grass_block") ~= 1 and below.name ~= "mcl_core:coarse_dirt" and below.name ~= "mcl_core:podzol" then
146 return false
149 -- Select schematic
150 local schematic, offset, height
151 if n.name == "mcl_mushrooms:mushroom_brown" then
152 schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_brown.mts"
153 offset = { x = -3, y = -1, z = -3 }
154 height = 8
155 elseif n.name == "mcl_mushrooms:mushroom_red" then
156 schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_red.mts"
157 offset = { x = -2, y = -1, z = -2 }
158 height = 8
159 else
160 return false
162 -- 40% chance
163 if math.random(1,100) <= 40 then
164 -- Check space requirements
165 for i=1,3 do
166 local cpos = vector.add(pos, {x=0, y=i, z=0})
167 if minetest.get_node(cpos).name ~= "air" then
168 return false
171 local yoff = 3
172 local minp, maxp = {x=pos.x-3, y=pos.y+yoff, z=pos.z-3}, {x=pos.x+3, y=pos.y+yoff+(height-3), z=pos.z+3}
173 local diff = vector.subtract(maxp, minp)
174 diff = vector.add(diff, {x=1,y=1,z=1})
175 local totalnodes = diff.x * diff.y * diff.z
176 local goodnodes = minetest.find_nodes_in_area(minp, maxp, {"air", "group:leaves"})
177 if #goodnodes < totalnodes then
178 return false
181 -- Place the huge mushroom
182 minetest.remove_node(pos)
183 local place_pos = vector.add(pos, offset)
184 local ok = minetest.place_schematic(place_pos, schematic, 0, nil, false)
185 return ok ~= nil
187 return false
188 -- Wheat, Potato, Carrot, Pumpkin Stem, Melon Stem: Advance by 2-5 stages
189 elseif string.find(n.name, "mcl_farming:wheat_") ~= nil then
190 local stages = math.random(2, 5)
191 return mcl_farming:grow_plant("plant_wheat", pos, n, stages)
192 elseif string.find(n.name, "mcl_farming:potato_") ~= nil then
193 local stages = math.random(2, 5)
194 return mcl_farming:grow_plant("plant_potato", pos, n, stages)
195 elseif string.find(n.name, "mcl_farming:carrot_") ~= nil then
196 local stages = math.random(2, 5)
197 return mcl_farming:grow_plant("plant_carrot", pos, n, stages)
198 elseif string.find(n.name, "mcl_farming:pumpkin_") ~= nil then
199 local stages = math.random(2, 5)
200 return mcl_farming:grow_plant("plant_pumpkin_stem", pos, n, stages)
201 elseif string.find(n.name, "mcl_farming:melontige_") ~= nil then
202 local stages = math.random(2, 5)
203 return mcl_farming:grow_plant("plant_melon_stem", pos, n, stages)
205 elseif string.find(n.name, "mcl_farming:beetroot_") ~= nil then
206 -- Beetroot: 75% chance to advance to next stage
207 if math.random(1,100) <= 75 then
208 return mcl_farming:grow_plant("plant_beetroot", pos, n)
210 elseif n.name == "mcl_cocoas:cocoa_1" or n.name == "mcl_cocoas:cocoa_2" then
211 -- Cocoa: Advance by 1 stage
212 mcl_cocoas.grow(pos)
213 return true
214 elseif minetest.get_item_group(n.name, "grass_block") == 1 then
215 -- Grass Block: Generate tall grass and random flowers all over the place
216 for i = -2, 2 do
217 for j = -2, 2 do
218 pos = pointed_thing.above
219 pos = {x=pos.x+i, y=pos.y, z=pos.z+j}
220 n = minetest.get_node(pos)
221 local n2 = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
223 if n.name ~= "" and n.name == "air" and (minetest.get_item_group(n2.name, "grass_block_no_snow") == 1) then
224 -- Randomly generate flowers, tall grass or nothing
225 if math.random(1,100) <= 90 then
226 -- 90% tall grass, 10% flower
227 if math.random(1,100) <= 90 then
228 local col = minetest.registered_nodes[n2.name]._mcl_grass_palette_index
229 minetest.add_node(pos, {name="mcl_flowers:tallgrass", param2=col})
230 else
231 if n2.name == "mcl_core:dirt_with_dry_grass" then
232 minetest.add_node(pos, {name=flowers_table_dry[math.random(1, #flowers_table_dry)]})
233 else
234 minetest.add_node(pos, {name=flowers_table[math.random(1, #flowers_table)]})
241 return true
243 -- Double flowers: Drop corresponding item
244 elseif n.name == "mcl_flowers:rose_bush" or n.name == "mcl_flowers:rose_bush_top" then
245 minetest.add_item(pos, "mcl_flowers:rose_bush")
246 return true
247 elseif n.name == "mcl_flowers:peony" or n.name == "mcl_flowers:peony_top" then
248 minetest.add_item(pos, "mcl_flowers:peony")
249 return true
250 elseif n.name == "mcl_flowers:lilac" or n.name == "mcl_flowers:lilac_top" then
251 minetest.add_item(pos, "mcl_flowers:lilac")
252 return true
253 elseif n.name == "mcl_flowers:sunflower" or n.name == "mcl_flowers:sunflower_top" then
254 minetest.add_item(pos, "mcl_flowers:sunflower")
255 return true
257 elseif n.name == "mcl_flowers:tallgrass" then
258 -- Tall Grass: Grow into double tallgrass
259 local toppos = { x=pos.x, y=pos.y+1, z=pos.z }
260 local topnode = minetest.get_node(toppos)
261 if minetest.registered_nodes[topnode.name].buildable_to then
262 minetest.set_node(pos, { name = "mcl_flowers:double_grass", param2 = n.param2 })
263 minetest.set_node(toppos, { name = "mcl_flowers:double_grass_top", param2 = n.param2 })
264 return true
267 elseif n.name == "mcl_flowers:fern" then
268 -- Fern: Grow into large fern
269 local toppos = { x=pos.x, y=pos.y+1, z=pos.z }
270 local topnode = minetest.get_node(toppos)
271 if minetest.registered_nodes[topnode.name].buildable_to then
272 minetest.set_node(pos, { name = "mcl_flowers:double_fern", param2 = n.param2 })
273 minetest.set_node(toppos, { name = "mcl_flowers:double_fern_top", param2 = n.param2 })
274 return true
278 return false
281 minetest.register_craftitem("mcl_dye:white", {
282 inventory_image = "dye_white.png",
283 description = "Bone Meal",
284 _doc_items_longdesc = "Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.",
285 _doc_items_usagehelp = "Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.",
286 stack_max = 64,
287 groups = dyelocal.dyes[1][3],
288 on_place = function(itemstack, user, pointed_thing)
289 -- Use pointed node's on_rightclick function first, if present
290 local node = minetest.get_node(pointed_thing.under)
291 if user and not user:get_player_control().sneak then
292 if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
293 return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack
297 -- Use the bone meal on the ground
298 if(mcl_dye.apply_bone_meal(pointed_thing) and not minetest.settings:get_bool("creative_mode")) then
299 itemstack:take_item()
301 return itemstack
302 end,
305 minetest.register_craftitem("mcl_dye:brown", {
306 inventory_image = "dye_brown.png",
307 _doc_items_longdesc = "Cocoa beans are a brown dye and can be used to plant cocoas.",
308 _doc_items_usagehelp = "Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.",
309 description = "Cocoa Beans",
310 stack_max = 64,
311 groups = dyelocal.dyes[12][3],
312 on_place = function(itemstack, placer, pointed_thing)
313 return mcl_cocoas.place(itemstack, placer, pointed_thing, "mcl_cocoas:cocoa_1")
314 end,
317 -- Dye mixing
318 minetest.register_craft({
319 type = "shapeless",
320 output = "mcl_dye:dark_grey 2",
321 recipe = {"mcl_dye:black", "mcl_dye:white"},
323 minetest.register_craft({
324 type = "shapeless",
325 output = "mcl_dye:lightblue 2",
326 recipe = {"mcl_dye:blue", "mcl_dye:white"},
328 minetest.register_craft({
329 type = "shapeless",
330 output = "mcl_dye:grey 3",
331 recipe = {"mcl_dye:black", "mcl_dye:white", "mcl_dye:white"},
333 minetest.register_craft({
334 type = "shapeless",
335 output = "mcl_dye:grey 2",
336 recipe = {"mcl_dye:dark_grey", "mcl_dye:white"},
338 minetest.register_craft({
339 type = "shapeless",
340 output = "mcl_dye:green 2",
341 recipe = {"mcl_dye:dark_green", "mcl_dye:white"},
343 minetest.register_craft({
344 type = "shapeless",
345 output = "mcl_dye:magenta 4",
346 recipe = {"mcl_dye:blue", "mcl_dye:white", "mcl_dye:red", "mcl_dye:red"},
348 minetest.register_craft({
349 type = "shapeless",
350 output = "mcl_dye:magenta 3",
351 recipe = {"mcl_dye:pink", "mcl_dye:red", "mcl_dye:blue"},
353 minetest.register_craft({
354 type = "shapeless",
355 output = "mcl_dye:magenta 2",
356 recipe = {"mcl_dye:violet", "mcl_dye:pink"},
359 minetest.register_craft({
360 type = "shapeless",
361 output = "mcl_dye:pink 2",
362 recipe = {"mcl_dye:red", "mcl_dye:white"},
365 minetest.register_craft({
366 type = "shapeless",
367 output = "mcl_dye:cyan 2",
368 recipe = {"mcl_dye:blue", "mcl_dye:dark_green"},
371 minetest.register_craft({
372 type = "shapeless",
373 output = "mcl_dye:violet 2",
374 recipe = {"mcl_dye:blue", "mcl_dye:red"},
376 minetest.register_craft({
377 type = "shapeless",
378 output = "mcl_dye:orange 2",
379 recipe = {"mcl_dye:yellow", "mcl_dye:red"},
382 -- Dye creation
383 minetest.register_craft({
384 output = "mcl_dye:yellow",
385 recipe = {{"mcl_flowers:dandelion"}},
387 minetest.register_craft({
388 output = "mcl_dye:yellow 2",
389 recipe = {{"mcl_flowers:sunflower"}},
391 minetest.register_craft({
392 output = "mcl_dye:lightblue",
393 recipe = {{"mcl_flowers:blue_orchid"}},
395 minetest.register_craft({
396 output = "mcl_dye:grey",
397 recipe = {{"mcl_flowers:azure_bluet"}},
399 minetest.register_craft({
400 output = "mcl_dye:grey",
401 recipe = {{"mcl_flowers:oxeye_daisy"}},
403 minetest.register_craft({
404 output = "mcl_dye:grey",
405 recipe = {{"mcl_flowers:tulip_white"}},
407 minetest.register_craft({
408 output = "mcl_dye:magenta",
409 recipe = {{"mcl_flowers:allium"}},
411 minetest.register_craft({
412 output = "mcl_dye:magenta 2",
413 recipe = {{"mcl_flowers:lilac"}},
415 minetest.register_craft({
416 output = "mcl_dye:orange",
417 recipe = {{"mcl_flowers:tulip_orange"}},
419 minetest.register_craft({
420 output = "mcl_dye:pink",
421 recipe = {{"mcl_flowers:tulip_pink"}},
423 minetest.register_craft({
424 output = "mcl_dye:pink 2",
425 recipe = {{"mcl_flowers:peony"}},
427 minetest.register_craft({
428 output = "mcl_dye:red",
429 recipe = {{"mcl_farming:beetroot_item"}},
431 minetest.register_craft({
432 output = "mcl_dye:red",
433 recipe = {{"mcl_flowers:poppy"}},
435 minetest.register_craft({
436 output = "mcl_dye:red",
437 recipe = {{"mcl_flowers:tulip_red"}},
439 minetest.register_craft({
440 output = "mcl_dye:red 2",
441 recipe = {{"mcl_flowers:rose_bush"}},
443 minetest.register_craft({
444 type = "cooking",
445 output = "mcl_dye:dark_green",
446 recipe = "mcl_core:cactus",
447 cooktime = 10,
449 minetest.register_craft({
450 output = "mcl_dye:white 3",
451 recipe = {{"mcl_mobitems:bone"}},