From b68224a38d26b4e27c2169a8344de869cead64fd Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 2 Mar 2017 15:44:31 +0100 Subject: [PATCH] Spawn egg, boat, cart, book use node rightclick --- mods/ENTITIES/mobs/api.lua | 8 ++++++++ mods/ITEMS/mcl_boats/init.lua | 9 +++++++++ mods/ITEMS/mcl_books/init.lua | 20 ++++++++++++++++++++ mods/ITEMS/mcl_minecarts/init.lua | 9 +++++++++ 4 files changed, 46 insertions(+) diff --git a/mods/ENTITIES/mobs/api.lua b/mods/ENTITIES/mobs/api.lua index 8000e4876..08d9cfd32 100644 --- a/mods/ENTITIES/mobs/api.lua +++ b/mods/ENTITIES/mobs/api.lua @@ -2821,6 +2821,14 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) on_place = function(itemstack, placer, pointed_thing) + -- Call on_rightclick if the pointed node defines it + 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 pos = pointed_thing.above if pos diff --git a/mods/ITEMS/mcl_boats/init.lua b/mods/ITEMS/mcl_boats/init.lua index b50e43dc6..e0ba1526e 100644 --- a/mods/ITEMS/mcl_boats/init.lua +++ b/mods/ITEMS/mcl_boats/init.lua @@ -152,6 +152,15 @@ for w=1, #woods do if pointed_thing.type ~= "node" then return end + + -- Call on_rightclick if the pointed node defines it + 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 not is_water(pointed_thing.under) then return end diff --git a/mods/ITEMS/mcl_books/init.lua b/mods/ITEMS/mcl_books/init.lua index 0648af464..f1b79784f 100644 --- a/mods/ITEMS/mcl_books/init.lua +++ b/mods/ITEMS/mcl_books/init.lua @@ -13,6 +13,16 @@ minetest.register_craft({ }) local write = function(itemstack, user, pointed_thing) + -- Call on_rightclick if the pointed node defines it + if pointed_thing.type == "node" then + 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 + end + local text = itemstack:get_metadata() local formspec = "size[8,9]".. "background[-0.5,-0.5;9,10;mcl_books_book_bg.png]".. @@ -23,6 +33,16 @@ local write = function(itemstack, user, pointed_thing) end local read = function(itemstack, user, pointed_thing) + -- Call on_rightclick if the pointed node defines it + if pointed_thing.type == "node" then + 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 + end + local meta = minetest.deserialize(itemstack:get_metadata()) local text if meta ~= nil then diff --git a/mods/ITEMS/mcl_minecarts/init.lua b/mods/ITEMS/mcl_minecarts/init.lua index 402384a52..e2a963f93 100644 --- a/mods/ITEMS/mcl_minecarts/init.lua +++ b/mods/ITEMS/mcl_minecarts/init.lua @@ -267,6 +267,15 @@ minetest.register_craftitem("mcl_minecarts:minecart", { if not pointed_thing.type == "node" then return end + + -- Call on_rightclick if the pointed node defines it + 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 mcl_minecarts:is_rail(pointed_thing.under) then minetest.add_entity(pointed_thing.under, "mcl_minecarts:minecart") elseif mcl_minecarts:is_rail(pointed_thing.above) then