Advertisement
EphemeralKap

Untitled

Dec 4th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. local distance = 0
  2.  
  3. function MoveFront()
  4. if turtle.detect() then
  5. turtle.dig()
  6. if turtle.forward() == false then
  7. MoveFront()
  8. end
  9. else
  10. turtle.forward()
  11. end
  12. end
  13.  
  14. function PlaceTorch()
  15. turtle.select(3)
  16. turtle.placeDown()
  17. turtle.select(1)
  18. end
  19.  
  20. function CheckDist()
  21. if distance % 8 == 0 then
  22. return true
  23. else
  24. return false
  25. end
  26. end
  27.  
  28. function DigUp()
  29. if turtle.detectUp() then
  30. turtle.digUp()
  31. end
  32. end
  33.  
  34. function DigDown()
  35. if turtle.detectDown() then
  36. turtle.digDown()
  37. end
  38. end
  39.  
  40. -- Mines 3x3 infront of the turtle.
  41. function Mine()
  42. MoveFront()
  43. DigUp()
  44. DigDown()
  45. turtle.turnLeft()
  46. MoveFront()
  47. DigUp()
  48. DigDown()
  49. turtle.turnRight()
  50. turtle.turnRight()
  51. MoveFront()
  52. MoveFront()
  53. DigUp()
  54. DigDown()
  55. turtle.back()
  56. turtle.turnLeft()
  57. end
  58.  
  59. -- Checks if chests are present in slot 2, and if torches are present in slot 3.
  60. function CheckForItem(n)
  61. --chest checking
  62. if n == 1 then
  63. if turtle.getItemDetail(2).name == "minecraft:chest" then
  64. return true
  65. else
  66. return false
  67. end
  68. end
  69.  
  70. --torch checking
  71. if n == 2 then
  72. if turtle.getItemDetail(2).name == "minecraft:torch" then
  73. return true
  74. else
  75. return false
  76. end
  77. end
  78. end
  79.  
  80.  
  81. -- true if deposits, false if it cant due to no chests
  82. function Deposit()
  83. if CheckForItem(1) then
  84. turtle.turnLeft()
  85. turtle.turnLeft()
  86. turtle.select(2)
  87. turtle.placeDown()
  88. turtle.select(1)
  89. for i = 4,16 do
  90. if turtle.getItemCount(i) > 0 then
  91. turtle.select(i)
  92. turtle.dropDown()
  93. end
  94. end
  95. turtle.select(1)
  96. turtle.turnLeft()
  97. turtle.turnLeft()
  98. return true
  99. else
  100. return false
  101. end
  102. end
  103.  
  104. -- attempts to refuel the fucker
  105. function Refuel()
  106. for i = 1,16 do
  107. if turtle.getItemCount(i) > 0 then
  108. turtle.select(i)
  109. if turtle.refuel(1) then
  110. break
  111. end
  112. end
  113. end
  114. turtle.select(1)
  115. end
  116.  
  117. -- deposit -> refuel -> mine
  118. while true do
  119. if turtle.getItemCount(16) > 0 then
  120. if CheckForItem(1) then
  121. Deposit()
  122. else
  123. break
  124. end
  125. elseif turtle.getFuelLevel() < 3 then
  126. Refuel()
  127. else
  128. Mine()
  129. distance = distance + 1 -- place torch every 8th block
  130. if CheckDist() then
  131. if CheckForItem(2) then
  132. PlaceTorch()
  133. end
  134. end
  135. end
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement