ToLazyToThink

enchanting turtle v0

Apr 7th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1.  
  2. local bookSlot = 1
  3.  
  4. local lootSlotStart = 2
  5. local lootSlotEnd = 16
  6.  
  7. local xpSide = "right"
  8. local grinderSide = "left"
  9. local manualSide  = "back"
  10.  
  11. local xp = peripheral.wrap(xpSide)
  12.  
  13. local enchantLevel = 30
  14. local levelLow = 60
  15. local levelHigh = 120
  16.  
  17.  
  18. main()
  19.  
  20.  
  21. function checkBooks()
  22.   if turtle.getItemCount(bookSlot) < 2 then
  23.     turtle.select(bookSlot)
  24.     turtle.suckUp()
  25.     if turtle.getItemCount(bookSlot) < 2 then
  26.       return false
  27.     end
  28.   end
  29.  
  30.   return true
  31. end
  32.  
  33. function setGrind(isGrind)
  34.   redstone.setOutput(grinderSide, isGrind)
  35. end
  36.  
  37. function checkXP()
  38.   local level = xp.getLevels()
  39.   if level <= levelLow then
  40.     setGrind(true)
  41.   elseif level >= levelHigh then
  42.     setGrind(false)
  43.   end
  44.  
  45.   return level >= enchantLevel
  46. end  
  47.  
  48. function clearInv()
  49.   for i = lootSlotStart, lootSlotEnd do
  50.     turtle.select(i)
  51.     turtle.dropDown()
  52.   end
  53.   turtle.select(bookSlot)
  54. end
  55.  
  56. function enchant()
  57.   turtle.select(bookSlot)
  58.   xp.enchant(enchantLevel)
  59.   clearInv()
  60. end
  61.  
  62. function setManual(isManual)
  63.   if isManual then
  64.     setGrind(false)
  65.     xp.setAutoCollect(false)
  66.   else
  67.     xp.setAutoCollect(true)
  68.   end
  69. end
  70.  
  71. function isManualSignal()
  72.   return redstone.getInput(manualSide)
  73. end
  74.  
  75. function main()
  76.   clearInv()
  77.   while true do
  78.     if isManualSignal() then
  79.       setManual(true)
  80.       sleep(1)
  81.     else
  82.       setManual(false)
  83.       if checkXP() and checkBooks() then
  84.         enchant()
  85.       else
  86.         sleep(5)
  87.       end
  88.     end
  89.   end
  90. end
Advertisement
Add Comment
Please, Sign In to add comment