Advertisement
hdgamer14

Miner 2.1 (alpha,works but is not done yet)

Mar 22nd, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.39 KB | None | 0 0
  1. --[[
  2. MINER
  3.  
  4. Made by HDGamer14
  5.  
  6. Alpha had has bugs most likely :(
  7.  
  8. --]]
  9.  
  10. local rows,length,torchs,x,y,x1,y1,direction,direction1,miner
  11.  
  12. function turn(dirc)
  13.     if dirc == "left" then
  14.         turtle.turnLeft()
  15.         if direction == 3 then
  16.             direction = 0
  17.         else
  18.             direction = direction + 1
  19.         end
  20.     else
  21.         turtle.turnRight()
  22.         if direction == 0 then
  23.             direction = 3
  24.         else
  25.             direction = direction - 1
  26.         end
  27.     end
  28. end
  29.  
  30. function goforward()
  31.     if turtle.forward() == false then
  32.         repeat
  33.             turtle.dig()
  34.             turtle.attack()
  35.             sleep(0.5)
  36.         until turtle.forward() == true
  37.     end
  38. end
  39.  
  40. function forward()
  41.     checkfuel()
  42.     if direction == 0 then
  43.         goforward()
  44.         x = x + 1
  45.     elseif direction == 2 then
  46.         goforward()
  47.         x = x - 1
  48.     elseif direction == 3 then
  49.         goforward()
  50.         y = y - 1
  51.     else
  52.         goforward()
  53.         y = y + 1
  54.     end
  55. end
  56.  
  57. function checkfuel()
  58.     if turtle.getFuelLevel() < 5 then
  59.         print("Place fuel in slot 15")
  60.         repeat
  61.         sleep(1)
  62.         until turtle.getItemCount(15) > 0
  63.         turtle.select(15)
  64.         turtle.refuel(turtle.getItemCount(15))
  65.         print("Refueled, curent about of fuel : "..turtle.getFuelLevel())
  66.     end
  67. end
  68.  
  69. function gohome()
  70.     x1 = x
  71.     y1 = y
  72.     direction1 = direction
  73.     while direction ~= 3 do
  74.         turn("right")
  75.     end
  76.     while y ~= 0 do
  77.         forward()
  78.     end
  79.     turn("right")
  80.     while x ~= 0 do
  81.         forward()
  82.     end
  83. end
  84.  
  85. function goback()
  86.     while direction ~= 0 do
  87.         turn("right")
  88.     end
  89.     while x ~= x1 do
  90.         forward()
  91.     end
  92.     turn("left")
  93.     while y ~= y1 do
  94.         forward()
  95.     end
  96.     while direction ~= direction1 do
  97.         turn("right")
  98.     end
  99. end
  100.  
  101. function mine()
  102.   turtle.digUp()
  103.   turtle.dig()
  104.   turtle.digDown()  
  105. end
  106.  
  107. function torch( )
  108.     if torchs == true then
  109.         if math.fmod(x,4) == 0 then
  110.             if math.fmod(y,4) == 0 then
  111.                 turtle.select(16)
  112.                 turtle.placeDown()
  113.             end
  114.         end
  115.     end
  116. end
  117.  
  118. function row(lrow)
  119.     for i=1,lrow do
  120.         mine()
  121.         torch()
  122.         if turtle.getItemCount(12) > 0 then
  123.             gohome()
  124.             unload()
  125.             goback()
  126.         end
  127.         forward()
  128. --      print("X : ".. x)
  129. --      print("Y : ".. y)
  130. --      print("direction : "..direction)
  131. --      print()
  132.     end
  133. end
  134.  
  135. function newrow()
  136.     --forward()
  137.     if (y == rows - 1) then
  138. --      print("Swag rows = y")
  139.         if direction == 0 then
  140.             turn("right")
  141.             mine()
  142.         else
  143.             turn("left")
  144.             mine()
  145.         end
  146.     else
  147.         if direction == 0 then
  148.             turn("left")
  149.             mine()
  150.             forward()
  151.             turn("left")
  152.         else
  153.             turn("right")
  154.             mine()
  155.             forward()
  156.             turn("right")
  157.         end
  158.     end
  159. end
  160.  
  161. function unload()
  162.   print ("Unloading items...")
  163.   for n=1,15 do
  164.     turtle.select(n)
  165.     turtle.drop()
  166.   end
  167.   turtle.select(1)
  168. end
  169.  
  170. function cycle()
  171.     row(length - 1)
  172.     newrow()
  173. end
  174.  
  175.  
  176. x = 0
  177. y = 0
  178. direction = 0
  179.  
  180.  
  181.  
  182. -- Program start
  183.  
  184.   shell.run("clear")
  185.   print("Place chest behind me!")
  186.   print("How far you you like me to go?")
  187.     length=read()
  188.   print("How many rows would you like me to mine?")
  189.     rows=read(number)
  190.    -- if row == 1 then
  191.    --   newRow = false
  192.    -- end  
  193.   print("Would you like me to use torches? (yes/no)")
  194.     torchs=read()
  195.   if torchs == "yes" then
  196.     print("Place torhes in slot 16")
  197.     repeat
  198.       sleep(1)
  199.     until turtle.getItemCount(16) > 0
  200.  
  201.  torchs = true
  202.    else
  203.  torchs = false  
  204.   end
  205.  
  206. miner = rows
  207.  
  208. repeat
  209.   cycle()
  210.   miner = miner - 1
  211. until miner == 0
  212.  
  213. gohome()
  214. unload()
  215.  
  216. --print("X : ".. x)
  217. --print("Y : ".. y)
  218. --print("direction : "..direction)
  219. print("All done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement