Improve huge mushroom schematics, varying height
[MineClone/MineClone2.git] / mods / ITEMS / mcl_dye / init.lua
blob77cc5efad969312b60b3a316797d0ad62e8b78df
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: Use biome-specific flowers
109 local flowers_table = {
110 "mcl_flowers:dandelion",
111 "mcl_flowers:dandelion",
112 "mcl_flowers:poppy",
114 "mcl_flowers:blue_orchid",
115 "mcl_flowers:oxeye_daisy",
116 "mcl_flowers:tulip_orange",
117 "mcl_flowers:tulip_red",
118 "mcl_flowers:tulip_white",
119 "mcl_flowers:tulip_pink",
120 "mcl_flowers:allium",
121 "mcl_flowers:azure_bluet",
124 pos = pointed_thing.under
125 n = minetest.get_node(pos)
126 if n.name == "" then return false end
127 if minetest.get_item_group(n.name, "sapling") >= 1 then
128 -- Saplings: 45% chance to advance growth stage
129 if math.random(1,100) <= 45 then
130 return mcl_core.grow_sapling(pos, n)
132 elseif minetest.get_item_group(n.name, "mushroom") == 1 then
133 -- Try to grow huge mushroom
135 -- Must be on a dirt-type block
136 local below = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
137 if below.name ~= "mcl_core:mycelium" and below.name ~= "mcl_core:dirt" and below.name ~= "mcl_core:dirt_with_grass" and below.name ~= "mcl_core:coarse_dirt" and below.name ~= "mcl_core:podzol" then
138 return false
141 -- Select schematic
142 local schematic, offset, height
143 if n.name == "mcl_mushrooms:mushroom_brown" then
144 schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_brown.mts"
145 offset = { x = -3, y = -1, z = -3 }
146 height = 8
147 elseif n.name == "mcl_mushrooms:mushroom_red" then
148 schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_red.mts"
149 offset = { x = -2, y = -1, z = -2 }
150 height = 8
151 else
152 return false
154 -- 40% chance
155 if math.random(1,100) <= 40 then
156 -- Check space requirements
157 for i=1,3 do
158 local cpos = vector.add(pos, {x=0, y=i, z=0})
159 if minetest.get_node(cpos).name ~= "air" then
160 return false
163 local yoff = 3
164 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}
165 local diff = vector.subtract(maxp, minp)
166 diff = vector.add(diff, {x=1,y=1,z=1})
167 local totalnodes = diff.x * diff.y * diff.z
168 local goodnodes = minetest.find_nodes_in_area(minp, maxp, {"air", "group:leaves"})
169 if #goodnodes < totalnodes then
170 return false
173 -- Place the huge mushroom
174 minetest.remove_node(pos)
175 local place_pos = vector.add(pos, offset)
176 local ok = minetest.place_schematic(place_pos, schematic, 0, nil, false)
177 return ok ~= nil
179 return false
180 -- Wheat, Potato, Carrot, Pumpkin Stem, Melon Stem: Advance by 2-5 stages
181 elseif string.find(n.name, "mcl_farming:wheat_") ~= nil then
182 local stages = math.random(2, 5)
183 return mcl_farming:grow_plant("plant_wheat", pos, n, stages)
184 elseif string.find(n.name, "mcl_farming:potato_") ~= nil then
185 local stages = math.random(2, 5)
186 return mcl_farming:grow_plant("plant_potato", pos, n, stages)
187 elseif string.find(n.name, "mcl_farming:carrot_") ~= nil then
188 local stages = math.random(2, 5)
189 return mcl_farming:grow_plant("plant_carrot", pos, n, stages)
190 elseif string.find(n.name, "mcl_farming:pumpkin_") ~= nil then
191 local stages = math.random(2, 5)
192 return mcl_farming:grow_plant("plant_pumpkin_stem", pos, n, stages)
193 elseif string.find(n.name, "mcl_farming:melontige_") ~= nil then
194 local stages = math.random(2, 5)
195 return mcl_farming:grow_plant("plant_melon_stem", pos, n, stages)
197 elseif string.find(n.name, "mcl_farming:beetroot_") ~= nil then
198 -- Beetroot: 75% chance to advance to next stage
199 if math.random(1,100) <= 75 then
200 return mcl_farming:grow_plant("plant_beetroot", pos, n)
202 elseif n.name == "mcl_cocoas:cocoa_1" or n.name == "mcl_cocoas:cocoa_2" then
203 -- Cocoa: Advance by 1 stage
204 mcl_cocoas.grow(pos)
205 return true
206 elseif n.name == "mcl_core:dirt_with_grass" or n.name == "mcl_core:dirt_with_grass_snow" then
207 -- Grass Block: Generate tall grass and random flowers all over the place
208 for i = -2, 2 do
209 for j = -2, 2 do
210 pos = pointed_thing.above
211 pos = {x=pos.x+i, y=pos.y, z=pos.z+j}
212 n = minetest.get_node(pos)
213 n2 = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
215 if n.name ~= "" and n.name == "air" and (n2.name == "mcl_core:dirt_with_grass" or n2.name == "mcl_core:dirt_with_grass_snow") then
216 -- Randomly generate flowers, tall grass or nothing
217 if math.random(1,100) <= 90 then
218 -- 90% tall grass, 10% flower
219 if math.random(1,100) <= 90 then
220 minetest.add_node(pos, {name="mcl_core:tallgrass"})
221 else
222 minetest.add_node(pos, {name=flowers_table[math.random(1, #flowers_table)]})
228 return true
230 -- Double flowers: Drop corresponding item
231 elseif n.name == "mcl_flowers:rose_bush" or n.name == "mcl_flowers:rose_bush_top" then
232 minetest.add_item(pos, "mcl_flowers:rose_bush")
233 return true
234 elseif n.name == "mcl_flowers:peony" or n.name == "mcl_flowers:peony_top" then
235 minetest.add_item(pos, "mcl_flowers:peony")
236 return true
237 elseif n.name == "mcl_flowers:lilac" or n.name == "mcl_flowers:lilac_top" then
238 minetest.add_item(pos, "mcl_flowers:lilac")
239 return true
240 elseif n.name == "mcl_flowers:sunflower" or n.name == "mcl_flowers:sunflower_top" then
241 minetest.add_item(pos, "mcl_flowers:sunflower")
242 return true
244 elseif n.name == "mcl_flowers:tallgrass" then
245 -- Tall Grass: Grow into double tallgrass
246 local toppos = { x=pos.x, y=pos.y+1, z=pos.z }
247 local topnode = minetest.get_node(toppos)
248 if minetest.registered_nodes[topnode.name].buildable_to then
249 minetest.set_node(pos, { name = "mcl_flowers:double_grass" })
250 minetest.set_node(toppos, { name = "mcl_flowers:double_grass_top" })
251 return true
254 elseif n.name == "mcl_flowers:fern" then
255 -- Fern: Grow into large fern
256 local toppos = { x=pos.x, y=pos.y+1, z=pos.z }
257 local topnode = minetest.get_node(toppos)
258 if minetest.registered_nodes[topnode.name].buildable_to then
259 minetest.set_node(pos, { name = "mcl_flowers:double_fern" })
260 minetest.set_node(toppos, { name = "mcl_flowers:double_fern_top" })
261 return true
265 return false
268 minetest.register_craftitem("mcl_dye:white", {
269 inventory_image = "dye_white.png",
270 description = "Bone Meal",
271 _doc_items_longdesc = "Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.",
272 _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.",
273 stack_max = 64,
274 groups = dyelocal.dyes[1][3],
275 on_place = function(itemstack, user, pointed_thing)
276 -- Use pointed node's on_rightclick function first, if present
277 local node = minetest.get_node(pointed_thing.under)
278 if user and not user:get_player_control().sneak then
279 if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
280 return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack
284 -- Use the bone meal on the ground
285 if(mcl_dye.apply_bone_meal(pointed_thing) and not minetest.settings:get_bool("creative_mode")) then
286 itemstack:take_item()
288 return itemstack
289 end,
292 minetest.register_craftitem("mcl_dye:brown", {
293 inventory_image = "dye_brown.png",
294 _doc_items_longdesc = "Cocoa beans are a brown dye and can be used to plant cocoas.",
295 _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.",
296 description = "Cocoa Beans",
297 stack_max = 64,
298 groups = dyelocal.dyes[12][3],
299 on_place = function(itemstack, placer, pointed_thing)
300 return mcl_cocoas.place(itemstack, placer, pointed_thing, "mcl_cocoas:cocoa_1")
301 end,
304 -- Dye mixing
305 minetest.register_craft({
306 type = "shapeless",
307 output = "mcl_dye:dark_grey 2",
308 recipe = {"mcl_dye:black", "mcl_dye:white"},
310 minetest.register_craft({
311 type = "shapeless",
312 output = "mcl_dye:lightblue 2",
313 recipe = {"mcl_dye:blue", "mcl_dye:white"},
315 minetest.register_craft({
316 type = "shapeless",
317 output = "mcl_dye:grey 3",
318 recipe = {"mcl_dye:black", "mcl_dye:white", "mcl_dye:white"},
320 minetest.register_craft({
321 type = "shapeless",
322 output = "mcl_dye:grey 2",
323 recipe = {"mcl_dye:dark_grey", "mcl_dye:white"},
325 minetest.register_craft({
326 type = "shapeless",
327 output = "mcl_dye:green 2",
328 recipe = {"mcl_dye:dark_green", "mcl_dye:white"},
330 minetest.register_craft({
331 type = "shapeless",
332 output = "mcl_dye:magenta 4",
333 recipe = {"mcl_dye:blue", "mcl_dye:white", "mcl_dye:red", "mcl_dye:red"},
335 minetest.register_craft({
336 type = "shapeless",
337 output = "mcl_dye:magenta 3",
338 recipe = {"mcl_dye:pink", "mcl_dye:red", "mcl_dye:blue"},
340 minetest.register_craft({
341 type = "shapeless",
342 output = "mcl_dye:magenta 2",
343 recipe = {"mcl_dye:violet", "mcl_dye:pink"},
346 minetest.register_craft({
347 type = "shapeless",
348 output = "mcl_dye:pink 2",
349 recipe = {"mcl_dye:red", "mcl_dye:white"},
352 minetest.register_craft({
353 type = "shapeless",
354 output = "mcl_dye:cyan 2",
355 recipe = {"mcl_dye:blue", "mcl_dye:dark_green"},
358 minetest.register_craft({
359 type = "shapeless",
360 output = "mcl_dye:violet 2",
361 recipe = {"mcl_dye:blue", "mcl_dye:red"},
363 minetest.register_craft({
364 type = "shapeless",
365 output = "mcl_dye:orange 2",
366 recipe = {"mcl_dye:yellow", "mcl_dye:red"},
369 -- Dye creation
370 minetest.register_craft({
371 output = "mcl_dye:yellow",
372 recipe = {{"mcl_flowers:dandelion"}},
374 minetest.register_craft({
375 output = "mcl_dye:yellow 2",
376 recipe = {{"mcl_flowers:sunflower"}},
378 minetest.register_craft({
379 output = "mcl_dye:lightblue",
380 recipe = {{"mcl_flowers:blue_orchid"}},
382 minetest.register_craft({
383 output = "mcl_dye:grey",
384 recipe = {{"mcl_flowers:azure_bluet"}},
386 minetest.register_craft({
387 output = "mcl_dye:grey",
388 recipe = {{"mcl_flowers:oxeye_daisy"}},
390 minetest.register_craft({
391 output = "mcl_dye:grey",
392 recipe = {{"mcl_flowers:tulip_white"}},
394 minetest.register_craft({
395 output = "mcl_dye:magenta",
396 recipe = {{"mcl_flowers:allium"}},
398 minetest.register_craft({
399 output = "mcl_dye:magenta 2",
400 recipe = {{"mcl_flowers:lilac"}},
402 minetest.register_craft({
403 output = "mcl_dye:orange",
404 recipe = {{"mcl_flowers:tulip_orange"}},
406 minetest.register_craft({
407 output = "mcl_dye:pink",
408 recipe = {{"mcl_flowers:tulip_pink"}},
410 minetest.register_craft({
411 output = "mcl_dye:pink 2",
412 recipe = {{"mcl_flowers:peony"}},
414 minetest.register_craft({
415 output = "mcl_dye:red",
416 recipe = {{"mcl_farming:beetroot_item"}},
418 minetest.register_craft({
419 output = "mcl_dye:red",
420 recipe = {{"mcl_flowers:poppy"}},
422 minetest.register_craft({
423 output = "mcl_dye:red",
424 recipe = {{"mcl_flowers:tulip_red"}},
426 minetest.register_craft({
427 output = "mcl_dye:red 2",
428 recipe = {{"mcl_flowers:rose_bush"}},
430 minetest.register_craft({
431 type = "cooking",
432 output = "mcl_dye:dark_green",
433 recipe = "mcl_core:cactus",
434 cooktime = 10,
436 minetest.register_craft({
437 output = "mcl_dye:white 3",
438 recipe = {{"mcl_mobitems:bone"}},