From ffeac9a1bdd7a21825fa4cfddcfce937f6792bd2 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 10 Sep 2015 09:39:59 +0200 Subject: [PATCH] fix books and swing's on_place to handle CONTENT_IGNORE and CONTENT_UNKNOWN and to always return their itemstacks --- homedecor/books.lua | 16 ++++++++-------- homedecor/exterior.lua | 11 +++++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/homedecor/books.lua b/homedecor/books.lua index 725e77a..4783cb3 100644 --- a/homedecor/books.lua +++ b/homedecor/books.lua @@ -59,15 +59,15 @@ for c in ipairs(bookcolors) do on_place = function(itemstack, placer, pointed_thing) local plname = placer:get_player_name() local pos = pointed_thing.under - local node = minetest.get_node(pos) - local n = minetest.registered_nodes[node.name] - if not n.buildable_to then + local node = minetest.get_node_or_nil(pos) + local def = node and minetest.registered_nodes[node.name] + if not def or not def.buildable_to then pos = pointed_thing.above - node = minetest.get_node(pos) - n = minetest.registered_nodes[node.name] - if not n.buildable_to then return end + node = minetest.get_node_or_nil(pos) + def = node and minetest.registered_nodes[node.name] + if not def or not def.buildable_to then return itemstack 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()) minetest.set_node(pos, { name = "homedecor:book_"..color, @@ -89,7 +89,7 @@ for c in ipairs(bookcolors) do if data.title and data.title ~= "" then meta:set_string("infotext", data.title) end - if not minetest.setting_getbool("creative_mode") then + if not homedecor.expect_infinite_stacks then itemstack:take_item() end return itemstack diff --git a/homedecor/exterior.lua b/homedecor/exterior.lua index 97307dc..21573fa 100644 --- a/homedecor/exterior.lua +++ b/homedecor/exterior.lua @@ -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... height = i local testpos = { x=pos.x, y=pos.y-i-1, z=pos.z } - local testnode = minetest.get_node(testpos) - local testreg = core.registered_nodes[testnode.name] + local testnode = minetest.get_node_or_nil(testpos) + 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 minetest.chat_send_player(placer:get_player_name(), "No room under there to hang a swing.") - return + return itemstack else break end @@ -274,12 +274,11 @@ homedecor.register("swing", { if not homedecor.expect_infinite_stacks then itemstack:take_item() - return itemstack end - 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.") end + return itemstack end, after_dig_node = function(pos, oldnode, oldmetadata, digger) for i = 0, 4 do