fix books and swing's on_place to handle CONTENT_IGNORE and CONTENT_UNKNOWN and to always return their itemstacks

This commit is contained in:
Tim 2015-09-10 09:39:59 +02:00
parent 40431fc050
commit ffeac9a1bd
2 changed files with 13 additions and 14 deletions

View File

@ -59,15 +59,15 @@ for c in ipairs(bookcolors) do
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local plname = placer:get_player_name() local plname = placer:get_player_name()
local pos = pointed_thing.under local pos = pointed_thing.under
local node = minetest.get_node(pos) local node = minetest.get_node_or_nil(pos)
local n = minetest.registered_nodes[node.name] local def = node and minetest.registered_nodes[node.name]
if not n.buildable_to then if not def or not def.buildable_to then
pos = pointed_thing.above pos = pointed_thing.above
node = minetest.get_node(pos) node = minetest.get_node_or_nil(pos)
n = minetest.registered_nodes[node.name] def = node and minetest.registered_nodes[node.name]
if not n.buildable_to then return end if not def or not def.buildable_to then return itemstack end
end end
if minetest.is_protected(pos, plname) then return end if minetest.is_protected(pos, plname) then return itemstack end
local fdir = minetest.dir_to_facedir(placer:get_look_dir()) local fdir = minetest.dir_to_facedir(placer:get_look_dir())
minetest.set_node(pos, { minetest.set_node(pos, {
name = "homedecor:book_"..color, name = "homedecor:book_"..color,
@ -89,7 +89,7 @@ for c in ipairs(bookcolors) do
if data.title and data.title ~= "" then if data.title and data.title ~= "" then
meta:set_string("infotext", data.title) meta:set_string("infotext", data.title)
end end
if not minetest.setting_getbool("creative_mode") then if not homedecor.expect_infinite_stacks then
itemstack:take_item() itemstack:take_item()
end end
return itemstack return itemstack

View File

@ -249,13 +249,13 @@ homedecor.register("swing", {
for i = 0, 4 do -- search up to 5 spaces downward from the ceiling for the first non-buildable-to node... for i = 0, 4 do -- search up to 5 spaces downward from the ceiling for the first non-buildable-to node...
height = i height = i
local testpos = { x=pos.x, y=pos.y-i-1, z=pos.z } local testpos = { x=pos.x, y=pos.y-i-1, z=pos.z }
local testnode = minetest.get_node(testpos) local testnode = minetest.get_node_or_nil(testpos)
local testreg = core.registered_nodes[testnode.name] local testreg = testnode and core.registered_nodes[testnode.name]
if not testreg.buildable_to then if not testreg or not testreg.buildable_to then
if i < 1 then if i < 1 then
minetest.chat_send_player(placer:get_player_name(), "No room under there to hang a swing.") minetest.chat_send_player(placer:get_player_name(), "No room under there to hang a swing.")
return return itemstack
else else
break break
end end
@ -274,12 +274,11 @@ homedecor.register("swing", {
if not homedecor.expect_infinite_stacks then if not homedecor.expect_infinite_stacks then
itemstack:take_item() itemstack:take_item()
return itemstack
end end
else else
minetest.chat_send_player(placer:get_player_name(), "You have to point at the bottom side of an overhanging object to place a swing.") minetest.chat_send_player(placer:get_player_name(), "You have to point at the bottom side of an overhanging object to place a swing.")
end end
return itemstack
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
for i = 0, 4 do for i = 0, 4 do