From 9cb2f5b392837c831c6e8b769c8d4e0cfcec61fd Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 2 Mar 2017 16:09:13 +0100 Subject: [PATCH] Make more items respect the node's on_rightclick - Bone meal - Fishing rod - Seeds - Hopper - Nether wart - Sponge - Bow - Shovel --- mods/ITEMS/mcl_dye/init.lua | 9 +++++++++ mods/ITEMS/mcl_farming/init.lua | 8 ++++++++ mods/ITEMS/mcl_fishing/init.lua | 7 +++++++ mods/ITEMS/mcl_hoppers/init.lua | 11 ++++++++++- mods/ITEMS/mcl_nether/nether_wart.lua | 11 ++++++++++- mods/ITEMS/mcl_sponges/init.lua | 9 +++++++++ mods/ITEMS/mcl_throwing/init.lua | 10 ++++++++++ mods/ITEMS/mcl_tools/init.lua | 10 +++++++++- 8 files changed, 72 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_dye/init.lua b/mods/ITEMS/mcl_dye/init.lua index 4b66f290..4f132324 100644 --- a/mods/ITEMS/mcl_dye/init.lua +++ b/mods/ITEMS/mcl_dye/init.lua @@ -217,6 +217,15 @@ minetest.register_craftitem("mcl_dye:white", { stack_max = 64, groups = dyelocal.dyes[1][3], on_place = function(itemstack, user, pointed_thing) + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(pointed_thing.under) + if user and not user: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, user, itemstack) or itemstack + end + end + + -- Use the bone meal on the ground if(mcl_dye.apply_bone_meal(pointed_thing) and not minetest.setting_getbool("creative_mode")) then itemstack:take_item() end diff --git a/mods/ITEMS/mcl_farming/init.lua b/mods/ITEMS/mcl_farming/init.lua index ec993b01..0857c77b 100644 --- a/mods/ITEMS/mcl_farming/init.lua +++ b/mods/ITEMS/mcl_farming/init.lua @@ -46,6 +46,14 @@ function mcl_farming:place_seed(itemstack, placer, pointed_thing, plantname) if pt.type ~= "node" then return end + + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(pt.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(pt.under, node, placer, itemstack) or itemstack + end + end local pos = {x=pt.above.x, y=pt.above.y-1, z=pt.above.z} local farmland = minetest.get_node(pos) diff --git a/mods/ITEMS/mcl_fishing/init.lua b/mods/ITEMS/mcl_fishing/init.lua index 9d475a42..7719f95c 100644 --- a/mods/ITEMS/mcl_fishing/init.lua +++ b/mods/ITEMS/mcl_fishing/init.lua @@ -1,6 +1,13 @@ local go_fishing = function(itemstack, user, pointed_thing) if pointed_thing and pointed_thing.under then + -- Use pointed node's on_rightclick function first, if present local node = minetest.get_node(pointed_thing.under) + if user and not user: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, user, itemstack) or itemstack + end + end + if string.find(node.name, "mcl_core:water") then local itemname local itemcount = 1 diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index cdfeb5ff..1699c51d 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -48,8 +48,17 @@ minetest.register_node("mcl_hoppers:hopper", { local upos = pointed_thing.under local apos = pointed_thing.above + local uposnode = minetest.get_node(upos) + local uposnodedef = minetest.registered_nodes[uposnode.name] + + -- Use pointed node's on_rightclick function first, if present + if placer and not placer:get_player_control().sneak then + if uposnodedef and uposnodedef.on_rightclick then + return uposnodedef.on_rightclick(pointed_thing.under, uposnode, placer, itemstack) or itemstack + end + end + local bpos - local uposnodedef = minetest.registered_nodes[minetest.get_node(upos).name] if uposnodedef.buildable_to then bpos = upos else diff --git a/mods/ITEMS/mcl_nether/nether_wart.lua b/mods/ITEMS/mcl_nether/nether_wart.lua index b600f54b..74b838f3 100644 --- a/mods/ITEMS/mcl_nether/nether_wart.lua +++ b/mods/ITEMS/mcl_nether/nether_wart.lua @@ -74,13 +74,22 @@ minetest.register_node("mcl_nether:nether_wart", { }) minetest.register_craftitem("mcl_nether:nether_wart_item", { - description = "Nether Wart", + descripointed_thingption = "Nether Wart", inventory_image = "mcl_nether_nether_wart.png", wield_image = "mcl_nether_nether_wart.png", on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return itemstack end + + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(pointed_thing.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 placepos = pointed_thing.above local soilpos = table.copy(placepos) soilpos.y = soilpos.y - 1 diff --git a/mods/ITEMS/mcl_sponges/init.lua b/mods/ITEMS/mcl_sponges/init.lua index ad73f7e1..026458da 100644 --- a/mods/ITEMS/mcl_sponges/init.lua +++ b/mods/ITEMS/mcl_sponges/init.lua @@ -16,6 +16,15 @@ minetest.register_node("mcl_sponges:sponge", { if pointed_thing.type ~= "node" then return itemstack end + + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(pointed_thing.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 + if minetest.is_protected(pointed_thing.above, pn) then return itemstack end diff --git a/mods/ITEMS/mcl_throwing/init.lua b/mods/ITEMS/mcl_throwing/init.lua index 83133d98..7962cb60 100644 --- a/mods/ITEMS/mcl_throwing/init.lua +++ b/mods/ITEMS/mcl_throwing/init.lua @@ -72,6 +72,16 @@ end local powerup_function = function(nextbow) return function(itemstack, placer, pointed_thing) + -- Use pointed node's on_rightclick function first, if present + if pointed_thing.type == "node" then + local node = minetest.get_node(pointed_thing.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 + end + if get_arrow(placer) ~= nil then local wear = itemstack:get_wear() itemstack:replace(nextbow) diff --git a/mods/ITEMS/mcl_tools/init.lua b/mods/ITEMS/mcl_tools/init.lua index 6869d8c6..a6ba4519 100644 --- a/mods/ITEMS/mcl_tools/init.lua +++ b/mods/ITEMS/mcl_tools/init.lua @@ -142,7 +142,15 @@ local get_shovel_dig_group = function(itemstring) end local make_grass_path = function(itemstack, placer, pointed_thing) - if minetest.get_node(pointed_thing.under).name == "mcl_tools:dirt_with_grass" and pointed_thing.above.y == pointed_thing.under.y then + -- Use pointed node's on_rightclick function first, if present + local node = minetest.get_node(pointed_thing.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 + + if minetest.get_node(node).name == "mcl_tools:dirt_with_grass" and pointed_thing.above.y == pointed_thing.under.y then local above = table.copy(pointed_thing.under) above.y = above.y + 1 if minetest.get_node(above).name == "air" then