mirror of
https://github.com/minetest-mods/digtron.git
synced 2024-12-22 12:22:22 +01:00
Use new style of itemstack metadata to show description in inventory
This commit is contained in:
parent
4b810fc584
commit
0b4ec531c7
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user