diff options
Diffstat (limited to 'beanpole.lua')
-rw-r--r-- | beanpole.lua | 81 |
1 files changed, 52 insertions, 29 deletions
diff --git a/beanpole.lua b/beanpole.lua index f06aea5..fd93383 100644 --- a/beanpole.lua +++ b/beanpole.lua @@ -6,46 +6,69 @@ local S = farming.intllib --- beans -minetest.register_craftitem("farming:beans", { - description = S("Green Beans"), - inventory_image = "farming_beans.png", - on_use = minetest.item_eat(1), +-- place beans +function place_beans(itemstack, placer, pointed_thing, plantname) - on_place = function(itemstack, placer, pointed_thing) + local pt = pointed_thing - if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then - return - end + -- check if pointing at a node + if not pt or pt.type ~= "node" then - local nodename = minetest.get_node(pointed_thing.under).name + return + end - if nodename == "farming:beanpole" then - minetest.set_node(pointed_thing.under, {name = "farming:beanpole_1"}) + local under = minetest.get_node(pt.under) - minetest.sound_play("default_place_node", {pos = pointed_thing.above, gain = 1.0}) - else - return - end + -- return if any of the nodes are not registered + if not minetest.registered_nodes[under.name] then + return + end - if not minetest.setting_getbool("creative_mode") then + -- am I right-clicking on something that has a custom on_place set? + -- thanks to Krock for helping with this issue :) + local def = minetest.registered_nodes[under.name] + if def and def.on_rightclick then + return def.on_rightclick(pt.under, under, placer, itemstack) + end - itemstack:take_item() + -- check if pointing at bean pole + if under.name ~= "farming:beanpole" then + return + end - -- check for refill - if itemstack:get_count() == 0 then + -- add the node and remove 1 item from the itemstack + minetest.set_node(pt.under, {name = plantname}) - minetest.after(0.20, - farming.refill_plant, - placer, - "farming:beans", - placer:get_wield_index() - ) - end - end + minetest.sound_play("default_place_node", {pos = pt.under, gain = 1.0}) - return itemstack + if not minetest.setting_getbool("creative_mode") then + + itemstack:take_item() + + -- check for refill + if itemstack:get_count() == 0 then + + minetest.after(0.20, + farming.refill_plant, + placer, + "farming:beans", + placer:get_wield_index() + ) + end end + + return itemstack +end + +-- beans +minetest.register_craftitem("farming:beans", { + description = S("Green Beans"), + inventory_image = "farming_beans.png", + on_use = minetest.item_eat(1), + + on_place = function(itemstack, placer, pointed_thing) + return place_beans(itemstack, placer, pointed_thing, "farming:beanpole_1") + end, }) -- beans can be used for green dye |