Always return the leftover ItemStack for on_place and on_rightclick

This commit is contained in:
Tim 2016-07-01 22:43:02 +02:00 committed by paramat
parent e38099225c
commit 71c7e21669
6 changed files with 20 additions and 15 deletions

View File

@ -91,8 +91,9 @@ function beds.register_bed(name, def)
destruct_bed(pos, 1)
end,
on_rightclick = function(pos, node, clicker)
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
beds.on_rightclick(pos, clicker)
return itemstack
end,
on_rotate = function(pos, node, user, mode, new_param2)

View File

@ -224,10 +224,10 @@ minetest.register_craftitem("boats:boat", {
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return
return itemstack
end
if not is_water(pointed_thing.under) then
return
return itemstack
end
pointed_thing.under.y = pointed_thing.under.y + 0.5
minetest.add_entity(pointed_thing.under, "boats:boat")

View File

@ -1612,7 +1612,7 @@ minetest.register_node("default:chest_locked", {
" takes " .. stack:get_name() ..
" from locked chest at " .. minetest.pos_to_string(pos))
end,
on_rightclick = function(pos, node, clicker)
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
if has_locked_chest_privilege(meta, clicker) then
minetest.show_formspec(
@ -1621,6 +1621,7 @@ minetest.register_node("default:chest_locked", {
get_locked_chest_formspec(pos)
)
end
return itemstack
end,
on_blast = function() end,
})

View File

@ -373,8 +373,9 @@ function doors.register(name, def)
sounds = { def.sound_close, def.sound_open },
}
def.on_rightclick = function(pos, node, clicker)
def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
_doors.door_toggle(pos, clicker)
return itemstack
end
def.after_dig_node = function(pos, node, meta, digger)
minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
@ -547,8 +548,9 @@ function doors.register_trapdoor(name, def)
return meta:get_string("doors_owner") == pn
end
def.on_rightclick = function(pos, node, clicker)
def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
_doors.trapdoor_toggle(pos, clicker)
return itemstack
end
-- Common trapdoor configuration
@ -681,12 +683,13 @@ function doors.register_fencegate(name, def)
connect_sides = {"left", "right"},
groups = def.groups,
sounds = def.sounds,
on_rightclick = function(pos, clicker)
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local node = minetest.get_node(pos)
local node_def = minetest.registered_nodes[node.name]
minetest.swap_node(pos, {name = node_def.gate, param2 = node.param2})
minetest.sound_play(node_def.sound, {pos = pos, gain = 0.3,
max_hear_distance = 8})
return itemstack
end,
selection_box = {
type = "fixed",

View File

@ -133,10 +133,10 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
local pt = pointed_thing
-- check if pointing at a node
if not pt then
return
return itemstack
end
if pt.type ~= "node" then
return
return itemstack
end
local under = minetest.get_node(pt.under)
@ -153,25 +153,25 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
-- return if any of the nodes is not registered
if not minetest.registered_nodes[under.name] then
return
return itemstack
end
if not minetest.registered_nodes[above.name] then
return
return itemstack
end
-- check if pointing at the top of the node
if pt.above.y ~= pt.under.y+1 then
return
return itemstack
end
-- check if you can replace the node above the pointed node
if not minetest.registered_nodes[above.name].buildable_to then
return
return itemstack
end
-- check if pointing at soil
if minetest.get_item_group(under.name, "soil") < 2 then
return
return itemstack
end
-- add the node and remove 1 item from the itemstack

View File

@ -251,8 +251,8 @@ minetest.register_node("flowers:waterlily", {
end
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
return itemstack
end
end
return itemstack
end
})