diff options
author | TenPlus1 <kinsellaja@yahoo.com> | 2017-01-18 10:46:44 +0000 |
---|---|---|
committer | TenPlus1 <kinsellaja@yahoo.com> | 2017-01-18 10:46:44 +0000 |
commit | 3b185e00993aeafee7209f9c3025bf173e134be1 (patch) | |
tree | ef3ea29e9442a99354318b1e2da734fa1eebd13d | |
parent | cfd05614600967dd4bc6a75d0ea1520f97790348 (diff) |
added global on_use function
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | api.txt | 9 | ||||
-rw-r--r-- | init.lua | 54 |
3 files changed, 41 insertions, 23 deletions
@@ -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 @@ -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 =========== @@ -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,
|