Books: Fix backwards compatibility issues
authoroctacian <enduffy2014@outlook.com>
Tue, 14 Mar 2017 05:28:03 +0000 (22:28 -0700)
committerparamat <mat.gregory@virginmedia.com>
Mon, 20 Mar 2017 00:13:31 +0000 (00:13 +0000)
Commit c68b8274fed183f30bd7609018766a261448b83d prevented books from
being copied in the crafting grid, and made it so that old books, though
seemingly successfully transferred to the new format, could not be written
to as the old data still persisted.

mods/default/craftitems.lua

index f002d7096b9d19c65a5e61d221f51b6338dfde2d..aa8f56bda616a7ea92f8f1659398278a0533875e 100644 (file)
@@ -71,6 +71,7 @@ local function book_on_use(itemstack, user)
        end
 
        minetest.show_formspec(player_name, "default:book", formspec)
+       return itemstack
 end
 
 minetest.register_on_player_receive_fields(function(player, formname, fields)
@@ -133,11 +134,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
                        end
                end
 
-               local data_str = minetest.serialize(data)
-               stack:set_metadata(data_str)
-               book_on_use(stack, player)
+               stack:get_meta():from_table(data)
+               stack = book_on_use(stack, player)
        end
 
+       -- Update stack
        player:set_wielded_item(stack)
 end)
 
@@ -178,9 +179,9 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
        if not original then
                return
        end
-       local copymeta = original:get_metadata()
+       local copymeta = original:get_meta():to_table()
        -- copy of the book held by player's mouse cursor
-       itemstack:set_metadata(copymeta)
+       itemstack:get_meta():from_table(copymeta)
        -- put the book with metadata back in the craft grid
        craft_inv:set_stack("craft", index, original)
 end)