0
0
Fork 0

Incorporate applying bonemeal to Bamboo stalks.

This commit is contained in:
Michieal 2023-01-04 22:49:17 -05:00
parent 65aa956d9c
commit 687887fe27
1 changed files with 56 additions and 46 deletions

View File

@ -67,28 +67,28 @@ local dyelocal = {}
-- This collection of colors is partly a historic thing, partly something else.
dyelocal.dyes = {
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
{"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}},
}
local mg_name = minetest.get_mapgen_setting("mg_name")
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
if string.sub(k, 1, 9) == "unicolor_" then
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 description = row[3]
local groups = row[4]
local item_name = "mcl_dye:"..name
local item_image = img..".png"
local item_name = "mcl_dye:" .. name
local item_image = img .. ".png"
minetest.register_craftitem(item_name, {
inventory_image = item_image,
description = description,
@ -156,7 +156,7 @@ function mcl_dye.register_on_bone_meal_apply(func)
table.insert(mcl_dye.bone_meal_callbacks, func)
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.
local flowers_table_plains = {
"mcl_flowers:dandelion",
@ -191,7 +191,9 @@ local function apply_bone_meal(pointed_thing,user)
local pos = pointed_thing.under
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
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
mcl_dye.add_bone_meal_particle(pos)
-- 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)
end
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
-- 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
return false
end
@ -218,12 +220,12 @@ local function apply_bone_meal(pointed_thing,user)
-- Select schematic
local schematic, offset, height
if n.name == "mcl_mushrooms:mushroom_brown" then
schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_brown.mts"
offset = { x = -3, y = -1, z = -3 }
schematic = minetest.get_modpath("mcl_mushrooms") .. "/schematics/mcl_mushrooms_huge_brown.mts"
offset = {x = -3, y = -1, z = -3}
height = 8
elseif n.name == "mcl_mushrooms:mushroom_red" then
schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_red.mts"
offset = { x = -2, y = -1, z = -2 }
schematic = minetest.get_modpath("mcl_mushrooms") .. "/schematics/mcl_mushrooms_huge_red.mts"
offset = {x = -2, y = -1, z = -2}
height = 8
else
return false
@ -231,16 +233,16 @@ local function apply_bone_meal(pointed_thing,user)
-- 40% chance
if math.random(1, 100) <= 40 then
-- Check space requirements
for i=1,3 do
local cpos = vector.add(pos, {x=0, y=i, z=0})
for i = 1, 3 do
local cpos = vector.add(pos, {x = 0, y = i, z = 0})
if minetest.get_node(cpos).name ~= "air" then
return false
end
end
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)
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 goodnodes = minetest.find_nodes_in_area(minp, maxp, {"air", "group:leaves"})
if #goodnodes < totalnodes then
@ -254,7 +256,7 @@ local function apply_bone_meal(pointed_thing,user)
return ok ~= nil
end
return false
-- Wheat, Potato, Carrot, Pumpkin Stem, Melon Stem: Advance by 2-5 stages
-- Wheat, Potato, Carrot, Pumpkin Stem, Melon Stem: Advance by 2-5 stages
elseif string.find(n.name, "mcl_farming:wheat_") then
mcl_dye.add_bone_meal_particle(pos)
local stages = math.random(2, 5)
@ -284,7 +286,7 @@ local function apply_bone_meal(pointed_thing,user)
elseif string.find(n.name, "mcl_farming:sweet_berry_bush_") then
mcl_dye.add_bone_meal_particle(pos)
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
return mcl_farming:grow_plant("plant_sweet_berry_bush", pos, n, 1, true)
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
-- 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
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
minetest.add_node(pos, {name="mcl_flowers:tallgrass", param2=col})
minetest.add_node(pos, {name = "mcl_flowers:tallgrass", param2 = col})
else
local flowers_table
if mg_name == "v6" then
@ -326,7 +328,7 @@ local function apply_bone_meal(pointed_thing,user)
flowers_table = flowers_table_simple
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
@ -335,7 +337,7 @@ local function apply_bone_meal(pointed_thing,user)
end
return true
-- Double flowers: Drop corresponding item
-- Double flowers: Drop corresponding item
elseif n.name == "mcl_flowers:rose_bush" or n.name == "mcl_flowers:rose_bush_top" then
mcl_dye.add_bone_meal_particle(pos)
minetest.add_item(pos, "mcl_flowers:rose_bush")
@ -356,22 +358,30 @@ local function apply_bone_meal(pointed_thing,user)
elseif n.name == "mcl_flowers:tallgrass" then
mcl_dye.add_bone_meal_particle(pos)
-- 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)
if minetest.registered_nodes[topnode.name].buildable_to then
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(pos, {name = "mcl_flowers:double_grass", param2 = n.param2})
minetest.set_node(toppos, {name = "mcl_flowers:double_grass_top", param2 = n.param2})
return true
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
mcl_dye.add_bone_meal_particle(pos)
-- 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)
if minetest.registered_nodes[topnode.name].buildable_to then
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(pos, {name = "mcl_flowers:double_fern", param2 = n.param2})
minetest.set_node(toppos, {name = "mcl_flowers:double_fern_top", param2 = n.param2})
return true
end
end
@ -408,9 +418,9 @@ minetest.register_craftitem("mcl_dye:white", {
-- Apply bone meal, if possible
local pointed_thing
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
pointed_thing = { above = pos, under = droppos }
pointed_thing = {above = pos, under = droppos}
end
local success = apply_bone_meal(pointed_thing, nil)
if success then