summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTenPlus1 <kinsellaja@yahoo.com>2017-01-18 10:46:44 +0000
committerTenPlus1 <kinsellaja@yahoo.com>2017-01-18 10:46:44 +0000
commit3b185e00993aeafee7209f9c3025bf173e134be1 (patch)
treeef3ea29e9442a99354318b1e2da734fa1eebd13d
parentcfd05614600967dd4bc6a75d0ea1520f97790348 (diff)
added global on_use function
-rw-r--r--README.md1
-rw-r--r--api.txt9
-rw-r--r--init.lua54
3 files changed, 41 insertions, 23 deletions
diff --git a/README.md b/README.md
index 2e94b37..2671dd1 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/api.txt b/api.txt
index 7e51368..9892887 100644
--- a/api.txt
+++ b/api.txt
@@ -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
===========
diff --git a/init.lua b/init.lua
index 5ecd3e7..883517c 100644
--- a/init.lua
+++ b/init.lua
@@ -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,