Let right-click handler override seed placement

A customer on_place_node is used for seed planting. This change lets a
node with a custom right-click handler get called instead (as it would
normally) before the seed placement is done. This allows the placement
of seeds in various contains that rely on this, e.g. barrels, item
frames, without impacting on the actual use of the seeds.

Additionally, on_place_node the handler is moved to a common location
rather than being duplicated across every file.
master
Ciaran Gultnieks 2014-03-09 21:56:38 +00:00 committed by Vanessa Ezekowitz
parent fa1e9b0454
commit 94c261b8a4
1 changed files with 13 additions and 0 deletions

View File

@ -155,6 +155,7 @@ farming.seeds = {
["farming_plus:carrot_seed"]=30,
}
-- ========= GENERATE PLANTS IN THE MAP =========
minetest.register_on_generated(function(minp, maxp, seed)
if maxp.y >= 2 and minp.y <= 0 then
@ -210,6 +211,18 @@ minetest.register_on_generated(function(minp, maxp, seed)
end)
function farming:place_seed(itemstack, placer, pointed_thing, plantname)
-- Call on_rightclick if the pointed node defines it
if pointed_thing.type == "node" and placer and
not placer:get_player_control().sneak then
local n = minetest.get_node(pointed_thing.under)
local nn = n.name
if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then
return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, n,
placer, itemstack, pointed_thing) or itemstack, false
end
end
local pt = pointed_thing
-- check if pointing at a node
if not pt then