From 0b4ec531c76f83509f4f18a35a09d7c3ff197683 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Fri, 5 Jul 2019 23:50:55 -0600 Subject: [PATCH] Use new style of itemstack metadata to show description in inventory --- nodes/node_crate.lua | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/nodes/node_crate.lua b/nodes/node_crate.lua index 653a95d..196b21f 100644 --- a/nodes/node_crate.lua +++ b/nodes/node_crate.lua @@ -263,9 +263,11 @@ end local loaded_on_dig = function(pos, player, loaded_node_name) local meta = minetest.get_meta(pos) - local to_serialize = {title=meta:get_string("title"), layout=meta:get_string("crated_layout")} - - local stack = ItemStack({name=loaded_node_name, count=1, wear=0, metadata=minetest.serialize(to_serialize)}) + + local stack = ItemStack({name=loaded_node_name, count=1, wear=0}) + local stack_meta = stack:get_meta() + stack_meta:set_string("crated_layout", meta:get_string("crated_layout")) + stack_meta:set_string("description", meta:get_string("title")) local inv = player:get_inventory() local stack = inv:add_item("main", stack) if stack:get_count() > 0 then @@ -276,13 +278,28 @@ local loaded_on_dig = function(pos, player, loaded_node_name) end local loaded_after_place = function(pos, itemstack) - local deserialized = minetest.deserialize(itemstack:get_metadata()) - if deserialized then + + -- Older versions of Digtron used this deprecated method for saving layout data on items. + -- Maintain backward compatibility here. + local deprecated_metadata = itemstack:get_metadata() + if deprecated_metadata ~= "" then + deprecated_metadata = minetest.deserialize(deprecated_metadata) + local meta = minetest.get_meta(pos) + meta:set_string("crated_layout", deprecated_metadata.layout) + meta:set_string("title", deprecated_metadata.title) + meta:set_string("infotext", deprecated_metadata.title) + return + end + + local stack_meta = itemstack:get_meta() + local layout = stack_meta:get_string("crated_layout") + local title = stack_meta:get_string("description") + if layout ~= "" then local meta = minetest.get_meta(pos) - meta:set_string("crated_layout", deserialized.layout) - meta:set_string("title", deserialized.title) - meta:set_string("infotext", deserialized.title) + meta:set_string("crated_layout", layout) + meta:set_string("title", title) + meta:set_string("infotext", title) --meta:set_string("formspec", loaded_formspec(pos, meta)) -- not needed, on_construct handles this end end