From 567d1129422abf0ec552af7c4bae23302cee81e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski?= Date: Sat, 13 Jul 2024 10:48:03 +0700 Subject: [PATCH] Fix deprecated get_metadata() usage Items are instead written as a serialized string into ItemStackMetaRef, and read from there as well. Old itemstacks get converted to the new format automatically. --- mods/ITEMS/mcl_chests/shulkers.lua | 36 +++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/mods/ITEMS/mcl_chests/shulkers.lua b/mods/ITEMS/mcl_chests/shulkers.lua index ac10cbb0d..b6ada6c46 100644 --- a/mods/ITEMS/mcl_chests/shulkers.lua +++ b/mods/ITEMS/mcl_chests/shulkers.lua @@ -136,12 +136,20 @@ for color, desc in pairs(boxtypes) do end, after_place_node = function(pos, placer, itemstack, pointed_thing) local nmeta = minetest.get_meta(pos) - local imetadata = itemstack:get_metadata() - local iinv_main = minetest.deserialize(imetadata) + local imeta = itemstack:get_meta() + + -- Convert old itemstacks to not use get_metadata() + if not imeta:contains("inv") and + (itemstack:get_metadata() ~= "") then + imeta:set_string("inv", itemstack:get_metadata()) + itemstack:set_metadata("") -- clear + end + + local iinv_main = minetest.deserialize(imeta:get_string("inv")) local ninv = nmeta:get_inventory() ninv:set_list("main", iinv_main) ninv:set_size("main", 9 * 3) - set_shulkerbox_meta(nmeta, itemstack:get_meta()) + set_shulkerbox_meta(nmeta, imeta) if minetest.is_creative_enabled(placer:get_player_name()) then if not ninv:is_empty("main") then @@ -158,11 +166,11 @@ for color, desc in pairs(boxtypes) do if minetest.registered_nodes[dropnode.name].buildable_to then minetest.set_node(droppos, { name = small_name, param2 = minetest.dir_to_facedir(dropdir) }) local ninv = minetest.get_inventory({ type = "node", pos = droppos }) - local imetadata = stack:get_metadata() - local iinv_main = minetest.deserialize(imetadata) + local imeta = stack:get_meta() + local iinv_main = minetest.deserialize(imeta:get_string("inv")) ninv:set_list("main", iinv_main) ninv:set_size("main", 9 * 3) - set_shulkerbox_meta(minetest.get_meta(droppos), stack:get_meta()) + set_shulkerbox_meta(minetest.get_meta(droppos), imeta) stack:take_item() end return stack @@ -213,12 +221,20 @@ for color, desc in pairs(boxtypes) do end, after_place_node = function(pos, placer, itemstack, pointed_thing) local nmeta = minetest.get_meta(pos) - local imetadata = itemstack:get_metadata() - local iinv_main = minetest.deserialize(imetadata) + local imeta = itemstack:get_meta() + + -- Convert old itemstacks to not use get_metadata() + if not imeta:contains("inv") and + (itemstack:get_metadata() ~= "") then + imeta:set_string("inv", itemstack:get_metadata()) + itemstack:set_metadata("") -- clear + end + + local iinv_main = minetest.deserialize(imeta:get_string("inv")) local ninv = nmeta:get_inventory() ninv:set_list("main", iinv_main) ninv:set_size("main", 9 * 3) - set_shulkerbox_meta(nmeta, itemstack:get_meta()) + set_shulkerbox_meta(nmeta, imeta) if minetest.is_creative_enabled(placer:get_player_name()) then if not ninv:is_empty("main") then @@ -252,7 +268,7 @@ for color, desc in pairs(boxtypes) do local boxitem_meta = boxitem:get_meta() boxitem_meta:set_string("description", meta:get_string("description")) boxitem_meta:set_string("name", meta:get_string("name")) - boxitem:set_metadata(data) + boxitem_meta:set_string("inv", data) if minetest.is_creative_enabled("") then if not inv:is_empty("main") then