Guest User

mynwell

a guest
Jun 10th, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.69 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 - XdE0B0vd
  26. -- ---------------------
  27. -- Mining Turtle --
  28. -- mynwell - f8ad3Vtz (This program)
  29. --  older mynwell - xUtqQ73B
  30. -- ---------------------
  31. -- If you choose not to use the 'myfuel' program then you need to
  32. -- comment it out from the programs. It simply reports remaining fuel.
  33. -- However, you need both the startup and collectit programs for
  34. -- the engineering turtle.
  35.  
  36. function instructions()
  37.     print("Place a Redstone Energy Cell in slot 1")
  38.     print("Place an ender chest in slot 2")
  39.     print("Place a Mining well in slot 3")
  40.     print("Place an Engineering turtle in slot 4")
  41. end
  42.  
  43. function getDim()
  44.     print("Current fuel level = " .. turtle.getFuelLevel())
  45.     print("How far should I mine before returning?")
  46.     l = tonumber(read())
  47.     print("How wide should my mining be?")
  48.     w = tonumber(read())
  49.     term.write("Left(1) or Right(2)?")
  50.     mydir = read()
  51.     return {l, w, mydir}
  52. end
  53.  
  54. function clearWorkZone()
  55.     while turtle.detect() do
  56.         turtle.dig()
  57.         sleep(0.5)
  58.     end
  59.     while not turtle.up() do
  60.         turtle.digUp()
  61.     end
  62.     while turtle.detect() do
  63.         turtle.dig()
  64.         sleep(0.5)
  65.     end
  66. end
  67.  
  68. function forward()
  69.         while not turtle.forward() do
  70.             turtle.dig()
  71.             turtle.suck()
  72.             turtle.attack()
  73.             turtle.suck()
  74.             sleep(0.5)
  75.         end
  76. end
  77.  
  78. function deploy()
  79.     while turtle.getItemCount(1) ~= 0 do
  80.         turtle.select(1)
  81.         turtle.place()
  82.     end
  83.     turtle.down()
  84.     while turtle.getItemCount(2) ~= 0 do
  85.         turtle.select(2)
  86.         turtle.placeUp()
  87.     end
  88.     while turtle.getItemCount(4) ~= 0 do
  89.         turtle.select(4)
  90.         turtle.transferTo(16)
  91.     end
  92.     while turtle.getItemCount(3) ~= 0 do
  93.         turtle.select(3)
  94.         while not turtle.place() do
  95.             turtle.dig()
  96.             sleep(0.5)
  97.         end
  98.     end
  99.     sleep(0.5)
  100. end
  101.  
  102. function retrieve()
  103.     if turtle.getItemCount(1) > 0 then
  104.         print("Error, sleeping for 10,000")
  105.         sleeping(10000)
  106.     end
  107.     while turtle.getItemCount(2) == 0 do
  108.         turtle.select(1)
  109.         turtle.digUp()
  110.         turtle.transferTo(2)
  111.     end
  112.     while turtle.getItemCount(3) == 0 do
  113.         turtle.select(1)
  114.         turtle.dig()
  115.         turtle.transferTo(3)
  116.     end
  117.     while turtle.getItemCount(16) ~= 0 do
  118.         turtle.select(16)
  119.         turtle.place()
  120.     end
  121.     local engineer = peripheral.wrap("front")
  122.     while turtle.getItemCount(1) == 0 do
  123.         engineer.turnOn()
  124.         turtle.select(1)
  125.         while not turtle.suck() do
  126.             sleep(3)
  127.         end
  128.     end
  129.     while turtle.dig() == false do
  130.         sleep(0.1)
  131.     end
  132. end
  133.  
  134. function scanMe()
  135.     turtle.select(1)
  136.     for i=1, 15 do
  137.         if turtle.getItemCount(i) > 0 then
  138.             return false
  139.         end
  140.     end
  141.     return true
  142. end
  143.  
  144. function unload()
  145.     turtle.select(1)
  146.     while scanMe() == false do
  147.         for i=1,15 do
  148.             turtle.select(i)
  149.             if turtle.getItemCount(i) > 0 then
  150.                 if turtle.getFuelLevel() < 1000 then
  151.                     turtle.refuel()
  152.                 end
  153.                 turtle.dropUp()
  154.                 sleep(0.1)
  155.             end
  156.         end
  157.     end
  158. end
  159.  
  160. function mineLength(l)
  161.     for i=1, l do
  162.         clearWorkZone()
  163.         deploy()
  164.         sleep(6)
  165.         unload()
  166.         retrieve()
  167.         forward()
  168.     end
  169.     print("I have this much fuel left")
  170.     print(tostring(turtle.getFuelLevel()))
  171. end
  172.  
  173. function turn(d,x)
  174.     if d == "1" then
  175.         turtle.turnLeft()
  176.         clearWorkZone()
  177.         deploy()
  178.         sleep(6)
  179.         unload()
  180.         retrieve()
  181.         forward()
  182.         turtle.turnLeft()
  183.     elseif d == "2" then
  184.         turtle.turnRight()
  185.         clearWorkZone()
  186.         deploy()
  187.         sleep(6)
  188.         unload()
  189.         retrieve()
  190.         forward()
  191.         turtle.turnRight()     
  192.     else
  193.         print("You were supposed to type a direction(1/2).")
  194.         print ("But you typed " .. d .. " instead")
  195.     end
  196.     x = x + 1
  197.     return x
  198. end
  199.  
  200. function myFuel()
  201.     print("My current fuel is: " .. tostring(turtle.getFuelLevel()))
  202. end
  203.  
  204. -- Main
  205. local myt
  206. -- x = starting point by width
  207. local x = 1
  208.  
  209. instructions()
  210. myt = getDim()
  211. local ll = tonumber(myt[1])
  212. local ww = tonumber(myt[2])
  213. local dd = myt[3]
  214. local bb --this will be opposite dd
  215. local recharge = turtle.getFuelLevel() - 960
  216. print ("Length will be = " .. ll)
  217. print ("Width will be =  " .. ww)
  218.  
  219. if dd == "1" then
  220.     bb = "2"
  221. elseif  dd == "2" then
  222.     bb = "1"
  223. else
  224.     print("You were supposed to type a direction(1/2).")
  225.     print ("But you typed " .. dd .. " instead")
  226. end
  227.  
  228. while not turtle.back() do
  229.     sleep(1)
  230. end
  231. mineLength(1)
  232.  
  233. if ww > x then
  234.     while x <= ww do
  235.         if turtle.getFuelLevel() <= recharge then
  236.             print("Waiting so you can change out the energy block")
  237.             waiting = read()
  238.             recharge = turtle.getFuelLevel() - 960
  239.         end
  240.         mineLength(ll)
  241.         if x == ww then
  242.             myFuel()
  243.             return
  244.         else
  245.             x = turn(dd,x)     
  246.         end
  247.         mineLength(ll)
  248.         if x >= ww then
  249.             myFuel()
  250.             return
  251.         else
  252.             x = turn(bb,x)     
  253.         end
  254.     end
  255. else
  256.     mineLength(ll)
  257. end
  258.  
  259. print ("All Finished!")
  260. myFuel()
Advertisement
Add Comment
Please, Sign In to add comment