Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --wrapping peripheral and init variables
- enableMonitor = peripheral.isPresent("bottom")
- local xp = peripheral.wrap("left")
- local anvil = peripheral.wrap("right")
- xp.setAutoCollect(true)
- xpPickup = true
- mode = 1
- statusText = "Booting"
- desiredLvl = 30
- modeStatus = "Booting"
- done = false
- manual = false
- help = false
- --make the book
- function enchant(dLvl)
- turtle.select(1)
- xp.enchant(dLvl)
- turtle.drop()
- end
- --get the slot number that books are in
- function findbooks()
- for i=2,14 do
- if turtle.getItemCount(i) > 0 then
- return i
- end
- end
- if turtle.getItemCount(14) == 0 then
- print("no books") return false
- else error("Error getting book count")
- end
- end
- --check for books in inventory, and place 1 in first slot
- function bookcheck()
- if turtle.getItemCount(1) == 0 then
- turtle.select(findbooks())
- turtle.transferTo(1,1)
- end
- end
- --print usage information
- function startup()
- term.clear()
- term.setCursorPos(1,1)
- textutils.slowPrint("Lucky Auto Enchant and Anvil v1", 20)
- sleep(3)
- term.clear()
- term.setCursorPos(1,1)
- end
- -- monitor updates
- function updateScreen()
- if mode == 4 then
- dispHelp()
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Lucky Auto Enchant & Anvil v1.0")
- term.setCursorPos(1,3)
- print("Xp lvl: " .. xp.getLevels())
- term.setCursorPos(1,4)
- print("Mode:" .. statusText .. " ")
- term.setCursorPos(1,7)
- print("Status: " .. modeStatus)
- term.setCursorPos(1,8)
- if mode == 1 or mode == 2 then
- print("Desired lvl: " .. desiredLvl)
- elseif mode == 3 then
- print("Anvil Cost: " .. anvil.getRepairCost(15,16))
- term.setCursorPos(1,9)
- print("Repair slot 15 with slot 16")
- end
- term.setCursorPos(20,3)
- print("Press H for Help")
- term.setCursorPos(1,10)
- print("Xp Collection: " .. tostring(xpPickup))
- end
- end
- function autoEnchant()
- bookcheck()
- desiredLvl = 30
- sleep(0.1)
- if xp.getLevels() >= desiredLvl then
- enchant(desiredLvl)
- modeStatus = "Enchanted!"
- else
- modeStatus = "Waiting"
- end
- end
- function manEnchant()
- sleep(0.1)
- if xp.getLevels() >= desiredLvl then
- modeStatus = "Ready!"
- else
- modeStatus = "Waiting"
- end
- end
- function manAnvil()
- sleep(0.1)
- end
- function dispHelp()
- term.clear()
- term.setCursorPos(1,1)
- term.write("Lucky Help Menu")
- term.setCursorPos(1,3)
- term.write("Press M for Manual Enchant")
- term.setCursorPos(1,4)
- term.write("Press D for Xp pickup")
- term.setCursorPos(1,5)
- term.write("Press A for Anvil Mode")
- term.setCursorPos(1,6)
- term.write("Press S for Auto Enchant")
- term.setCursorPos(1,7)
- term.write("Press Enter for manual anvil/enchant")
- term.setCursorPos(1,8)
- term.write("Arrow keys change desired lvl")
- term.setCursorPos(1,9)
- term.write("Press H to exit help")
- term.setCursorPos(1,10)
- term.write("Press Q to quit")
- sleep(0.5)
- end
- function eventHandle()
- while true do
- timer1 = os.startTimer(1)
- id,p1,p2,p3 = os.pullEvent()
- if id == "key" and p1 == 200 and manual then
- desiredLvl = desiredLvl + 1
- if desiredLvl > 30 then desiredLvl = 30 end
- elseif id == "key" and p1 == 208 and manual then
- desiredLvl = desiredLvl - 1
- if desiredLvl < 1 then desiredLvl = 1 end
- elseif id == "key" and p1 == 50 then
- mode = 2
- elseif id == "key" and p1 == 31 then
- mode = 1
- elseif id == "key" and p1 == 30 then
- mode = 3
- elseif id == "key" and p1 == 16 then
- error("Program Shutdown")
- elseif id == "key" and p1 == 32 then
- if xpPickup == true then xpPickup = false
- else xpPickup = true
- end
- xp.setAutoCollect(xpPickup)
- elseif id == "key" and p1 == 28 and manual then
- if mode == 3 then
- anvil.repair(15,16)
- else
- enchant(desiredLvl)
- end
- elseif id == "key" and p1 == 35 then
- if mode == 4 then mode = 1
- else mode = 4
- end
- elseif id == "timer" and p1 == "timer1" then
- timer1 = os.startTimer(1)
- end
- end
- end
- function modeHandle()
- while true do
- sleep(0.1)
- updateScreen()
- if mode == 1 then
- manual = false
- statusText = "Automatic"
- autoEnchant()
- elseif mode == 2 then
- statusText = "Manual"
- manual = true
- manEnchant()
- elseif mode == 3 then
- statusText = "Anvil"
- manual = true
- manAnvil()
- elseif mode == 4 then
- statusText = "Help"
- end
- end
- end
- startup()
- while true do
- parallel.waitForAny(eventHandle, modeHandle)
- end
Advertisement
Add Comment
Please, Sign In to add comment