Advertisement
melzneni

NEW_Mine

Feb 8th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.34 KB | None | 0 0
  1. args = { ... }
  2.  
  3. garbage = {
  4.     "minecraft:cobblestone",
  5.     "minecraft:dirt",
  6.     "minecraft:gravel",
  7.     "chisel:diorite",
  8.     "chisel:andesite",
  9.     "chisel:granite",
  10.     "chisel:marble",
  11.     "chisel:limestone",
  12. }
  13.  
  14. function digForward()
  15.     while turtle.detect() do
  16.         turtle.dig()
  17.     end
  18. end
  19.  
  20. function digUp()
  21.     while turtle.detectUp() do
  22.         turtle.digUp()
  23.     end
  24. end
  25.  
  26. function digDown()
  27.     while turtle.detectDown() do
  28.         turtle.digDown()
  29.     end
  30. end
  31.  
  32. local px = 0; local py = 0; local pz = 0
  33. local facing = 0
  34.  
  35. function back(count)
  36.     for i = 1, count do
  37.         if not turtle.back() then
  38.             turnLeft(2)
  39.             forward(1)
  40.             turnLeft(2)
  41.         else
  42.             if facing == 0 then px = px - 1
  43.             elseif facing == 1 then py = py - 1
  44.             elseif facing == 2 then px = px + 1
  45.             elseif facing == 3 then py = py + 1
  46.             end
  47.         end
  48.     end
  49. end
  50.  
  51. function forward(count)
  52.     for i = 1, count do
  53.         digForward(1)
  54.         while not turtle.forward() do
  55.             if not digForward(1) then
  56.                 turtle.attack()
  57.             end
  58.         end
  59.     end
  60.     if facing == 0 then px = px + count
  61.     elseif facing == 1 then py = py + count
  62.     elseif facing == 2 then px = px - count
  63.     elseif facing == 3 then py = py - count
  64.     end
  65. end
  66.  
  67. function up(count)
  68.     for i = 1, count do
  69.         digUp(1)
  70.         while not turtle.up() do
  71.             if not digUp(1) then
  72.                 turtle.attackUp()
  73.             end
  74.         end
  75.     end
  76.     pz = pz + count
  77. end
  78.  
  79. function down(count)
  80.     for i = 1, count do
  81.         digDown(1)
  82.         while not turtle.down() do
  83.             if not digDown(1) then
  84.                 turtle.attackDown()
  85.             end
  86.         end
  87.     end
  88.     pz = pz - count
  89. end
  90.  
  91. function turnLeft(count)
  92.     for i = 1, count do
  93.         turtle.turnLeft()
  94.     end
  95.     facing = facing - count
  96.     while facing < 0 do facing = facing + 4 end
  97. end
  98.  
  99. function turnRight(count)
  100.     for i = 1, count do
  101.         turtle.turnRight()
  102.     end
  103.     facing = facing + count
  104.     while facing > 3 do facing = facing - 4 end
  105. end
  106.  
  107. function dig3xXInFront(height)
  108.     forward(1)
  109.     turnLeft(1)
  110.     for i = 1, height - 1 do
  111.         digForward(1)
  112.         up(1)
  113.     end
  114.     checkForFilled()
  115.     digForward(1)
  116.     turnRight(2)
  117.     for i = 1, height - 1 do
  118.         digForward(1)
  119.         down(1)
  120.     end
  121.     checkForFilled()
  122.     digForward(1)
  123.     turnLeft(1)
  124. end
  125.  
  126. function checkForFilled()
  127.     if turtle.getItemCount(10) > 0 then
  128.         checkForAndDropGarbage()
  129.         local pos = getLocationData()
  130.         moveToPos({ 0, 0, 0, 0 })
  131.         checkForAndDropGarbage()
  132.         turnLeft(1)
  133.         dropAll()
  134.         moveToPos(pos)
  135.     end
  136. end
  137.  
  138. function isGarbage(val)
  139.     for index, value in ipairs(garbage) do
  140.         if value == val then
  141.             return true
  142.         end
  143.     end
  144.     return false
  145. end
  146.  
  147. function checkForAndDropGarbage()
  148.     for i = 1, 16 do
  149.         local data = turtle.getItemDetail(i)
  150.         if data then
  151.             if isGarbage(data.name) then
  152.                 turtle.select(i)
  153.                 turtle.drop()
  154.             end
  155.         end
  156.     end
  157.     turtle.select(1)
  158. end
  159.  
  160. function getLocationData()
  161.     return { px, py, pz, facing }
  162. end
  163.  
  164. function moveToPos(pos)
  165.     local lpx = pos[1]
  166.     local lpy = pos[2]
  167.     local lpz = pos[3]
  168.     local lfacing = pos[4]
  169.     if lpx ~= px then
  170.         if lpx > px then
  171.             setFacing(0)
  172.             forward(lpx - px)
  173.         else
  174.             setFacing(2)
  175.             forward(px - lpx)
  176.         end
  177.     end
  178.     if lpy ~= py then
  179.         if lpy > py then
  180.             setFacing(1)
  181.             forward(lpy - py)
  182.         else
  183.             setFacing(3)
  184.             forward(py - lpy)
  185.         end
  186.     end
  187.     if lpz ~= pz then
  188.         if lpz > pz then
  189.             up(lpz - pz)
  190.         else
  191.             down(pz - lpz)
  192.         end
  193.     end
  194.     setFacing(lfacing)
  195. end
  196.  
  197. function setFacing(lfacing)
  198.     while lfacing ~= facing do
  199.         turnLeft(1)
  200.     end
  201. end
  202.  
  203. function digLoop(length, height)
  204.     for i = 1, length do
  205.         dig3xXInFront(height)
  206.     end
  207.     --checkForAndDropGarbage()
  208.     back(1)
  209.     turnRight(1)
  210.     forward(1)
  211.     dig3xXInFront(height)
  212.     dig3xXInFront(height)
  213.     dig3xXInFront(height)
  214.     back(1)
  215.     turnRight(1)
  216.     forward(1)
  217.     for i = 1, length do
  218.         dig3xXInFront(height)
  219.     end
  220.     --checkForAndDropGarbage()
  221.     back(1)
  222.     turnLeft(1)
  223.     forward(1)
  224.     dig3xXInFront(height)
  225.     dig3xXInFront(height)
  226.     dig3xXInFront(height)
  227.     back(1)
  228.     turnLeft(1)
  229.     forward(1)
  230. end
  231.  
  232. function refuel()
  233.     for i = 1, 16 do
  234.         turtle.select(i);
  235.         turtle.refuel()
  236.     end
  237. end
  238.  
  239. function dropAll()
  240.     for i = 1, 16 do
  241.         turtle.select(i)
  242.         turtle.drop()
  243.     end
  244.     turtle.select(1)
  245. end
  246.  
  247. if table.getn(args) ~= 3 then
  248.     print("arguments 'width', 'depth' and 'height' expected (width is not 100% accourate)")
  249. else
  250.     local x = tonumber(args[1]) / 6
  251.     if tonumber(args[1]) % 6 ~= 0 then x = x + 1 end
  252.     local y = tonumber(args[2]) - 2
  253.     local z = tonumber(args[3])
  254.     for j = 1, x do
  255.         digLoop(y, z)
  256.         refuel()
  257.     end
  258.     checkForAndDropGarbage()
  259.     moveToPos({ 0, 0, 0, 3 })
  260.     dropAll()
  261.     turnRight(1)
  262. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement