Advertisement
Blazuno

smart quarry

Dec 20th, 2024 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 KB | None | 0 0
  1. -- things not to veinmine
  2. local blacklist = {
  3.     "minecraft:stone",
  4.     "minecraft:dirt",
  5.     "minecraft:diorite",
  6.     "minecraft:andesite",
  7.     "minecraft:granite",
  8.     "minecraft:gravel",
  9.     "quark:slate"
  10. }
  11.  
  12. -- vars to identify the current pos relative to start point
  13. local x = 0
  14. local y = 0
  15. local z = 0
  16. local rotation = 0
  17.  
  18. -- params
  19. local x_size, y_size, depth, increment = ...
  20. x_size, y_size, depth, increment = tonumber(x_size), tonumber(y_size) - 1, tonumber(depth), tonumber(increment)
  21.  
  22.  
  23. --this is mostly for gravel
  24. local function better_forward()
  25.     while not turtle.forward() do
  26.         turtle.dig()
  27.         turtle.attack()
  28.     end
  29. end
  30.  
  31. -- function that returns to start point
  32. local function return_to_origin(up)
  33.     --switch for when something is blocking its way
  34.     local offset = false
  35.     -- rotating it to face the starting wall
  36.     if rotation ~= 2 then
  37.         if rotation > 2 then
  38.             repeat turtle.turnLeft() rotation = rotation - 1 until rotation == 2
  39.         elseif rotation < 2 then
  40.             repeat turtle.turnRight() rotation = rotation + 1 until rotation == 2
  41.         end
  42.     end
  43.     -- moving it out of the way if theres a block in front of it
  44.     if turtle.detect() and x ~= 0 then
  45.         offset = true
  46.         turtle.turnRight()
  47.         better_forward()
  48.         turtle.turnLeft()
  49.     end
  50.     -- returning to start
  51.     for i = 1,y do
  52.         better_forward()
  53.     end
  54.     turtle.turnRight()
  55.     if offset then
  56.         for i = 1,x-1 do
  57.             better_forward()
  58.         end
  59.     else
  60.         for i = 1,x do
  61.             better_forward()
  62.         end
  63.     end
  64.     --rotating back to 0
  65.     turtle.turnRight()
  66.     -- going back to the top if desired
  67.     if up then
  68.         for i = 1, z do
  69.             turtle.up()
  70.         end
  71.     end
  72. end
  73.  
  74.  
  75.  
  76. local function mine_sector()
  77.     -- switch to alternate digging left/right
  78.     local left = false
  79.     for i = 1, x_size do
  80.         --digging forward
  81.         for i = 1, y_size do
  82.             better_forward()
  83.             if not left then y = y + 1
  84.             else y = y - 1 end
  85.         end
  86.         --turning using switch
  87.         if x ~= x_size - 1 then
  88.             if not left then
  89.                 turtle.turnRight()
  90.                 better_forward()
  91.                 turtle.turnRight()
  92.                 left = true
  93.                 rotation = 2
  94.                 x = x + 1
  95.             else
  96.                 turtle.turnLeft()
  97.                 better_forward()
  98.                 turtle.turnLeft()
  99.                 left = false
  100.                 rotation = 0
  101.                 x = x + 1
  102.             end
  103.         end
  104.     end
  105. end
  106.  
  107.  
  108.  
  109. local function dig_deeper()
  110.     return_to_origin(false)
  111.     for i = 1, increment do
  112.         z = z + 1
  113.         turtle.digDown()
  114.         turtle.down()
  115.         if z == depth then return end
  116.     end
  117. end
  118.  
  119. local function quarry()
  120.     for i = 1,4 do
  121.         dig_deeper()
  122.         x,y,rotation = 0,0,0
  123.         if z >= depth then break end
  124.         mine_sector()
  125.     end
  126.     return_to_origin(true)
  127. end
  128.  
  129. quarry()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement