Skip to content

Commit b0ec8f1

Browse files
sofarparamat
authored andcommittedJan 5, 2016
Allow books to be copied on the craft grid.
Combine any written book with an empty book to copy it. The copy is in player hands when using, and the original is put back on the crafting grid and can be directly copied again. All ownership and metadata is retained, so the copy of the book is as writable as the original is, or isn't.
1 parent c76a919 commit b0ec8f1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
 

‎mods/default/craftitems.lua

+30
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,36 @@ minetest.register_craftitem("default:book_written", {
8888
on_use = book_on_use,
8989
})
9090

91+
minetest.register_craft({
92+
type = "shapeless",
93+
output = "default:book_written",
94+
recipe = { "default:book", "default:book_written" }
95+
})
96+
97+
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
98+
if itemstack:get_name() ~= "default:book_written" then
99+
return
100+
end
101+
102+
local copy = ItemStack("default:book_written")
103+
local original
104+
local index
105+
for i = 1, player:get_inventory():get_size("craft") do
106+
if old_craft_grid[i]:get_name() == "default:book_written" then
107+
original = old_craft_grid[i]
108+
index = i
109+
end
110+
end
111+
if not original then
112+
return
113+
end
114+
local copymeta = original:get_metadata()
115+
-- copy of the book held by player's mouse cursor
116+
itemstack:set_metadata(copymeta)
117+
-- put the book with metadata back in the craft grid
118+
craft_inv:set_stack("craft", index, original)
119+
end)
120+
91121
minetest.register_craftitem("default:coal_lump", {
92122
description = "Coal Lump",
93123
inventory_image = "default_coal_lump.png",

0 commit comments

Comments
 (0)
Please sign in to comment.