Guest User

mine

a guest
Aug 10th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 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. -- Program --
  31.  
  32. if not fs.exists("data/initialize") then
  33.   handle = fs.open("data/initialize", "w")
  34.   handle.write("false")
  35.   handle.close()
  36. end
  37.  
  38. handle = fs.open("data/initialize", "r")
  39. local initialize = handle.readAll()
  40.  
  41. if initialize == "true" then
  42.   print("quarry already started")
  43. else
  44.   print("Quarry initializing now...")
  45.  
  46.   reset()
  47.  
  48.   term.clear()
  49.   term.setCursorPos(1,1)
  50.   term.write("Welcome to tompy Mine")
  51.  
  52.   local quarry = {}
  53.  
  54.   term.setCursorPos(1,3)
  55.   term.write("Quarry Width: ")
  56.   quarry["width"] = read()
  57.  
  58.   term.setCursorPos(1,4)
  59.   term.write("Quarry Height: ")
  60.   quarry["height"] = read()
  61.  
  62.   term.setCursorPos(1,5)
  63.   term.write("Quarry Depth: ")
  64.   quarry["depth"] = read()
  65.  
  66.   move.store("quarry", quarry)
  67.  
  68.   move.store("initialize", true)
  69.  
  70.   local mineLocation = {x = 0, y = 0, z = 1}
  71.   move.store("mineLocation", mineLocation)  
  72. end
  73.  
  74. location = move.pull("location")
  75. quarry = move.pull("quarry")
  76. mineLocation = move.pull("mineLocation")
  77.  
  78. move.display()
  79.  
  80. while  tonumber(location["z"]) < tonumber(quarry["depth"]) + 1 do
  81.  
  82.   while tonumber(location["y"])%3 == 0 and tonumber(location["x"]) < tonumber(quarry["width"])-1 do
  83.     move.face(3)
  84.     dig()
  85.     move.forward()
  86.     location = move.pull("location")
  87.   end
  88.   dig()
  89.    
  90.   while tonumber(location["y"]) < tonumber(quarry["height"]) do
  91.     move.face(1)
  92.     dig()
  93.     move.up()
  94.     location = move.pull("location")
  95.     if tonumber(location["y"])%3 == 0 then
  96.       dig()
  97.       move.forward()
  98.       location = move.pull("location")      
  99.       break
  100.     end  
  101.   end
  102.  
  103.   while tonumber(location["x"]) > 0 do
  104.     move.face(1)
  105.     dig()
  106.     move.forward()
  107.     location = move.pull("location")
  108.   end
  109.   dig()        
  110.  
  111. end
Advertisement
Add Comment
Please, Sign In to add comment