Replace deprecated itemstack metadata methods with up to date ones and add book description naming

This commit is contained in:
KaadmY 2017-07-04 11:42:22 -07:00
parent 476a723aab
commit a0a1a61692

View File

@ -7,9 +7,10 @@
minetest.register_craftitem( minetest.register_craftitem(
":default:book", ":default:book",
{ {
description = "Book", description = "Unnamed Book",
inventory_image = "default_book.png", inventory_image = "default_book.png",
stack_max = 1, stack_max = 1,
on_use = function(itemstack, player, pointed_thing) on_use = function(itemstack, player, pointed_thing)
local name = player:get_player_name() local name = player:get_player_name()
local data = minetest.deserialize(itemstack:get_metadata()) local data = minetest.deserialize(itemstack:get_metadata())
@ -36,13 +37,14 @@ minetest.register_on_player_receive_fields(
if form_name ~= "book:book" or not fields.write then return end if form_name ~= "book:book" or not fields.write then return end
local itemstack = player:get_wielded_item() local itemstack = player:get_wielded_item()
local data = minetest.deserialize(itemstack:get_metadata())
if not data then data = {} end local meta = itemstack:get_meta()
data.text = fields.text
data.title = fields.title meta:set_string("description", fields.title) -- Set the item description
meta:set_string("book:title", fields.title)
meta:set_string("book:text", fields.text)
itemstack:set_metadata(minetest.serialize(data))
player:set_wielded_item(itemstack) player:set_wielded_item(itemstack)
end) end)