Skip to content

Fix magic conjuring of books #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
},

Expand Down