Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- get the current level of the turtle
- function getLvl()
- curLev = m.getLevels()
- return curLev
- end
- -- Check if nLvl(default=30) levels have been reached, if not wait, if yes, return true.
- function checkLevel(nLvl)
- getLvl()
- if curLev<nLvl then
- printStatus("gathering XP", curLev)
- turtle.attack()
- sleep(0.2)
- turtle.select(1)
- turtle.dropDown()
- return false
- else
- printStatus("moving to enchant area", getLvl())
- return true
- end
- end
- -- Look for items to enchant in slots 2 through 14, if there are none, default to findBooks()
- function getItems()
- for i=2,14 do
- if turtle.getItemCount(i)>0 then
- turtle.select(i)
- turtle.transferTo(1,1)
- turtle.select(1)
- return true
- end
- end
- -- print("no items found, trying to find books")
- if findBook() then
- -- print("Books found")
- return true
- else
- return false
- end
- end
- -- Get books from inventory slot 15 and put 1 in slot 1, returning true, if not return false
- function findBook()
- if turtle.getItemCount(15)>=1 then
- turtle.select(15)
- turtle.transferTo(1,1)
- turtle.select(1)
- return true
- else
- return false
- end
- end
- -- enchant the book in slot one and drop it into the chest underneath the turtle
- function enchantBook(nLvl)
- if m.enchant(nLvl) then
- turtle.dropDown()
- else
- error("Unexpected error while trying to enchant")
- end
- end
- -- End program with a message
- function exitMsg(exitNr)
- if exitNr == 1 then exitStr="Out of fuel. Place more fuel in slot 16 and restart the program"
- elseif exitNr == 2 then exitStr="No more items or books"
- -- elseif exitNr == 3 then exitStr=""
- -- elseif exitNr == 4 then exitStr=""
- -- elseif exitNr == then exitStr=""
- end
- term.clear()
- term.setCursorPos(2,2)
- sleep(0.5)
- print(exitStr)
- run.state="end"
- end
- function printIntro()
- term.clear()
- print("---------------------------------------")
- print("------- XPSlayer 0.1 by Summit --------")
- print("---------------------------------------")
- print()
- print("This turtle will automatically enchant items in its inventory")
- print("Place any items in slots 2 through 14")
- print("Place some books in slot 15.")
- print("Place some fuel in slot 16")
- print("Press any key to start")
- print()
- end
- function printStatus(curTask, curLvl)
- term.clear()
- term.setCursorPos(1,1)
- print("------- XPSlayer 0.1 by Summit --------")
- term.setCursorPos(2,4)
- io.write(string.format("Current Task: %s", curTask))
- term.setCursorPos(2,6)
- io.write(string.format("Current Level: %s", curLvl))
- end
- --INIT
- m=peripheral.wrap("right")
- m.setAutoCollect(true)
- nLvl=30
- run = {}
- run.state="running"
- screenw, screenh = term.getSize()
- -- Main Program
- printIntro()
- os.pullEvent()
- -- start main loop
- while run.state=="running" do
- while not checkLevel(nLvl) do
- sleep(1)
- end
- -- checkFuel()
- -- loadState()
- printStatus("enchanting", getLvl())
- sleep(2)
- if getItems() then
- enchantBook(nLvl)
- sleep(2)
- -- moveForward(5)
- else
- exitMsg(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment