Incorporate applying bonemeal to Bamboo stalks.

This commit is contained in:
Michieal 2023-01-04 22:49:17 -05:00
parent 65aa956d9c
commit 687887fe27

View file

@ -67,28 +67,28 @@ local dyelocal = {}
-- This collection of colors is partly a historic thing, partly something else. -- This collection of colors is partly a historic thing, partly something else.
dyelocal.dyes = { dyelocal.dyes = {
{"white", "mcl_dye_white", S("Bone Meal"), {dye=1, craftitem=1, basecolor_white=1, excolor_white=1, unicolor_white=1}}, {"white", "mcl_dye_white", S("Bone Meal"), {dye = 1, craftitem = 1, basecolor_white = 1, excolor_white = 1, unicolor_white = 1}},
{"grey", "dye_grey", S("Light Grey Dye"), {dye=1, craftitem=1, basecolor_grey=1, excolor_grey=1, unicolor_grey=1}}, {"grey", "dye_grey", S("Light Grey Dye"), {dye = 1, craftitem = 1, basecolor_grey = 1, excolor_grey = 1, unicolor_grey = 1}},
{"dark_grey", "dye_dark_grey", S("Grey Dye"), {dye=1, craftitem=1, basecolor_grey=1, excolor_darkgrey=1, unicolor_darkgrey=1}}, {"dark_grey", "dye_dark_grey", S("Grey Dye"), {dye = 1, craftitem = 1, basecolor_grey = 1, excolor_darkgrey = 1, unicolor_darkgrey = 1}},
{"black", "mcl_dye_black", S("Ink Sac"), {dye=1, craftitem=1, basecolor_black=1, excolor_black=1, unicolor_black=1}}, {"black", "mcl_dye_black", S("Ink Sac"), {dye = 1, craftitem = 1, basecolor_black = 1, excolor_black = 1, unicolor_black = 1}},
{"violet", "dye_violet", S("Purple Dye"), {dye=1, craftitem=1, basecolor_magenta=1, excolor_violet=1, unicolor_violet=1}}, {"violet", "dye_violet", S("Purple Dye"), {dye = 1, craftitem = 1, basecolor_magenta = 1, excolor_violet = 1, unicolor_violet = 1}},
{"blue", "mcl_dye_blue", S("Lapis Lazuli"), {dye=1, craftitem=1, basecolor_blue=1, excolor_blue=1, unicolor_blue=1}}, {"blue", "mcl_dye_blue", S("Lapis Lazuli"), {dye = 1, craftitem = 1, basecolor_blue = 1, excolor_blue = 1, unicolor_blue = 1}},
{"lightblue", "mcl_dye_light_blue", S("Light Blue Dye"), {dye=1, craftitem=1, basecolor_blue=1, excolor_blue=1, unicolor_light_blue=1}}, {"lightblue", "mcl_dye_light_blue", S("Light Blue Dye"), {dye = 1, craftitem = 1, basecolor_blue = 1, excolor_blue = 1, unicolor_light_blue = 1}},
{"cyan", "dye_cyan", S("Cyan Dye"), {dye=1, craftitem=1, basecolor_cyan=1, excolor_cyan=1, unicolor_cyan=1}}, {"cyan", "dye_cyan", S("Cyan Dye"), {dye = 1, craftitem = 1, basecolor_cyan = 1, excolor_cyan = 1, unicolor_cyan = 1}},
{"dark_green", "dye_dark_green", S("Cactus Green"),{dye=1, craftitem=1, basecolor_green=1, excolor_green=1, unicolor_dark_green=1}}, {"dark_green", "dye_dark_green", S("Cactus Green"), {dye = 1, craftitem = 1, basecolor_green = 1, excolor_green = 1, unicolor_dark_green = 1}},
{"green", "mcl_dye_lime", S("Lime Dye"), {dye=1, craftitem=1, basecolor_green=1, excolor_green=1, unicolor_green=1}}, {"green", "mcl_dye_lime", S("Lime Dye"), {dye = 1, craftitem = 1, basecolor_green = 1, excolor_green = 1, unicolor_green = 1}},
{"yellow", "dye_yellow", S("Dandelion Yellow"), {dye=1, craftitem=1, basecolor_yellow=1, excolor_yellow=1, unicolor_yellow=1}}, {"yellow", "dye_yellow", S("Dandelion Yellow"), {dye = 1, craftitem = 1, basecolor_yellow = 1, excolor_yellow = 1, unicolor_yellow = 1}},
{"brown", "mcl_dye_brown", S("Cocoa Beans"), {dye=1, craftitem=1, basecolor_brown=1, excolor_orange=1, unicolor_dark_orange=1, compostability = 65}}, {"brown", "mcl_dye_brown", S("Cocoa Beans"), {dye = 1, craftitem = 1, basecolor_brown = 1, excolor_orange = 1, unicolor_dark_orange = 1, compostability = 65}},
{"orange", "dye_orange", S("Orange Dye"), {dye=1, craftitem=1, basecolor_orange=1, excolor_orange=1, unicolor_orange=1}}, {"orange", "dye_orange", S("Orange Dye"), {dye = 1, craftitem = 1, basecolor_orange = 1, excolor_orange = 1, unicolor_orange = 1}},
{"red", "dye_red", S("Rose Red"), {dye=1, craftitem=1, basecolor_red=1, excolor_red=1, unicolor_red=1}}, {"red", "dye_red", S("Rose Red"), {dye = 1, craftitem = 1, basecolor_red = 1, excolor_red = 1, unicolor_red = 1}},
{"magenta", "dye_magenta", S("Magenta Dye"), {dye=1, craftitem=1, basecolor_magenta=1, excolor_red_violet=1,unicolor_red_violet=1}}, {"magenta", "dye_magenta", S("Magenta Dye"), {dye = 1, craftitem = 1, basecolor_magenta = 1, excolor_red_violet = 1, unicolor_red_violet = 1}},
{"pink", "dye_pink", S("Pink Dye"), {dye=1, craftitem=1, basecolor_red=1, excolor_red=1, unicolor_light_red=1}}, {"pink", "dye_pink", S("Pink Dye"), {dye = 1, craftitem = 1, basecolor_red = 1, excolor_red = 1, unicolor_light_red = 1}},
} }
local mg_name = minetest.get_mapgen_setting("mg_name") local mg_name = minetest.get_mapgen_setting("mg_name")
dyelocal.unicolor_to_dye_id = {} dyelocal.unicolor_to_dye_id = {}
for d=1, #dyelocal.dyes do for d = 1, #dyelocal.dyes do
for k, _ in pairs(dyelocal.dyes[d][4]) do for k, _ in pairs(dyelocal.dyes[d][4]) do
if string.sub(k, 1, 9) == "unicolor_" then if string.sub(k, 1, 9) == "unicolor_" then
dyelocal.unicolor_to_dye_id[k] = dyelocal.dyes[d][1] dyelocal.unicolor_to_dye_id[k] = dyelocal.dyes[d][1]
@ -114,8 +114,8 @@ for _, row in ipairs(dyelocal.dyes) do
local img = row[2] local img = row[2]
local description = row[3] local description = row[3]
local groups = row[4] local groups = row[4]
local item_name = "mcl_dye:"..name local item_name = "mcl_dye:" .. name
local item_image = img..".png" local item_image = img .. ".png"
minetest.register_craftitem(item_name, { minetest.register_craftitem(item_name, {
inventory_image = item_image, inventory_image = item_image,
description = description, description = description,
@ -156,7 +156,7 @@ function mcl_dye.register_on_bone_meal_apply(func)
table.insert(mcl_dye.bone_meal_callbacks, func) table.insert(mcl_dye.bone_meal_callbacks, func)
end end
local function apply_bone_meal(pointed_thing,user) local function apply_bone_meal(pointed_thing, user)
-- Bone meal currently spawns all flowers found in the plains. -- Bone meal currently spawns all flowers found in the plains.
local flowers_table_plains = { local flowers_table_plains = {
"mcl_flowers:dandelion", "mcl_flowers:dandelion",
@ -191,7 +191,9 @@ local function apply_bone_meal(pointed_thing,user)
local pos = pointed_thing.under local pos = pointed_thing.under
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
if n.name == "" then return false end if n.name == "" then
return false
end
for _, func in pairs(mcl_dye.bone_meal_callbacks) do for _, func in pairs(mcl_dye.bone_meal_callbacks) do
if func(pointed_thing, user) then if func(pointed_thing, user) then
@ -202,7 +204,7 @@ local function apply_bone_meal(pointed_thing,user)
if minetest.get_item_group(n.name, "sapling") >= 1 then if minetest.get_item_group(n.name, "sapling") >= 1 then
mcl_dye.add_bone_meal_particle(pos) mcl_dye.add_bone_meal_particle(pos)
-- Saplings: 45% chance to advance growth stage -- Saplings: 45% chance to advance growth stage
if math.random(1,100) <= 45 then if math.random(1, 100) <= 45 then
return mcl_core.grow_sapling(pos, n) return mcl_core.grow_sapling(pos, n)
end end
elseif minetest.get_item_group(n.name, "mushroom") == 1 then elseif minetest.get_item_group(n.name, "mushroom") == 1 then
@ -210,7 +212,7 @@ local function apply_bone_meal(pointed_thing,user)
-- Try to grow huge mushroom -- Try to grow huge mushroom
-- Must be on a dirt-type block -- Must be on a dirt-type block
local below = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}) local below = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
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 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
return false return false
end end
@ -218,12 +220,12 @@ local function apply_bone_meal(pointed_thing,user)
-- Select schematic -- Select schematic
local schematic, offset, height local schematic, offset, height
if n.name == "mcl_mushrooms:mushroom_brown" then if n.name == "mcl_mushrooms:mushroom_brown" then
schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_brown.mts" schematic = minetest.get_modpath("mcl_mushrooms") .. "/schematics/mcl_mushrooms_huge_brown.mts"
offset = { x = -3, y = -1, z = -3 } offset = {x = -3, y = -1, z = -3}
height = 8 height = 8
elseif n.name == "mcl_mushrooms:mushroom_red" then elseif n.name == "mcl_mushrooms:mushroom_red" then
schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_red.mts" schematic = minetest.get_modpath("mcl_mushrooms") .. "/schematics/mcl_mushrooms_huge_red.mts"
offset = { x = -2, y = -1, z = -2 } offset = {x = -2, y = -1, z = -2}
height = 8 height = 8
else else
return false return false
@ -231,16 +233,16 @@ local function apply_bone_meal(pointed_thing,user)
-- 40% chance -- 40% chance
if math.random(1, 100) <= 40 then if math.random(1, 100) <= 40 then
-- Check space requirements -- Check space requirements
for i=1,3 do for i = 1, 3 do
local cpos = vector.add(pos, {x=0, y=i, z=0}) local cpos = vector.add(pos, {x = 0, y = i, z = 0})
if minetest.get_node(cpos).name ~= "air" then if minetest.get_node(cpos).name ~= "air" then
return false return false
end end
end end
local yoff = 3 local yoff = 3
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} 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}
local diff = vector.subtract(maxp, minp) local diff = vector.subtract(maxp, minp)
diff = vector.add(diff, {x=1,y=1,z=1}) diff = vector.add(diff, {x = 1, y = 1, z = 1})
local totalnodes = diff.x * diff.y * diff.z local totalnodes = diff.x * diff.y * diff.z
local goodnodes = minetest.find_nodes_in_area(minp, maxp, {"air", "group:leaves"}) local goodnodes = minetest.find_nodes_in_area(minp, maxp, {"air", "group:leaves"})
if #goodnodes < totalnodes then if #goodnodes < totalnodes then
@ -284,7 +286,7 @@ local function apply_bone_meal(pointed_thing,user)
elseif string.find(n.name, "mcl_farming:sweet_berry_bush_") then elseif string.find(n.name, "mcl_farming:sweet_berry_bush_") then
mcl_dye.add_bone_meal_particle(pos) mcl_dye.add_bone_meal_particle(pos)
if n.name == "mcl_farming:sweet_berry_bush_3" then if n.name == "mcl_farming:sweet_berry_bush_3" then
return minetest.add_item(vector.offset(pos,math.random()-0.5,math.random()-0.5,math.random()-0.5),"mcl_farming:sweet_berry") return minetest.add_item(vector.offset(pos, math.random() - 0.5, math.random() - 0.5, math.random() - 0.5), "mcl_farming:sweet_berry")
else else
return mcl_farming:grow_plant("plant_sweet_berry_bush", pos, n, 1, true) return mcl_farming:grow_plant("plant_sweet_berry_bush", pos, n, 1, true)
end end
@ -304,12 +306,12 @@ local function apply_bone_meal(pointed_thing,user)
if n.name ~= "" and n.name == "air" and (minetest.get_item_group(n2.name, "grass_block_no_snow") == 1) then if n.name ~= "" and n.name == "air" and (minetest.get_item_group(n2.name, "grass_block_no_snow") == 1) then
-- Randomly generate flowers, tall grass or nothing -- Randomly generate flowers, tall grass or nothing
if math.random(1, 100) <= 90 / ((math.abs(i) + math.abs(j)) / 2)then if math.random(1, 100) <= 90 / ((math.abs(i) + math.abs(j)) / 2) then
-- 90% tall grass, 10% flower -- 90% tall grass, 10% flower
mcl_dye.add_bone_meal_particle(pos, {amount = 4}) mcl_dye.add_bone_meal_particle(pos, {amount = 4})
if math.random(1,100) <= 90 then if math.random(1, 100) <= 90 then
local col = n2.param2 local col = n2.param2
minetest.add_node(pos, {name="mcl_flowers:tallgrass", param2=col}) minetest.add_node(pos, {name = "mcl_flowers:tallgrass", param2 = col})
else else
local flowers_table local flowers_table
if mg_name == "v6" then if mg_name == "v6" then
@ -326,7 +328,7 @@ local function apply_bone_meal(pointed_thing,user)
flowers_table = flowers_table_simple flowers_table = flowers_table_simple
end end
end end
minetest.add_node(pos, {name=flowers_table[math.random(1, #flowers_table)]}) minetest.add_node(pos, {name = flowers_table[math.random(1, #flowers_table)]})
end end
end end
end end
@ -356,22 +358,30 @@ local function apply_bone_meal(pointed_thing,user)
elseif n.name == "mcl_flowers:tallgrass" then elseif n.name == "mcl_flowers:tallgrass" then
mcl_dye.add_bone_meal_particle(pos) mcl_dye.add_bone_meal_particle(pos)
-- Tall Grass: Grow into double tallgrass -- Tall Grass: Grow into double tallgrass
local toppos = { x=pos.x, y=pos.y+1, z=pos.z } local toppos = {x = pos.x, y = pos.y + 1, z = pos.z}
local topnode = minetest.get_node(toppos) local topnode = minetest.get_node(toppos)
if minetest.registered_nodes[topnode.name].buildable_to then if minetest.registered_nodes[topnode.name].buildable_to then
minetest.set_node(pos, { name = "mcl_flowers:double_grass", param2 = n.param2 }) minetest.set_node(pos, {name = "mcl_flowers:double_grass", param2 = n.param2})
minetest.set_node(toppos, { name = "mcl_flowers:double_grass_top", param2 = n.param2 }) minetest.set_node(toppos, {name = "mcl_flowers:double_grass_top", param2 = n.param2})
return true return true
end end
-- Handle applying bonemeal to bamboo.
elseif mcl_bamboo.is_bamboo(n.name) then
local success = mcl_bamboo.grow_bamboo(pos, true)
if success then
mcl_dye.add_bone_meal_particle(pos)
end
return success
elseif n.name == "mcl_flowers:fern" then elseif n.name == "mcl_flowers:fern" then
mcl_dye.add_bone_meal_particle(pos) mcl_dye.add_bone_meal_particle(pos)
-- Fern: Grow into large fern -- Fern: Grow into large fern
local toppos = { x=pos.x, y=pos.y+1, z=pos.z } local toppos = {x = pos.x, y = pos.y + 1, z = pos.z}
local topnode = minetest.get_node(toppos) local topnode = minetest.get_node(toppos)
if minetest.registered_nodes[topnode.name].buildable_to then if minetest.registered_nodes[topnode.name].buildable_to then
minetest.set_node(pos, { name = "mcl_flowers:double_fern", param2 = n.param2 }) minetest.set_node(pos, {name = "mcl_flowers:double_fern", param2 = n.param2})
minetest.set_node(toppos, { name = "mcl_flowers:double_fern_top", param2 = n.param2 }) minetest.set_node(toppos, {name = "mcl_flowers:double_fern_top", param2 = n.param2})
return true return true
end end
end end
@ -408,9 +418,9 @@ minetest.register_craftitem("mcl_dye:white", {
-- Apply bone meal, if possible -- Apply bone meal, if possible
local pointed_thing local pointed_thing
if dropnode.name == "air" then if dropnode.name == "air" then
pointed_thing = { above = droppos, under = { x=droppos.x, y=droppos.y-1, z=droppos.z } } pointed_thing = {above = droppos, under = {x = droppos.x, y = droppos.y - 1, z = droppos.z}}
else else
pointed_thing = { above = pos, under = droppos } pointed_thing = {above = pos, under = droppos}
end end
local success = apply_bone_meal(pointed_thing, nil) local success = apply_bone_meal(pointed_thing, nil)
if success then if success then