melzneni

digArea

Feb 3rd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. args = { ... }
  2.  
  3. garbage = {
  4.     "minecraft:cobblestone",
  5.     "minecraft:dirt",
  6.     "minecraft:gravel",
  7.     "minecraft:diorite",
  8.     "minecraft:andesite",
  9.     "minecraft:granite",
  10.     "chisel:marble",
  11. }
  12.  
  13. function digForward()
  14.     while turtle.detect() do
  15.         turtle.dig()
  16.     end
  17. end
  18.  
  19. function digUp()
  20.     while turtle.detectUp() do
  21.         turtle.digUp()
  22.     end
  23. end
  24.  
  25. function digDown()
  26.     while turtle.detectDown() do
  27.         turtle.digDown()
  28.     end
  29. end
  30.  
  31. function forward(count)
  32.     for i = 1, count do
  33.         digForward(1)
  34.         while not turtle.forward() do
  35.             digForward(1)
  36.             turtle.attack()
  37.         end
  38.     end
  39. end
  40.  
  41. function up(count)
  42.     for i = 1, count do
  43.         digUp(1)
  44.         while not turtle.up() do
  45.             digUp(1)
  46.             turtle.attackUp()
  47.         end
  48.     end
  49. end
  50.  
  51. function down(count)
  52.     for i = 1, count do
  53.         digDown(1)
  54.         while not turtle.down() do
  55.             digDown(1)
  56.             turtle.attackDown()
  57.         end
  58.     end
  59. end
  60.  
  61. function turnLeft(count)
  62.     for i = 1, count do
  63.         turtle.turnLeft()
  64.     end
  65. end
  66.  
  67. function turnRight(count)
  68.     for i = 1, count do
  69.         turtle.turnRight()
  70.     end
  71. end
  72.  
  73. function dig3x3InFront()
  74.     forward(1)
  75.     turnLeft(1)
  76.     for i = 1, 2 do
  77.         digForward(1)
  78.         up(1)
  79.     end
  80.     digForward(1)
  81.     turnRight(2)
  82.     for i = 1, 2 do
  83.         digForward(1)
  84.         down(1)
  85.     end
  86.     digForward(1)
  87.     turnLeft(1)
  88. end
  89.  
  90. function isGarbage(val)
  91.     for index, value in ipairs(garbage) do
  92.         if value == val then
  93.             return true
  94.         end
  95.     end
  96.     return false
  97. end
  98.  
  99. function checkForAndDropGarbage()
  100.     for i = 1, 16 do
  101.         local data = turtle.getItemDetail(i)
  102.         if data then
  103.             if isGarbage(data.name) then
  104.                 turtle.select(i)
  105.                 turtle.drop()
  106.             end
  107.         end
  108.     end
  109.     turtle.select(1)
  110. end
  111.  
  112. function digLoop(length)
  113.     for i = 1, length do
  114.         dig3x3InFront()
  115.     end
  116.     checkForAndDropGarbage()
  117.     turtle.back()
  118.     turnRight(1)
  119.     forward(1)
  120.     dig3x3InFront()
  121.     dig3x3InFront()
  122.     dig3x3InFront()
  123.     turtle.back()
  124.     turnRight(1)
  125.     forward(1)
  126.     for i = 1, length do
  127.         dig3x3InFront()
  128.     end
  129.     checkForAndDropGarbage()
  130.     turtle.back()
  131.     turnLeft(1)
  132.     forward(1)
  133.     dig3x3InFront()
  134.     dig3x3InFront()
  135.     dig3x3InFront()
  136.     turtle.back()
  137.     turtle.turnLeft(1)
  138.     forward(1)
  139. end
  140.  
  141. function refuel()
  142.     for i=1,16 do
  143.         turtle.select(i);
  144.         turtle.refuel()
  145.     end
  146. end
  147.  
  148. function dropAll()
  149.     for i = 1, 16 do
  150.         turtle.select(i)
  151.         turtle.drop()
  152.     end
  153.     turtle.select(1)
  154. end
  155.  
  156. if table.getn(args) ~= 2 then
  157.     print("arguments 'width' and 'depth' expected (width is multiplied by 3)")
  158. else
  159.     local x = tonumber(args[1])
  160.     local y = tonumber(args[2]) - 2
  161.     for j = 1, x do
  162.         digLoop(y)
  163.         refuel()
  164.         if turtle.getItemCount(10) > 0 then
  165.             checkForAndDropGarbage()
  166.             turnLeft(1)
  167.             forward(6 * j)
  168.             dropAll()
  169.             turnLeft(2)
  170.             forward(6 * j)
  171.             turnLeft(1)
  172.         end
  173.     end
  174.     checkForAndDropGarbage()
  175.     turnLeft(1)
  176.     forward(6 * x)
  177.     dropAll()
  178.     turnRight(1)
  179. end
Add Comment
Please, Sign In to add comment