tompy90

tompyMine1.0

Aug 10th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("move")
  2.  
  3. -- Functions --
  4.  
  5. function reset()
  6.   move.reset()
  7.   move.store("initialize", "false")
  8. end
  9.  
  10. function dig()
  11.   while turtle.detect() do
  12.     turtle.dig()
  13.   end
  14.   while turtle.detectDown() do
  15.     turtle.digDown()
  16.   end
  17.   while turtle.detectUp() do
  18.     turtle.digUp()
  19.     sleep(0.6)
  20.   end
  21. end
  22.  
  23. function getType(number)
  24.   if bit.band(number,1) == 0 then
  25.     return "even"
  26.   end
  27.   return "odd"
  28. end  
  29.  
  30. function sweepLeft()
  31.   while tonumber(location["y"])%3 == 0 and tonumber(location["x"]) < tonumber(quarry["width"])-1 do
  32.     move.face(3)
  33.     dig()
  34.     move.forward()
  35.     location = move.pull("location")
  36.   end
  37.   dig()
  38. end
  39.  
  40. function sweepUp()
  41.   while tonumber(location["y"]) < tonumber(quarry["height"]) do
  42.     if tonumber(location["x"]) > 0 then
  43.       move.face(1)
  44.     else
  45.       move.face(3)
  46.     end
  47.     dig()
  48.     move.up()
  49.     location = move.pull("location")
  50.     if tonumber(location["y"])%3 == 0 then
  51.       dig()
  52.       move.forward()
  53.       location = move.pull("location")      
  54.       break
  55.     end  
  56.   end
  57. end
  58.  
  59. function sweepDown()
  60.   while tonumber(location["y"]) > 0 do
  61.     if tonumber(location["x"]) > 0 then
  62.       move.face(1)
  63.     else
  64.       move.face(3)
  65.     end
  66.     dig()
  67.     move.down()
  68.     location = move.pull("location")
  69.     if tonumber(location["y"])%3 == 0 then
  70.       dig()
  71.       move.forward()
  72.       location = move.pull("location")      
  73.       break
  74.     end  
  75.   end
  76. end
  77.  
  78. function sweepRight()
  79.   while tonumber(location["x"]) > 0 do
  80.     move.face(1)
  81.     dig()
  82.     move.forward()
  83.     location = move.pull("location")
  84.   end
  85.   dig()  
  86. end
  87.  
  88. function sweepForward()
  89.   if tonumber(location["y"]) == tonumber(quarry["height"]) then
  90.     move.face(0)
  91.     dig()
  92.     move.forward()
  93.     location = move.pull("location")
  94.   end
  95. end
  96.  
  97. -- Program --
  98.  
  99. if not fs.exists("data/initialize") then
  100.   handle = fs.open("data/initialize", "w")
  101.   handle.write("false")
  102.   handle.close()
  103. end
  104.  
  105. handle = fs.open("data/initialize", "r")
  106. local initialize = handle.readAll()
  107.  
  108. if initialize == "true" then
  109.   print("quarry already started")
  110. else
  111.   print("Quarry initializing now...")
  112.  
  113.   reset()
  114.  
  115.   term.clear()
  116.   term.setCursorPos(1,1)
  117.   term.write("Welcome to tompy Mine")
  118.  
  119.   local quarry = {}
  120.  
  121.   term.setCursorPos(1,3)
  122.   term.write("Quarry Width: ")
  123.   quarry["width"] = read()
  124.  
  125.   term.setCursorPos(1,4)
  126.   term.write("Quarry Height: ")
  127.   quarry["height"] = read()
  128.  
  129.   term.setCursorPos(1,5)
  130.   term.write("Quarry Depth: ")
  131.   quarry["depth"] = read()
  132.  
  133.   move.store("quarry", quarry)
  134.  
  135.   move.store("initialize", true)
  136.  
  137.   local mineLocation = {x = 0, y = 0, z = 1}
  138.   move.store("mineLocation", mineLocation)  
  139. end
  140.  
  141. location = move.pull("location")
  142. quarry = move.pull("quarry")
  143. mineLocation = move.pull("mineLocation")
  144.  
  145. move.display()
  146.  
  147. while  tonumber(location["z"]) < tonumber(quarry["depth"]) + 1 do
  148.   sweepLeft()
  149.   sweepUp()
  150.   sweepRight()
  151.   sweepUp()
  152.   sweepForward()
  153. end
Advertisement
Add Comment
Please, Sign In to add comment