Advertisement
LaikaJ

Miner Turtle

Jan 18th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. --------- Variables ----------
  2. chest = 14
  3. torch = 15
  4. fuel = 16
  5. maxFuel = 100
  6.  
  7. --------- Functions ----------
  8. function checkFuel()
  9.     print(turtle.getFuelLevel())
  10.     if  turtle.getFuelLevel() < 1 then
  11.         print('Refueling')
  12.         refuel()
  13.     end
  14. end
  15.  
  16. function refuel()
  17.     turtle.select(16)
  18.     while turtle.getItemCount(fuel) > 0 and turtle.getFuelLevel() < maxFuel do
  19.         turtle.refuel(1)
  20.     end
  21. end
  22.  
  23. function forward()
  24.     checkFuel()
  25.     while not turtle.forward() do
  26.         turtle.dig()
  27.     end
  28. end
  29.  
  30. function clearBlocks()
  31.     while turtle.detectUp() or turtle.detectDown() do
  32.         turtle.digUp()
  33.         turtle.digDown()
  34.     end
  35. end
  36.  
  37. function left()
  38.     turtle.turnLeft()
  39.     turtle.dig()
  40.     forward()
  41. end
  42.  
  43. function turnAround()
  44.     turtle.turnLeft()
  45.     turtle.turnLeft()
  46. end
  47.  
  48. function right()
  49.     turtle.turnRight()
  50.     turtle.dig()
  51.     forward()
  52. end
  53.  
  54. function isFull()
  55.     for i = 1,16 do
  56.         if turtle.getItemCount(i) == 0 then
  57.             return false
  58.         end
  59.     end
  60.   return true
  61. end
  62.  
  63. function returnHome()
  64.     turnAround()
  65.     turtle.select(chest)
  66.     while not turtle.compare() do
  67.         forward()
  68.     end
  69.     for i=1, 12, 1 do
  70.         turtle.select(i)
  71.         turtle.drop()
  72.     end
  73.     turnAround()
  74.     while not turtle.detect() do
  75.         forward()
  76.     end
  77. end
  78.  
  79. function dropOffCheck()
  80.     if isFull() then
  81.         returnHome()
  82.     end
  83. end
  84.  
  85. function placeTorch()
  86.     turtle.turnRight()
  87.     turtle.select(torch)
  88.     turtle.place()
  89.     turtle.turnLeft()
  90. end
  91.  
  92.  
  93.  
  94. --------- Execution ----------
  95. lastTorch = 6
  96. while true do
  97.     dropOffCheck()
  98.     if lastTorch > 5 then
  99.         placeTorch()
  100.         lastTorch=0
  101.     end
  102.     forward()
  103.     clearBlocks()
  104.     left()
  105.     clearBlocks()
  106.     turnAround()
  107.     forward()
  108.     forward()
  109.     clearBlocks()
  110.     turnAround()
  111.     forward()
  112.     turtle.turnRight()
  113.     lastTorch = lastTorch+1
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement