EphemeralKap

Untitled

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