kisiseldwarf

mining_program

Jul 17th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isfull()
  2.     for i=1,16,1 do
  3.         if turtle.getItemSpace(i) > 0 then
  4.             return false
  5.         end
  6.     end
  7.     return true
  8. end
  9.  
  10. function digging()
  11.     if turtle.detect() then
  12.         while tonumber(turtle.inspect()[1]) == 13 then
  13.             turtle.dig()
  14.         end
  15.         turtle.dig()
  16.     end
  17. end
  18. function dig_blocs(z)
  19.     if z == 3 then
  20.         digging()
  21.         turtle.down()
  22.         z = z - 1
  23.         digging()
  24.         turtle.down()
  25.         z = z - 1
  26.         digging()
  27.     end
  28.     if z == 1 then
  29.         digging()
  30.         turtle.up()
  31.         z = z + 1
  32.         digging()
  33.         turtle.up()
  34.         z = z + 1
  35.         digging()
  36.     end
  37. end
  38.        
  39. function get_back(home)
  40.     local position = vector.new(gps.locate(5))
  41.     turtle.turnLeft()
  42.     turtle.turnLeft()
  43.     if not position.x then
  44.         print("Lost")
  45.         return 0
  46.     end
  47.     while position.z ~= home.z do
  48.         turtle.down()
  49.         position = vector.new(gps.locate())
  50.     end
  51.     position = vector.new(gps.locate())
  52.     while position.x ~= home.x or position.y ~= home.y do
  53.         position =vector.new(gps.locate())
  54.         if turtle.getFuelLevel() < 3 then
  55.             reload_fuel(2)
  56.         end
  57.         turtle.forward()
  58.     end
  59. end
  60.        
  61. function check_level(fuel_slot)
  62.     turtle.select(fuel_slot)
  63.     return turtle.getItemCount()
  64. end
  65.  
  66. function reload_fuel(fuel_slot)
  67.     local previous_slot = turtle.getSelectedSlot()
  68.     turtle.select(fuel_slot)
  69.     turtle.refuel(1)
  70.     turtle.select(previous_slot)
  71. end
  72.  
  73. local args = { ... }
  74.  
  75. function main(args)
  76.     local upordown = false
  77.     local z = 1
  78.     local home = vector.new(gps.locate())
  79.     if table.getn(args) < 1 then
  80.         print("Depth of mining is required as arg. 1")
  81.         return 1
  82.     end
  83.     local depth = tonumber(args[1])
  84.     for i=1,depth,1 do
  85.         if turtle.getFuelLevel() < 3 then
  86.             reload_fuel(2)
  87.         end
  88.         dig_blocs(z)
  89.         turtle.forward()
  90.         upordown = not upordown
  91.         if check_level(2) < 5 then
  92.             get_back(home)
  93.         end
  94.     end
  95.     get_back(home)
  96. end
  97.  
  98. main(args)
Advertisement
Add Comment
Please, Sign In to add comment