kisiseldwarf

mining_program

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