From b31405307d80bed9d69b6acb8c3266215559a613 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 2 Mar 2017 16:20:19 +0100 Subject: [PATCH] Node on_rightclick: bed, bucket, lilypad, sign --- mods/ITEMS/beds/api.lua | 9 +++++++++ mods/ITEMS/bucket/init.lua | 10 +++++++++- mods/ITEMS/mcl_flowers/init.lua | 23 +++++++++++++++-------- mods/ITEMS/signs/init.lua | 9 +++++++++ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/mods/ITEMS/beds/api.lua b/mods/ITEMS/beds/api.lua index 190f46585..3452fa98f 100644 --- a/mods/ITEMS/beds/api.lua +++ b/mods/ITEMS/beds/api.lua @@ -47,6 +47,15 @@ function beds.register_bed(name, def) on_place = function(itemstack, placer, pointed_thing) local under = pointed_thing.under + + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(under) + if placer and not placer:get_player_control().sneak then + if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack + end + end + local pos if minetest.registered_items[minetest.get_node(under).name].buildable_to then pos = under diff --git a/mods/ITEMS/bucket/init.lua b/mods/ITEMS/bucket/init.lua index 53d5a1a3a..5c1bd3fd2 100644 --- a/mods/ITEMS/bucket/init.lua +++ b/mods/ITEMS/bucket/init.lua @@ -141,9 +141,17 @@ minetest.register_craftitem("bucket:bucket_empty", { if pointed_thing.type ~= "node" then return end - -- Check if pointing to a liquid source + + -- Call on_rightclick if the pointed node defines it local node = minetest.get_node(pointed_thing.under) local nn = node.name + if user and not user:get_player_control().sneak then + if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then + return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack + end + end + + -- Check if pointing to a liquid source liquiddef = bucket.liquids[nn] local new_bucket if liquiddef ~= nil and liquiddef.itemname ~= nil and (nn == liquiddef.source or diff --git a/mods/ITEMS/mcl_flowers/init.lua b/mods/ITEMS/mcl_flowers/init.lua index 035f589f6..581a4671c 100644 --- a/mods/ITEMS/mcl_flowers/init.lua +++ b/mods/ITEMS/mcl_flowers/init.lua @@ -295,18 +295,25 @@ minetest.register_node("mcl_flowers:waterlily", { on_place = function(itemstack, placer, pointed_thing) local pos = pointed_thing.above - local node = minetest.get_node(pointed_thing.under).name - local def = minetest.registered_nodes[node] + local node = minetest.get_node(pointed_thing.under) + local nodename = node.name + local def = minetest.registered_nodes[nodename] local node_above = minetest.get_node(pointed_thing.above).name local def_above = minetest.registered_nodes[node_above] local player_name = placer:get_player_name() - if def and - pointed_thing.under.x == pointed_thing.above.x and - pointed_thing.under.z == pointed_thing.above.z then - if ((def.liquidtype == "source" and minetest.get_item_group(node, "water") > 0) or - (node == "mcl_core:ice") or - (minetest.get_item_group(node, "frosted_ice") > 0)) and + if def then + -- Use pointed node's on_rightclick function first, if present + if placer and not placer:get_player_control().sneak then + if def and def.on_rightclick then + return def.on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack + end + end + + if (pointed_thing.under.x == pointed_thing.above.x and pointed_thing.under.z == pointed_thing.above.z) and + ((def.liquidtype == "source" and minetest.get_item_group(nodename, "water") > 0) or + (nodename == "mcl_core:ice") or + (minetest.get_item_group(nodename, "frosted_ice") > 0)) and (def_above.buildable_to and minetest.get_item_group(node_above, "liquid") == 0) then if not minetest.is_protected(pos, player_name) then minetest.set_node(pos, {name = "mcl_flowers:waterlily", diff --git a/mods/ITEMS/signs/init.lua b/mods/ITEMS/signs/init.lua index 8ea0c26d8..ae323c630 100644 --- a/mods/ITEMS/signs/init.lua +++ b/mods/ITEMS/signs/init.lua @@ -207,6 +207,15 @@ minetest.register_node("signs:sign_wall", { on_place = function(itemstack, placer, pointed_thing) local above = pointed_thing.above local under = pointed_thing.under + + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(under) + if placer and not placer:get_player_control().sneak then + if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack + end + end + local dir = {x = under.x - above.x, y = under.y - above.y, z = under.z - above.z}