Skip to content

Commit 2a74032

Browse files
octacianparamat
authored andcommittedMar 20, 2017
Books: Fix backwards compatibility issues
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.
1 parent ecf160d commit 2a74032

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
 

‎mods/default/craftitems.lua

+6-5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ local function book_on_use(itemstack, user)
7171
end
7272

7373
minetest.show_formspec(player_name, "default:book", formspec)
74+
return itemstack
7475
end
7576

7677
minetest.register_on_player_receive_fields(function(player, formname, fields)
@@ -133,11 +134,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
133134
end
134135
end
135136

136-
local data_str = minetest.serialize(data)
137-
stack:set_metadata(data_str)
138-
book_on_use(stack, player)
137+
stack:get_meta():from_table(data)
138+
stack = book_on_use(stack, player)
139139
end
140140

141+
-- Update stack
141142
player:set_wielded_item(stack)
142143
end)
143144

@@ -178,9 +179,9 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
178179
if not original then
179180
return
180181
end
181-
local copymeta = original:get_metadata()
182+
local copymeta = original:get_meta():to_table()
182183
-- copy of the book held by player's mouse cursor
183-
itemstack:set_metadata(copymeta)
184+
itemstack:get_meta():from_table(copymeta)
184185
-- put the book with metadata back in the craft grid
185186
craft_inv:set_stack("craft", index, original)
186187
end)

0 commit comments

Comments
 (0)
Please sign in to comment.