ToLazyToThink

enchanting turtle v0.1

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