added global on_use function

This commit is contained in:
TenPlus1 2017-01-18 10:46:44 +00:00
parent cfd0561460
commit 3b185e0099
3 changed files with 41 additions and 23 deletions

View File

@ -16,3 +16,4 @@ https://forum.minetest.net/viewtopic.php?f=9&t=16446
Changelog:
- 0.1 - Initial release
- 0.2 - Added global on_use function for bonemeal growth

View File

@ -53,6 +53,15 @@ bonemeal:add_deco({"default:dirt_with_dry_grass", {"default:dry_grass_1", "air"}
{"flowers:rose", "flowers:viola"} })
Global ON_USE Function
----------------------
bonemeal:on_use(pos)
This function can be called from other mods to grow plants using alternative
bonemeal items and have the same effect.
Final Words
===========

View File

@ -257,6 +257,35 @@ local function check_soil(pos, nodename)
end
end
-- global on_use function for bonemeal
function bonemeal:on_use(pos)
-- get node pointed at
local node = minetest.get_node(pos)
-- return if nothing there
if node.name == "ignore" then
return
end
-- check for tree growth if pointing at sapling
if minetest.get_item_group(node.name, "sapling") > 0 then
check_sapling(pos, node.name)
return
end
-- check for crop growth
check_crops(pos, node.name)
-- grow grass and flowers
if minetest.get_item_group(node.name, "soil") > 0
or minetest.get_item_group(node.name, "sand") > 0 then
check_soil(pos, node.name)
end
end
----- items
-- bonemeal item
@ -281,29 +310,8 @@ minetest.register_craftitem("bonemeal:bonemeal", {
itemstack:take_item()
end
-- get position and node
local pos = pointed_thing.under
local node = minetest.get_node(pos)
-- return if nothing there
if node.name == "ignore" then
return
end
-- check for tree growth if pointing at sapling
if minetest.get_item_group(node.name, "sapling") > 0 then
check_sapling(pos, node.name)
return
end
-- check for crop growth
check_crops(pos, node.name)
-- grow grass and flowers
if minetest.get_item_group(node.name, "soil") > 0
or minetest.get_item_group(node.name, "sand") > 0 then
check_soil(pos, node.name)
end
-- get position and call global on_use function
bonemeal:on_use(pointed_thing.under)
return itemstack
end,