Advertisement
Guest User

mining

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