bigougit

enchant v2.1

Mar 4th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. -- enchant v2.1 by bigougit
  2.  
  3. local dropDIR = "up"
  4. -- change for desired direction
  5. -- up, down, forward
  6.  
  7. local enchantSlot = 1
  8. --slot used for enchanting
  9.  
  10. local storageSlot = { 16, 15, 14 }
  11. --3 slots where books are stored
  12.  
  13. local pullItems = "forward"
  14. --pull more items from dir
  15. --none, up, down, forward
  16.  
  17. local xp
  18. if peripheral.getType("right") == "xp" then
  19.   xp = peripheral.wrap("right")
  20. elseif peripheral.getType("left") == "xp" then
  21.   xp = peripheral.wrap("left")
  22. else
  23.   print("Must be ran on XP turtle!")
  24.   return false
  25. end
  26.  
  27. local continue = true
  28. local collected = 0
  29. local totEnchanted = 0
  30.  
  31. local moreItems = {}
  32.  
  33. moreItems["none"] = function() return false end
  34. moreItems["up"] = function() return turtle.suckUp() end
  35. moreItems["down"] = function() return turtle.suckDown() end
  36. moreItems["forward"] = function() return turtle.suck() end
  37.  
  38. local dropTable = {}
  39.  
  40. dropTable["up"] = function () return turtle.dropUp() end
  41. dropTable["down"] = function () return turtle.dropDown() end
  42. dropTable["forward"] = function() return turtle.drop() end
  43.  
  44. local function dispStats()
  45.   term.clear()
  46.   term.setCursorPos(1,1)
  47.   print("Bigougit's enchanting program.")
  48.   print("XP collected:    "..collected)
  49.   print("Current level:   "..xp.getLevels())
  50.   print("Books Enchanted: "..totEnchanted)
  51. end
  52.  
  53.  
  54.  
  55. if turtle.getItemCount(enchantSlot) ~= 1 then
  56.   turtle.select(enchantSlot)
  57.   dropTable[dropDIR]()
  58.   turtle.select(storageSlot[1])
  59.   turtle.transferTo(enchantSlot,1)
  60. end
  61.  
  62. if turtle.getItemCount(storageSlot[2]) > 0 then
  63.   turtle.select(storageSlot[2])
  64.   turtle.transferTo(storageSlot[1],64)
  65. elseif turtle.getItemCount(storageSlot[3]) > 0 then
  66.   turtle.select(storageSlot[3])
  67.   turtle.transferTo(storageSlot[1],64)
  68. else
  69.   print("pulling items")
  70.   turtle.select(storageSlot[2])
  71.   moreItems[pullItems]()
  72.   turtle.select(storageSlot[3])
  73.   moreItems[pullItems]()
  74. end
  75. turtle.select(storageSlot[1])
  76.  
  77. while continue do
  78.   collected = xp.collect() + collected
  79.   dispStats()
  80.   if xp.getLevels() > 29 then
  81.     if turtle.getItemCount(enchantSlot) == 1 then
  82.       turtle.select(enchantSlot)
  83.       if xp.enchant(30) then
  84.         totEnchanted = totEnchanted + 1
  85.         while not dropTable[dropDIR]() do
  86.           sleep(0.5)
  87.         end
  88.         turtle.select(storageSlot[1])
  89.         if not turtle.transferTo(enchantSlot,1) then
  90.           print("!!Need more books!!")
  91.           if turtle.getItemCount(storageSlot[2]) > 0 then
  92.             turtle.select(storageSlot[2])
  93.             turtle.transferTo(storageSlot[1],64)
  94.           elseif turtle.getItemCount(storageSlot[3]) > 0 then
  95.             turtle.select(storageSlot[3])
  96.             turtle.transferTo(storageSlot[1],64)
  97.           else
  98.             print("pulling items")
  99.             turtle.select(storageSlot[2])
  100.             moreItems[pullItems]()
  101.             turtle.select(storageSlot[3])
  102.             moreItems[pullItems]()
  103.           end
  104.           turtle.select(storageSlot[1])
  105.           while not turtle.transferTo(enchantSlot,1) do
  106.             collected = xp.collect() + collected
  107.             dispStats()
  108.             print("!!Need more books!!")
  109.             sleep(0.5)
  110.           end
  111.         end
  112.       else
  113.         print("!!Error: Failed enchant!!")
  114.         while not dropTable[dropDIR]() do
  115.           collected = xp.collect() + collected
  116.           sleep(0.5)
  117.         end
  118.       end
  119.     end
  120.   end
  121.   sleep(1)
  122. end
Advertisement
Add Comment
Please, Sign In to add comment