Set infotext to the book's title.

Also use `swap_node` to avoid losing metadata on (placed)
book open/close.
This commit is contained in:
Diego Martinez 2015-01-23 14:25:01 -03:00
parent 0c7dfa9ba6
commit 2cdf6667dc

View File

@ -1947,7 +1947,7 @@ minetest.register_node("homedecor:book_"..color, {
}, },
on_rightclick = function(pos, node, clicker) on_rightclick = function(pos, node, clicker)
local fdir = node.param2 local fdir = node.param2
minetest.set_node(pos, { name = "homedecor:book_open_"..color, param2 = fdir }) minetest.swap_node(pos, { name = "homedecor:book_open_"..color, param2 = fdir })
end, end,
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()
@ -1969,6 +1969,10 @@ minetest.register_node("homedecor:book_"..color, {
local text = itemstack:get_metadata() or "" local text = itemstack:get_metadata() or ""
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("text", text) meta:set_string("text", text)
local data = minetest.deserialize(text) or {}
if data.title and data.title ~= "" then
meta:set_string("infotext", data.title)
end
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
itemstack:take_item() itemstack:take_item()
end end
@ -2024,7 +2028,7 @@ minetest.register_node("homedecor:book_open_"..color, {
on_dig = book_dig, on_dig = book_dig,
on_rightclick = function(pos, node, clicker) on_rightclick = function(pos, node, clicker)
local fdir = node.param2 local fdir = node.param2
minetest.set_node(pos, { name = "homedecor:book_"..color, param2 = fdir }) minetest.swap_node(pos, { name = "homedecor:book_"..color, param2 = fdir })
end, end,
}) })