Guest User

mine

a guest
Aug 10th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  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 sweepRight()
  60.   while tonumber(location["x"]) > 0 do
  61.     move.face(1)
  62.     dig()
  63.     move.forward()
  64.     location = move.pull("location")
  65.   end
  66.   dig()  
  67. end
  68.  
  69. function sweepForward()
  70.   if tonumber(location["y"]) == tonumber(quarry["height"]) then
  71.     move.face(0)
  72.     dig()
  73.     move.forward()
  74.     location = move.pull("location")
  75.   end
  76. end
  77.  
  78. -- Program --
  79.  
  80. if not fs.exists("data/initialize") then
  81.   handle = fs.open("data/initialize", "w")
  82.   handle.write("false")
  83.   handle.close()
  84. end
  85.  
  86. handle = fs.open("data/initialize", "r")
  87. local initialize = handle.readAll()
  88.  
  89. if initialize == "true" then
  90.   print("quarry already started")
  91. else
  92.   print("Quarry initializing now...")
  93.  
  94.   reset()
  95.  
  96.   term.clear()
  97.   term.setCursorPos(1,1)
  98.   term.write("Welcome to tompy Mine")
  99.  
  100.   local quarry = {}
  101.  
  102.   term.setCursorPos(1,3)
  103.   term.write("Quarry Width: ")
  104.   quarry["width"] = read()
  105.  
  106.   term.setCursorPos(1,4)
  107.   term.write("Quarry Height: ")
  108.   quarry["height"] = read()
  109.  
  110.   term.setCursorPos(1,5)
  111.   term.write("Quarry Depth: ")
  112.   quarry["depth"] = read()
  113.  
  114.   move.store("quarry", quarry)
  115.  
  116.   move.store("initialize", true)
  117.  
  118.   local mineLocation = {x = 0, y = 0, z = 1}
  119.   move.store("mineLocation", mineLocation)  
  120. end
  121.  
  122. location = move.pull("location")
  123. quarry = move.pull("quarry")
  124. mineLocation = move.pull("mineLocation")
  125.  
  126. move.display()
  127.  
  128. while  tonumber(location["z"]) < tonumber(quarry["depth"]) + 1 do
  129.   sweepLeft()
  130.   sweepUp()
  131.   sweepRight()
  132.   sweepUp()
  133.   sweepForward()
  134. end
Advertisement
Add Comment
Please, Sign In to add comment