From 01200e921437462f49c361a701b5ab8a750e86e4 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 1 Apr 2017 02:29:36 +0200 Subject: [PATCH] Implement proper bone meal behaviour for saplings --- mods/ITEMS/mcl_core/functions.lua | 27 +++++++++++++++++++++++++++ mods/ITEMS/mcl_dye/init.lua | 9 +++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index 931951c4f7..831168cb67 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -434,6 +434,33 @@ local sapling_grow_action = function(trunknode, leafnode, tree_id, soil_needed) end end +-- Attempts to grow the sapling at the specified position +-- pos: Position +-- node: Node table of the node at this position, from minetest.get_node +-- Returns true on success and false on failure +mcl_core.grow_sapling = function(pos, node) + local grow + if node.name == "mcl_core:sapling" then + grow = sapling_grow_action("mcl_core:tree", "mcl_core:leaves", 1, 1) + elseif node.name == "mcl_core:darksapling" then + grow = sapling_grow_action("mcl_core:darktree", "mcl_core:darkleaves", 1, 2) + elseif node.name == "mcl_core:junglesapling" then + grow = sapling_grow_action("mcl_core:jungletree", "mcl_core:jungleleaves", 1, 2) + elseif node.name == "mcl_core:acaciasapling" then + grow = sapling_grow_action("mcl_core:acaciatree", "mcl_core:acacialeaves", 1, 2) + elseif node.name == "mcl_core:sprucesapling" then + grow = sapling_grow_action("mcl_core:sprucetree", "mcl_core:spruceleaves", 1, 1) + elseif node.name == "mcl_core:birchsapling" then + grow = sapling_grow_action("mcl_core:birchtree", "mcl_core:birchleaves", 1, 1) + end + if grow then + grow(pos) + return true + else + return false + end +end + -- TODO: Use better tree models for everything -- TODO: Support 2×2 saplings diff --git a/mods/ITEMS/mcl_dye/init.lua b/mods/ITEMS/mcl_dye/init.lua index ec0ff41310..9122453982 100644 --- a/mods/ITEMS/mcl_dye/init.lua +++ b/mods/ITEMS/mcl_dye/init.lua @@ -128,10 +128,11 @@ mcl_dye.apply_bone_meal = function(pointed_thing) n = minetest.get_node(pos) if n.name == "" then return false end local stage = "" - if n.name == "mcl_core:sapling" then - minetest.add_node(pos, {name="air"}) - mcl_core.generate_tree(pos, "mcl_core:tree", "mcl_core:leaves", 1) - return true + if minetest.get_item_group(n.name, "sapling") >= 1 then + -- 45% chance to advance growth stage of sapling + if math.random(1,100) <= 45 then + return mcl_core.grow_sapling(pos, n) + end elseif string.find(n.name, "mcl_farming:wheat_") ~= nil then stage = string.sub(n.name, -1) if stage == "3" then