Advertisement
dougdudu

Untitled

Sep 9th, 2020 (edited)
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. starting_x, starting_y, starting_z = gps.locate(5)
  2.  
  3. possible_sides = {"left", "right"}
  4.  
  5. function get_opposite_side()
  6.     local side = read()
  7.     if side == "left" then
  8.         return possible_sides[2]
  9.     elseif side == "right" then
  10.         return possible_sides[1]
  11.     else
  12.         return get_side()
  13.     end
  14. end
  15.  
  16. function is_int(number)
  17.     return (type(number) == "number") and (math.floor(number) == number)
  18. end
  19.  
  20. function get_num()
  21.     local blocks_to_dig = read()
  22.     if not is_int(blocks_to_dig) then
  23.         return get_num()
  24.     else
  25.         return tonumber(blocks_to_dig)
  26.     end
  27. end
  28.  
  29. blocks = get_num()
  30.  
  31. function turn_around(side)
  32.     local func_table = {["left"] = turtle.turnLeft, ["right"] = turtle.turnRight}
  33.     func_table[side]()
  34.     turtle.dig()
  35.     turtle.foward()
  36.     func_table[side]()
  37.     main_loop()
  38. end
  39.  
  40. function dig_column()
  41.     if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then
  42.         turtle.refuel()
  43.     end
  44.  
  45.     local success, data = turtle.inspectUp()
  46.  
  47.     local blocks_dug_up = 0
  48.  
  49.     while success and (data.name ~= "minecraft:air") do
  50.         turtle.digUp()
  51.         turtle.up()
  52.         blocks_dug_up = blocks_dug_up + 1
  53.         success, data = turtle.inspect()
  54.     end
  55.  
  56.     if table.pack(turtle.inspect())[2].name ~= "minecraft:air" then
  57.         turtle.dig()
  58.     end
  59.  
  60.     turtle.forward()
  61.  
  62.     if blocks_dug_up ~= 0 then
  63.         for i = 0, index - 1, 1 do
  64.             turtle.digDown()
  65.             turtle.down()
  66.         end
  67.     end
  68. end
  69.  
  70. function main_loop()
  71.     local blocks_dug_front = 0
  72.     while blocks_dug_front ~= blocks do
  73.         dig_column()
  74.         blocks_dug_front = blocks_dug_front + 1
  75.     end
  76.     turn_side = get_opposite_side()
  77.     turn_around(turn_side)
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement