Skip to content

Commit

Permalink
Allow interaction with nodes while wielding these items.
Browse files Browse the repository at this point in the history
- beds
- boats
- carts
- key/skeleton key
- seeds

All these had on_place handlers that did not allow nodes with
an on_rightclick() handler to be used first (if not using
sneak). This code is taken from the torches mod and applied
everywhere.

This allows all these items to e.g. be inserted into the `frame`
mod's item frames.
  • Loading branch information
sofar committed Mar 1, 2017
1 parent d1b1325 commit 78c632e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
8 changes: 8 additions & 0 deletions mods/beds/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ function beds.register_bed(name, def)

on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local node = minetest.get_node(under)
local udef = minetest.registered_nodes[node.name]
if udef and udef.on_rightclick and
not (placer and placer:get_player_control().sneak) then
return udef.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack
end

local pos
if minetest.registered_items[minetest.get_node(under).name].buildable_to then
pos = under
Expand Down
9 changes: 9 additions & 0 deletions mods/boats/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ minetest.register_craftitem("boats:boat", {
groups = {flammable = 2},

on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local node = minetest.get_node(under)
local udef = minetest.registered_nodes[node.name]
if udef and udef.on_rightclick and
not (placer and placer:get_player_control().sneak) then
return udef.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack
end

if pointed_thing.type ~= "node" then
return itemstack
end
Expand Down
9 changes: 9 additions & 0 deletions mods/carts/cart_entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,15 @@ minetest.register_craftitem("carts:cart", {
inventory_image = minetest.inventorycube("carts_cart_top.png", "carts_cart_side.png", "carts_cart_side.png"),
wield_image = "carts_cart_side.png",
on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local node = minetest.get_node(under)
local udef = minetest.registered_nodes[node.name]
if udef and udef.on_rightclick and
not (placer and placer:get_player_control().sneak) then
return udef.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack
end

if not pointed_thing.type == "node" then
return
end
Expand Down
21 changes: 19 additions & 2 deletions mods/default/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,21 @@ minetest.register_tool("default:skeleton_key", {
inventory_image = "default_key_skeleton.png",
groups = {key = 1},
on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local node = minetest.get_node(under)
local def = minetest.registered_nodes[node.name]
if def and def.on_rightclick and
not (placer and placer:get_player_control().sneak) then
return def.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack
end

if pointed_thing.type ~= "node" then
return itemstack
end

local pos = pointed_thing.under
local node = minetest.get_node(pos)
node = minetest.get_node(pos)

if not node then
return itemstack
Expand Down Expand Up @@ -427,12 +436,20 @@ minetest.register_tool("default:key", {
groups = {key = 1, not_in_creative_inventory = 1},
stack_max = 1,
on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local node = minetest.get_node(under)
local def = minetest.registered_nodes[node.name]
if def and def.on_rightclick and
not (placer and placer:get_player_control().sneak) then
return def.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack
end
if pointed_thing.type ~= "node" then
return itemstack
end

local pos = pointed_thing.under
local node = minetest.get_node(pos)
node = minetest.get_node(pos)

if not node or node.name == "ignore" then
return itemstack
Expand Down
9 changes: 9 additions & 0 deletions mods/farming/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,15 @@ farming.register_plant = function(name, def)
}),

on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local node = minetest.get_node(under)
local udef = minetest.registered_nodes[node.name]
if udef and udef.on_rightclick and
not (placer and placer:get_player_control().sneak) then
return udef.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack
end

return farming.place_seed(itemstack, placer, pointed_thing, mname .. ":seed_" .. pname)
end,
next_plant = mname .. ":" .. pname .. "_1",
Expand Down

0 comments on commit 78c632e

Please sign in to comment.