Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- anvil = peripheral.wrap("right")
- xp = peripheral.wrap("left")
- m=peripheral.wrap("top")
- xp.setAutoCollect(true)
- if fs.exists("totalserved") then
- h=fs.open("totalserved", "r")
- total = h.readLine()
- h.close()
- total= math.abs(total)
- else total = 0
- end
- function save()
- h= fs.open("totalserved", "w")
- h.write(total)
- h.close()
- end
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function clearmon()
- m.clear()
- m.setCursorPos(1,1)
- end
- local cPrint = function (text)
- local x2, y2 = term.getCursorPos()
- local x,y = term.getSize()
- term.setCursorPos(math.ceil((x/2) - (text:len() / 2)), y2)
- print(text)
- end
- local cPrintMon = function (text)
- local x2, y2 =m.getCursorPos()
- local x,y = m.getSize()
- m.setCursorPos(math.ceil((x/2) - (text:len() /2)), y2)
- m.write(text)
- m.setCursorPos(x2, y2+1)
- end
- function enchant()
- if xp.getLevels() > 30 then
- turtle.select(3)
- if turtle.getItemCount(3) ~=1 then
- clear()
- cPrint("Place 1 book into slot 3")
- sleep(5)
- else
- if xp.enchant(30) then
- total = total + 30
- save()
- else
- clear()
- cPrint("an error occured, is a book in slot 3?")
- sleep(5)
- end
- end
- else
- clear()
- cPrint ("Not Enough EXP available")
- sleep(5)
- end
- end
- function repair()
- local cost = anvil.getRepairCost(1,2)
- local levels = xp.getLevels()
- if cost == 0 then
- clear()
- cPrint("invalid Items")
- sleep(5)
- elseif cost > levels then
- clear()
- cPrint("Not enough levels, needed "..cost.." levels")
- sleep(5)
- else
- if anvil.repair(1,2) then
- total = total + cost
- save()
- else
- clear()
- cPrint("an unknown error occured")
- sleep (5)
- end
- end
- end
- function mon ()
- while true do
- clearmon()
- cPrintMon ("Turtle XP Station")
- cPrintMon ("")
- cPrintMon ("Currently Level: "..xp.getLevels())
- cPrintMon ("")
- cPrintMon ("")
- cPrintMon ("For Anvil place items into")
- cPrintMon ("Slot 1 AND Slot 2")
- cPrintMon ("")
- cPrintMon ("For Enchanting place book")
- cPrintMon ("into Slot 3")
- cPrintMon ("")
- cPrintMon ("Total Levels Served: "..total)
- sleep(10)
- end
- end
- function menu()
- while true do
- clear()
- cPrint("Please Choose One")
- local n=1
- while true do
- local x,y = term.getCursorPos()
- term.clearLine()
- if n==1 then cPrint (">Enchant< Anvil ")
- else cPrint (" Enchant >Anvil<") end
- term.setCursorPos(x,y)
- a,b=os.pullEvent()
- while a~="key" do a, b=os.pullEvent() end
- if b==203 and n == 2 then n=1 end
- if b==205 and n==1 then n=2 end
- if b==28 then print ("") break end
- end
- if n==1 then enchant() end
- if n==2 then repair() end
- end
- end
- while true do
- parallel.waitForAll(mon, menu)
- sleep (1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement