Posted 16 March 2013 - 07:56 AM
Hi guys, this is my first published piece of code, it requires misc. peripherals to work though.
Its a simple set up really, the turtle dumps enchanted books into the chest at the (or on the right if you want it to) and pulls books 1 at a time from the chest above and produces level 30 enchantments.
Here is the code, and the pastebin http://pastebin.com/P7qXS1sS
Please comment with feedback and suggestions/improvements.
Edit: New version is up.
Change Log
Yarma
Its a simple set up really, the turtle dumps enchanted books into the chest at the (or on the right if you want it to) and pulls books 1 at a time from the chest above and produces level 30 enchantments.
Here is the code, and the pastebin http://pastebin.com/P7qXS1sS
Spoiler
m=peripheral.wrap("right")
m.setAutoCollect(true)
function levelCheck()
level = m.getLevels()
shell.run("clear")
print ("Currently level: "..level)
return level
end
function getBook()
local bookCount
local toReturn
turtle.suckUp()
bookCount = turtle.getItemCount(1)
if bookCount == 0 then
while bookCount == 0 do
shell.run("clear")
print ("Please Reload the Chest")
sleep(1)
turtle.suckUp()
bookCount = turtle.getItemCount(1)
end
end
if bookCount ~= 0 then do
print("Returning Books")
sleep(2)
returnBooks(bookCount)
print("Extra books returned")
end
end
end
function returnBooks(x)
x = x-1
print("Returning "..x.." books")
sleep(4)
turtle.transferTo(2, x)
turtle.select(2)
turtle.dropUp()
turtle.select(1)
end
while true do
local lv = levelCheck()
if lv >= 30 then
getBook()
m.enchant(30)
turtle.drop()
end
sleep (2)
end
Please comment with feedback and suggestions/improvements.
Edit: New version is up.
Change Log
Spoiler
16/03/12 - Fixed a bug where it would not replace books correctly when reloading the top chest.Yarma