DreamGamer

ComputerCraft Mining Programm

Dec 21st, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.42 KB | None | 0 0
  1. -- Program by DreamCoding / DreamGamer
  2. -- Youtube: /dr34m94m3r
  3. -- Web: http://DreamGamer.de
  4.  
  5. local distance = 0
  6. local torch = 0
  7.  
  8.  
  9.  
  10. function startMining(lenght)
  11.  
  12.     for i1=1, lenght, 1 do
  13.         dig()
  14.         goForward()
  15.         turnRight(1)
  16.         dig()
  17.         digUp()
  18.         goUp()
  19.         dig()
  20.         digUp()
  21.         goUp()
  22.         dig()
  23.         digDown()
  24.         goDown()
  25.         digDown()
  26.         goDown()
  27.         turnLeft(1)
  28.  
  29.         checkUnderground()
  30.         checkInv()
  31.         checkFuel()
  32.  
  33.         distance = distance + 1
  34.         torch = torch + 1
  35.  
  36.         checkLight()
  37.  
  38.         print("Distance: " .. distance)
  39.     end -- for
  40.  
  41.     turnLeft(2)
  42.  
  43.     for i3=1, distance,1 do
  44.         dig()
  45.         goForward()
  46.     end
  47.  
  48.     turnLeft(2)
  49.  
  50.  
  51.  
  52. end
  53.  
  54.  
  55.  
  56. function goDown()
  57.     while turtle.detectDown() do
  58.         turtle.digDown()
  59.         sleep(0.5)
  60.     end
  61.  
  62.     turtle.down()
  63. end
  64.  
  65. function digUp()
  66.     while turtle.detectUp() do
  67.         turtle.digUp()
  68.         sleep(0.5)
  69.     end
  70. end
  71.  
  72. function digDown()
  73.     while turtle.detectDown() do
  74.         turtle.digDown()
  75.         sleep(0.5)
  76.     end
  77. end
  78.  
  79.  
  80.  
  81. function goUp()
  82.     turtle.up()
  83. end
  84.  
  85.  
  86. function goForward()
  87.     while turtle.detect() do
  88.         turtle.dig()
  89.         sleep(0.5)
  90.     end
  91.  
  92.     turtle.forward()
  93. end
  94.  
  95.  
  96. function goBack()
  97.     while turtle.detect() do
  98.         turtle.dig()
  99.         sleep(0.5)
  100.     end
  101.  
  102.     turtle.back()
  103. end
  104.  
  105.  
  106. function turnRight(turnNumber)
  107.     for i=1, turnNumber, 1 do
  108.         turtle.turnRight()
  109.     end
  110. end
  111.  
  112. function turnLeft(turnNumber)
  113.     for i=1, turnNumber, 1 do
  114.         turtle.turnLeft()
  115.     end
  116. end
  117.  
  118.  
  119. function dig()
  120.     while turtle.detect() do
  121.         turtle.dig()
  122.         sleep(0.5)
  123.     end
  124.  
  125. end
  126.  
  127.  
  128.  
  129. function checkInv()
  130.     if turtle.getItemCount(14) == 0 then
  131.         while turtle.getItemCount(14) == 0 do
  132.             print("Missing Ender chest!")
  133.             sleep(10)
  134.         end
  135.     else
  136.  
  137.  
  138.         if turtle.getItemCount(13) > 1 then
  139.             local slot = 2
  140.  
  141.  
  142.             turnRight(1)
  143.             turtle.select(14)
  144.             turtle.place()
  145.  
  146.             print("Clear Inventory...")
  147.  
  148.                 while turtle.getItemCount(13) > 0 do
  149.                     if slot < 14 then
  150.                         turtle.select(slot)
  151.                         sleep(0.2)
  152.  
  153.                         if turtle.detect() then
  154.                             turtle.drop(64)
  155.                         else
  156.                             print("No chest?")
  157.                         end -- if
  158.                         slot = slot + 1
  159.                     else
  160.                         print("No Space in Inventory")
  161.                         sleep(30)
  162.                         slot = 2
  163.                     end -- if
  164.  
  165.             end -- while
  166.  
  167.             turtle.select(14)
  168.             turtle.dig()
  169.             turtle.select(1)
  170.             turnLeft(1)
  171.  
  172.             print("Inventory cleared!")
  173.         end --  if
  174.     end -- if
  175. end -- function
  176.  
  177.  
  178. function checkFuel()
  179.  
  180.     if turtle.getFuelLevel() < 10 then
  181.         turtle.select(15)
  182.         print("Out of Fuel! Try to get Fuel...")
  183.         print("Fuel Level:" .. turtle.getFuelLevel())
  184.         turtle.refuel(64)
  185.         turtle.select(1)
  186.  
  187.         for i2=1, 13, 1 do
  188.  
  189.             turtle.select(i2)
  190.             if turtle.refuel(0) then
  191.                 turtle.refuel(64)
  192.                 print("Fuel Level:" .. turtle.getFuelLevel())
  193.             end -- if
  194.         end -- for
  195.     end -- if
  196. end -- function
  197.  
  198.  
  199. function checkLight()
  200.  
  201.     if torch == 5 then
  202.         turnRight(1)
  203.         digUp()
  204.         goUp()
  205.         turtle.select(16)
  206.         goForward()
  207.  
  208.         if not turtle.detect() then
  209.             turtle.select(1)
  210.             turtle.place()
  211.             turtle.select(16)
  212.         end -- if
  213.  
  214.         turnLeft(2)
  215.         dig()
  216.         goForward()
  217.         turnRight(2)
  218.         turtle.place()
  219.         turnLeft(1)
  220.         digDown()
  221.         goDown()
  222.  
  223.  
  224.         torch = 0
  225.     end -- if
  226.  
  227. end --  function
  228.  
  229.  
  230.  
  231. function checkUnderground()
  232.  
  233.     if not turtle.detectDown() then
  234.         turtle.select(1)
  235.         turtle.placeDown()
  236.     end
  237.  
  238. end
  239.  
  240. print("Put in slot 14 an Ender chest in slot 15 fuel and in slot 16 torches!")
  241. print("------------------------")
  242.  
  243.  
  244. print("Mining lenght: ")
  245.  
  246. local lenght = read()
  247.  
  248. startMining(lenght)
Add Comment
Please, Sign In to add comment