Stravides

mynwell

Jul 10th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.18 KB | None | 0 0
  1. -- Author: Truthowl
  2. -- Makes turtle use a mining well and redstone energy cell to mine.
  3. -- Requires an Engineering Turtle, Mining Turtle, Ender Chest,
  4. -- Mining well, and a Thermal Expansion Energy Cell.
  5. -- The Engineering Turtle was crafted with a Thermal Expansion Hammer.
  6. -- Not sure if crafting with something else will work or not.
  7. --
  8. -- I made my mining turtle a chunk loading turtle as well.
  9. -- That's not needed, but then you have to remain close or drop
  10. -- your own chunk loader if you want to leave the area.
  11. -- With this, you can even set your mynwell turtle to begin underground.
  12. -- He/she will clear the workzone before placing the needed equipment.
  13. -- Also, the turtle will backup 1 block to begin mining from
  14. -- where you place him/her. So drop it from 2 blocks back or drop it
  15. -- and move out of the way.
  16. -- NOTE: Do not shut down your game while your mynwell turtle is running
  17. -- They will stop and need to be restarted if you do.
  18. --
  19. -- You need to label both the mining and engineering turtles. I know,
  20. -- that's obvious but thought I'd mention it anyway.
  21. -- Okay the turtle's need the following programs.
  22. --
  23. -- Engineering Turtle --
  24. -- collectit - GYCsY7rr
  25. -- startup - TpZs1Mqm
  26. -- ---------------------
  27. -- Mining Turtle --
  28. -- mynwell - xUtqQ73B (This program)
  29. -- ---------------------
  30. -- If you choose not to use the 'myfuel' program then you need to
  31. -- comment it out from the programs. It simply reports remaining fuel.
  32. -- However, you need both the startup and collectit programs for
  33. -- the engineering turtle.
  34.  
  35. function instructions()
  36.         print("Place a Redstone Energy Cell in slot 1")
  37.         print("Place an ender chest in slot 2")
  38.         print("Place a Mining well in slot 3")
  39.         print("Place an Engineering turtle in slot 4")
  40. end
  41.  
  42. function getDim()
  43.         -- print("Current fuel level = " .. turtle.getFuelLevel())
  44.         print("How far should I mine before returning?")
  45.         l = tonumber(read())
  46.         print("How wide should my mining be?")
  47.         w = tonumber(read())
  48.         term.write("Left(1) or Right(2)?")
  49.         mydir = read()
  50.         return {l, w, mydir}
  51. end
  52.  
  53. function clearWorkZone()
  54.         while turtle.detect() do
  55.                 turtle.dig()
  56.                 sleep(0.5)
  57.         end
  58.         while not turtle.up() do
  59.                 turtle.digUp()
  60.         end
  61.         while turtle.detect() do
  62.                 turtle.dig()
  63.                 sleep(0.5)
  64.         end
  65. end
  66.  
  67. function forward()
  68.                 while not turtle.forward() do
  69.                         turtle.dig()
  70.                         turtle.suck()
  71.                         turtle.attack()
  72.                         turtle.suck()
  73.                         sleep(0.5)
  74.                 end
  75. end
  76.  
  77. function deploy()
  78.         while turtle.getItemCount(1) ~= 0 do
  79.                 turtle.select(1)
  80.                 turtle.place()
  81.         end
  82.         turtle.down()
  83.         while turtle.getItemCount(2) ~= 0 do
  84.                 turtle.select(2)
  85.                 turtle.placeUp()
  86.         end
  87.         while turtle.getItemCount(4) ~= 0 do
  88.                 turtle.select(4)
  89.                 turtle.transferTo(16)
  90.         end
  91.         while turtle.getItemCount(3) ~= 0 do
  92.                 turtle.select(3)
  93.                 while not turtle.place() do
  94.                         turtle.dig()
  95.                         sleep(0.5)
  96.                 end
  97.         end
  98.         sleep(0.5)
  99. end
  100.  
  101. function retrieve()
  102.         if turtle.getItemCount(1) > 0 then
  103.                 print("Error, sleeping for 10,000")
  104.                 sleeping(10000)
  105.         end
  106.         while turtle.getItemCount(2) == 0 do
  107.                 turtle.select(1)
  108.                 turtle.digUp()
  109.                 turtle.transferTo(2)
  110.         end
  111.         while turtle.getItemCount(3) == 0 do
  112.                 turtle.select(1)
  113.                 turtle.dig()
  114.                 turtle.transferTo(3)
  115.         end
  116.         while turtle.getItemCount(16) ~= 0 do
  117.                 turtle.select(16)
  118.                 turtle.place()
  119.         end
  120.         local engineer = peripheral.wrap("front")
  121.         while turtle.getItemCount(1) == 0 do
  122.                 engineer.turnOn()
  123.                 turtle.select(1)
  124.                 while not turtle.suck() do
  125.                         sleep(3)
  126.                 end
  127.         end
  128.         while turtle.dig() == false do
  129.                 sleep(0.1)
  130.         end
  131. end
  132.  
  133. function scanMe()
  134.         turtle.select(1)
  135.         for i=1, 15 do
  136.                 if turtle.getItemCount(i) > 0 then
  137.                         return false
  138.                 end
  139.         end
  140.         return true
  141. end
  142.  
  143. function unload()
  144.         turtle.select(1)
  145.         while scanMe() == false do
  146.                 for i=1,15 do
  147.                         turtle.select(i)
  148.                         if turtle.getItemCount(i) > 0 then
  149.                                 turtle.dropUp()
  150.                                 sleep(0.1)
  151.                         end
  152.                 end
  153.         end
  154. end
  155.  
  156. function mineLength(l)
  157.         for i=1, l do
  158.                 clearWorkZone()
  159.                 deploy()
  160.                 sleep(6)
  161.                 unload()
  162.                 retrieve()
  163.                 forward()
  164.         end
  165. end
  166.  
  167. function turn(d,x)
  168.         if d == "1" then
  169.                 turtle.turnLeft()
  170.                 clearWorkZone()
  171.                 deploy()
  172.                 sleep(6)
  173.                 unload()
  174.                 retrieve()
  175.                 forward()
  176.                 turtle.turnLeft()
  177.         elseif d == "2" then
  178.                 turtle.turnRight()
  179.                 clearWorkZone()
  180.                 deploy()
  181.                 sleep(6)
  182.                 unload()
  183.                 retrieve()
  184.                 forward()
  185.                 turtle.turnRight()            
  186.         else
  187.                 print("You were supposed to type a direction(1/2).")
  188.                 print ("But you typed " .. d .. " instead")
  189.         end
  190.         x = x + 1
  191.         return x
  192. end
  193.  
  194. function myFuel()
  195.         -- print("My current fuel is: " .. tostring(turtle.getFuelLevel()))
  196.         return
  197. end
  198.  
  199. -- Main
  200. local myt
  201. -- x = starting point by width
  202. local x = 1
  203.  
  204. instructions()
  205. myt = getDim()
  206. local ll = tonumber(myt[1])
  207. local ww = tonumber(myt[2])
  208. local dd = myt[3]
  209. local bb --this will be opposite dd
  210. -- local recharge = turtle.getFuelLevel() - 960
  211. print ("Length will be = " .. ll)
  212. print ("Width will be =  " .. ww)
  213.  
  214. if dd == "1" then
  215.         bb = "2"
  216. elseif  dd == "2" then
  217.         bb = "1"
  218. else
  219.         print("You were supposed to type a direction(1/2).")
  220.         print ("But you typed " .. dd .. " instead")
  221. end
  222.  
  223. while not turtle.back() do
  224.         sleep(1)
  225. end
  226. mineLength(1)
  227.  
  228. if ww > x then
  229.         while x <= ww do
  230.                 mineLength(ll)
  231.                 if x == ww then
  232.                         -- myFuel()
  233.                         return
  234.                 else
  235.                         x = turn(dd,x)        
  236.                 end
  237.                 mineLength(ll)
  238.                 if x >= ww then
  239.                         -- myFuel()
  240.                         return
  241.                 else
  242.                         x = turn(bb,x)        
  243.                 end
  244.         end
  245. else
  246.         mineLength(ll)
  247. end
  248.  
  249. print ("All Finished!")
Advertisement
Add Comment
Please, Sign In to add comment