Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- xp = peripheral.wrap("left")
- anvil = peripheral.wrap("right")
- xp.setAutoCollect(true)
- term.clear()
- w,h = term.getSize()
- elvl = 30
- turtle.select(1)
- function swrite(str,x,y)
- term.setCursorPos(x,y)
- term.write(str)
- end
- function swritecenter(str,y)
- term.setCursorPos(w/2 - #str/2,y)
- term.write(str)
- end
- function cline(y)
- term.setCursorPos(1,y)
- term.clearLine()
- end
- function drawUI()
- swritecenter("Welcome to Fair's XP Turtle.",1)
- swrite("How to use enchant/repair:",2,3)
- swrite("1. Place item(s) in slot 1/2.",2,4)
- swrite("2. Use Arrowkeys to change level.",2,5)
- swrite("3. Press ENTER to enchant/repair.",2,6)
- swrite("NOTE: Exit, enter turtle to update.",2,13)
- end
- function updateLVL()
- swrite("Current stored levels: "..xp.getLevels().." ",2,8)
- end
- function updateSEL()
- cline(9)
- swrite("Selected enchant level: "..elvl,2,9)
- end
- function updateREP(str)
- cline(9)
- swrite("Items repair level cost: "..str,2,9)
- end
- function update(str)
- swrite("Last status:",2,10)
- term.setCursorPos(1,11)
- term.clearLine()
- swrite(str,2,11)
- end
- drawUI()
- updateLVL()
- updateSEL()
- updateREP("N/A")
- update("Startup complete.")
- while true do
- event,key = os.pullEvent()
- if turtle.getItemCount(2) == 0 then
- updateSEL()
- else
- if anvil.getRepairCost(1,2) > 0 then
- updateREP(tostring(anvil.getRepairCost(1,2)))
- else
- updateREP("N/A")
- end
- end
- if event == "key" then
- if key == 28 then
- if turtle.getItemCount(2) == 0 then
- if elvl <= xp.getLevels() then
- if xp.enchant(elvl) then
- update("Success enchant of "..elvl.." levels.")
- else
- update("Something went wrong in enchant.")
- end
- else
- update("Turtle level not high enough.")
- end
- else
- if anvil.getRepairCost(1,2) <= xp.getLevels() then
- if anvil.repair(1,2) then
- update("Success repair of items.")
- else
- update("Something went wrong in repair.")
- end
- else
- update("Turtle level not high enough.")
- end
- end
- elseif key == 200 or key == 205 then
- if elvl < 30 then
- elvl = elvl + 1
- updateSEL()
- end
- elseif key == 208 or key == 203 then
- if elvl > 1 then
- elvl = elvl - 1
- updateSEL()
- end
- end
- end
- updateLVL()
- os.sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment