Advertisement
Dombear

KopaczFull

Jul 30th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.32 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.     if heightFromStart > 0 then
  85.         for i = 1, heightFromStart do
  86.             moveUp3()
  87.         end
  88.     end
  89. end
  90.  
  91. local function moveBackToPosition()
  92.  
  93.     for i = 1, lengthFromStart do
  94.         moveForward()
  95.     end
  96.  
  97.     turtle.turnRight()
  98.  
  99.     for i = 1,widthFromStart do
  100.         moveForward()
  101.     end
  102.  
  103.     for i = 1, heightFromStart do
  104.         moveDown3()
  105.     end
  106.  
  107.     if direction == "FORWARD" then
  108.         turtle.turnLeft()
  109.     else
  110.         turtle.turnRight()
  111.     end
  112.  
  113. end
  114.  
  115. local function goToSliceStartPostion()
  116.  
  117.     if widthFromStart > 0 then
  118.         if direction == "FORWARD" then
  119.             turtle.turnLeft()
  120.         else
  121.             turtle.turnRight()
  122.         end
  123.         for i = 1, widthFromStart do
  124.             moveForward()
  125.         end
  126.     else
  127.         turtle.turnLeft()
  128.     end
  129.  
  130.     turtle.turnLeft()
  131.     for i = 1, lengthFromStart do
  132.         moveForward()
  133.     end
  134.  
  135.     turnBack()
  136. end
  137.  
  138.  
  139. local function moveAboveChest()
  140.     turtle.back()
  141. end
  142.  
  143. local function moveFromChest()
  144.     moveForward()
  145. end
  146.  
  147. local function dumpInventory()
  148.     local firstItem,lastItem = 1,16
  149.     for i=firstItem,lastItem do
  150.         turtle.select(i)
  151.         turtle.dropDown()
  152.     end
  153. end
  154.  
  155.  
  156. local function refuel()
  157.     --check current fuel level, find coal in inventory add to fuel level
  158.     while turtle.getFuelLevel() < (length * width) * 2 do
  159.         for i = 1, 16 do -- loop through the slots
  160.             turtle.select(i) -- change to the slot
  161.             if turtle.refuel(0) then -- if it's valid fuel
  162.                 local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot
  163.                 turtle.refuel(halfStack) -- consume half the stack as fuel
  164.                 break
  165.             end
  166.         end
  167.     end
  168. end
  169.  
  170. local function digSlice()
  171.  
  172.     while widthLeft > 0 do
  173.  
  174.         digForward()
  175.         moveForward()
  176.         digUpAndDown()
  177.         lengthLeft = lengthLeft - 1
  178.  
  179.         if direction == "FORWARD" then
  180.             lengthFromStart = lengthFromStart + 1
  181.         else
  182.             lengthFromStart = lengthFromStart - 1
  183.         end
  184.  
  185.         refuel()
  186.  
  187.         if inventoryFull() then
  188.             goToSliceStartPostion()
  189.             moveUp()
  190.  
  191.             moveAboveChest()
  192.             dumpInventory()
  193.             moveFromChest()
  194.  
  195.             moveBackToPosition()
  196.         end
  197.  
  198.         if lengthLeft == 0 then
  199.             lengthLeft = length - 1
  200.            
  201.             if widthLeft > 1 then
  202.                 startNextTunnel()
  203.                 widthFromStart = widthFromStart + 1
  204.             end        
  205.  
  206.             widthLeft = widthLeft - 1
  207.         end
  208.     end
  209. end
  210.  
  211.  
  212.  
  213. local function digTunnels()
  214.  
  215.     digForward()
  216.     moveForward()
  217.     digUpAndDown()
  218.  
  219.     for level = 1, height do
  220.  
  221.         widthFromStart = 0
  222.         lengthFromStart = 0
  223.         lengthLeft = lengthLeft - 1
  224.         digSlice()
  225.        
  226.         goToSliceStartPostion()
  227.         heightLeft = heightLeft - 1
  228.  
  229.         widthLeft = width
  230.         lengthLeft = length
  231.        
  232.         digToNextFloor()
  233.         heightFromStart = heightFromStart + 1
  234.  
  235.         direction = "FORWARD"
  236.     end
  237.  
  238.     goToSliceStartPostion()
  239.     moveUp()
  240.  
  241.     moveAboveChest()
  242.     dumpInventory()
  243. end
  244.  
  245. --START--
  246. print("Mining program")
  247.  
  248. print("Length of tunnel: ")
  249. input = io.read()
  250. length = tonumber(input)
  251. lengthLeft = length
  252. lengthFromStart = 0
  253.  
  254.  
  255. print("Width of tunnel: ")
  256. input = io.read()
  257. width = tonumber(input)
  258. widthLeft = width
  259. widthFromStart = 0
  260.  
  261. print("Height of tunnel: ")
  262. input = io.read()
  263. height = tonumber(input)
  264. heightLeft = height
  265. heightFromStart = 0
  266.  
  267. direction = "FORWARD"
  268.  
  269. refuel()
  270. digTunnels()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement