Advertisement
Dombear

Kopacz

Jul 29th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.92 KB | None | 0 0
  1. local function digToNextFloor()
  2.     turtle.down()
  3.     turtle.digDown()
  4.     turtle.down()
  5.     turtle.digDown()
  6.     turtle.down()
  7.     turtle.digDown()
  8. end
  9.  
  10. local function moveUp3()
  11.     turtle.up()
  12.     turtle.up()
  13.     turtle.up()
  14. end
  15.  
  16. local function moveDown3()
  17.     turtle.down()
  18.     turtle.down()
  19.     turtle.down()
  20. end
  21.  
  22.  
  23. local function turnBack()
  24.     turtle.turnRight()
  25.     turtle.turnRight()
  26. end
  27.  
  28. local function digForward()
  29.     if turtle.detect() then
  30.         turtle.dig()
  31.     end
  32. end
  33.  
  34. local function digUpAndDown()
  35.     if turtle.detectUp() then
  36.         turtle.digUp()
  37.     end
  38.  
  39.     if turtle.detectDown() then
  40.         turtle.digDown()       
  41.     end
  42. end
  43.  
  44. local function moveForward()
  45.  
  46.     while turtle.detect() do
  47.         turtle.dig()   
  48.         sleep(0.3) 
  49.     end
  50.     if turtle.detect() == false then
  51.         turtle.forward()
  52.     end
  53.  
  54. end
  55.  
  56.  
  57. local function startNextTunnel()
  58.     if direction == "FORWARD" then
  59.         turtle.turnRight()
  60.         moveForward()
  61.         digUpAndDown()
  62.         turtle.turnRight()
  63.         direction = "BACKWARD"
  64.     else
  65.         turtle.turnLeft()
  66.         moveForward()
  67.         digUpAndDown()
  68.         turtle.turnLeft()
  69.         direction = "FORWARD"
  70.     end
  71.    
  72. end
  73.  
  74. local function inventoryFull()
  75.     for i = 1,16 do
  76.         if turtle.getItemCount(i) == 0 then    
  77.           return false
  78.         end
  79.     end
  80.     return true
  81. end
  82.  
  83. local function moveUp()
  84.     print("Moving up " .. heightFromStart * 3 .. " blocks")
  85.     input = io.read()
  86.     if heightFromStart > 0 then
  87.         for i = 1, heightFromStart do
  88.             moveUp3()
  89.         end
  90.     end
  91. end
  92.  
  93. local function moveBackToPosition()
  94.  
  95.     print("Moving back to position " .. lengthFromStart .. " length")
  96.     input = io.read()
  97.     for i = 1, lengthFromStart do
  98.         moveForward()
  99.     end
  100.  
  101.     turtle.turnRight()
  102.  
  103.     print("Moving back to position " .. widthFromStart .. " width")
  104.     input = io.read()
  105.     for i = 1,widthFromStart do
  106.         moveForward()
  107.     end
  108.  
  109.     print("Moving back to position " .. heightFromStart .. " height")
  110.     input = io.read()
  111.     for i = 1, heightFromStart do
  112.         moveDown3()
  113.     end
  114.  
  115.     if direction == "FORWARD" then
  116.         turtle.turnLeft()
  117.     else
  118.         turtle.turnRight()
  119.     end
  120.  
  121.     print("Position done")
  122.     input = io.read()
  123. end
  124.  
  125. local function goToSliceStartPostion()
  126.  
  127.     print("Moving to start position")
  128.     input = io.read()
  129.     if widthFromStart > 0 then
  130.         if direction == "FORWARD" then
  131.             turtle.turnLeft()
  132.         else
  133.             turtle.turnRight()
  134.         end
  135.         print("Moving for " .. widthFromStart.. " blocks (width)")
  136.         input = io.read()
  137.         for i = 1, widthFromStart do
  138.             moveForward()
  139.         end
  140.     else
  141.         turtle.turnLeft()
  142.     end
  143.  
  144.     turtle.turnLeft()
  145.     print("Moving for " .. lengthFromStart .. " blocks (length)")
  146.     input = io.read()
  147.     for i = 1, lengthFromStart do
  148.         moveForward()
  149.     end
  150.  
  151.     turnBack()
  152.     print("Done")
  153.     input = io.read()
  154. end
  155.  
  156.  
  157. local function moveAboveChest()
  158.     turtle.back()
  159.     print("Moved above chest")
  160.     input = io.read()
  161. end
  162.  
  163. local function moveFromChest()
  164.     moveForward()
  165. end
  166.  
  167. local function dumpInventory()
  168.     local firstItem,lastItem = 1,16
  169.     for i=firstItem,lastItem do
  170.         turtle.select(i)
  171.         turtle.dropDown()
  172.     end
  173. end
  174.  
  175.  
  176. local function refuel()
  177.     --check current fuel level, find coal in inventory add to fuel level
  178.     while turtle.getFuelLevel() < (length * 2) + 10 do
  179.         for i = 1, 16 do -- loop through the slots
  180.             turtle.select(i) -- change to the slot
  181.             if turtle.refuel(0) then -- if it's valid fuel
  182.                 local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot
  183.                 turtle.refuel(halfStack) -- consume half the stack as fuel
  184.                 break
  185.             end
  186.         end
  187.     end
  188. end
  189.  
  190. local function digSlice()
  191.  
  192.     while widthLeft > 0 do
  193.  
  194.         digForward()
  195.         moveForward()
  196.         digUpAndDown()
  197.         lengthLeft = lengthLeft - 1
  198.  
  199.         if direction == "FORWARD" then
  200.             lengthFromStart = lengthFromStart + 1
  201.         else
  202.             lengthFromStart = lengthFromStart - 1
  203.         end
  204.  
  205.         refuel()
  206.  
  207.         if inventoryFull() then
  208.             goToSliceStartPostion()
  209.             moveUp()
  210.  
  211.             moveAboveChest()
  212.             dumpInventory()
  213.             moveFromChest()
  214.  
  215.             moveBackToPosition()
  216.         end
  217.  
  218.         if lengthLeft == 0 then
  219.             lengthLeft = length - 1
  220.            
  221.             if widthLeft > 1 then
  222.                 startNextTunnel()
  223.                 widthFromStart = widthFromStart + 1
  224.             end        
  225.  
  226.             widthLeft = widthLeft - 1
  227.         end
  228.     end
  229. end
  230.  
  231.  
  232.  
  233. local function digTunnels()
  234.  
  235.     digForward()
  236.     moveForward()
  237.     digUpAndDown()
  238.  
  239.     for level = 1, height do
  240.  
  241.         widthFromStart = 0
  242.         lengthFromStart = 0
  243.         lengthLeft = lengthLeft - 1
  244.         digSlice()
  245.        
  246.         goToSliceStartPostion()
  247.         heightLeft = heightLeft - 1
  248.  
  249.         widthLeft = width
  250.         lengthLeft = length
  251.        
  252.         digToNextFloor()
  253.         heightFromStart = heightFromStart + 1
  254.  
  255.         direction = "FORWARD"
  256.     end
  257. end
  258.  
  259. --START--
  260. print("Mining program")
  261.  
  262. print("Length of tunnel: ")
  263. input = io.read()
  264. length = tonumber(input)
  265. lengthLeft = length
  266. lengthFromStart = 0
  267.  
  268.  
  269. print("Width of tunnel: ")
  270. input = io.read()
  271. width = tonumber(input)
  272. widthLeft = width
  273. widthFromStart = 0
  274.  
  275. print("Height of tunnel: ")
  276. input = io.read()
  277. height = tonumber(input)
  278. heightLeft = height
  279. heightFromStart = 0
  280.  
  281. direction = "FORWARD"
  282.  
  283. refuel()
  284. digTunnels()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement