From f00236fceb59c3ac65efcf10cd70f97586b436c3 Mon Sep 17 00:00:00 2001 From: Eli Carter Date: Wed, 20 May 2020 12:36:56 -0500 Subject: [PATCH] Fix magic conjuring of books --- init.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 2fef084..0732df9 100644 --- a/init.lua +++ b/init.lua @@ -321,12 +321,19 @@ function getSandboxEnv (name) return nil end end, - write = function(i,title,text) - if i<=0 or i > 32 then return nil end + if i<=0 or i > 16 then return nil end local inv = minetest.get_meta(basic_robot.data[name].spawnpos):get_inventory(); - local stack = basic_robot.commands.write_book(basic_robot.data[name].owner,title,text); - if stack then inv:set_stack("library", i, stack) end + -- Make sure there is a book in the target slot before putting + -- a new one there so we don't magically conjure a book by + -- writing to an empty slot. + local old_stack = inv:get_stack("library", i) + if not old_stack or string.sub(old_stack:get_name(), 1, #"default:book") ~= "default:book" then + minetest.chat_send_player(name,"#ROBOT no book in position "..i.." for writing.") + else + local stack = basic_robot.commands.write_book(basic_robot.data[name].owner,title,text); + if stack then inv:set_stack("library", i, stack) end + end end },