Skip to content

Commit

Permalink
Books: Fix backwards compatibility issues
Browse files Browse the repository at this point in the history
Commit c68b827 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.
  • Loading branch information
octacian authored and paramat committed Mar 20, 2017
1 parent ecf160d commit 2a74032
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions mods/default/craftitems.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2a74032

Please sign in to comment.