Guest User

branchmining

a guest
Feb 27th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.11 KB | None | 0 0
  1. -- Variables
  2. local tArgs = { ... }
  3. distance = tonumber(tArgs[1])
  4. distance = distance or 8
  5. branchl = tonumber(tArgs[2])
  6. branchl = branchl or 3
  7. loops = tonumber(tArgs[3])
  8. loops = loops or 2
  9. ladder = tonumber(tArgs[4])
  10. ladder = ladder or 0
  11.  
  12. -- checks if ladder is in slot 2 if param is set
  13. function checkmaterials()
  14. if ladder == 1 then
  15. while turtle.getItemCount(2) <= 5*ladder do
  16. print("Please put " .. 5*loops.. " ladder in slot 2")
  17. sleep(5)
  18. end
  19. end
  20. end
  21. -- Functions --
  22.  
  23. --Fuels the turtle and waits for fuel if nothing left
  24. function tFuel(amount)
  25. if turtle.getItemCount(1) > 1 then
  26.   if turtle.getFuelLevel() < 3 then
  27.   turtle.select(1)
  28.    turtle.refuel(amount)
  29.    end
  30. else
  31. while turtle.getItemCount(1) < 1 do
  32.    print "Out of fuel!"
  33.    print "put fuel in slot 1"
  34.    sleep(5)
  35. end
  36. end
  37. end
  38.  
  39. -- move forward make sure there is no gravel stopping the turtle fuelcheck implemented here
  40. local function moveForward()
  41.                 while turtle.detect() do
  42.                 turtle.dig()
  43.                 end
  44.                 moved = false
  45.                 while not(moved) do
  46.                                 moved = turtle.forward()
  47.                 end
  48.                 tFuel(1)
  49. end
  50.  
  51. -- same like forward
  52. function moveUp()
  53. turtle.digUp()
  54. moved = false
  55. while not(moved) do
  56. while turtle.detectUp() do
  57.   turtle.digUp()
  58. end
  59. moved = turtle.up()
  60. end
  61. tFuel(1)
  62. end
  63.  
  64. -- in case there is a mob or player better include notmoved
  65. local function moveDown()
  66.                 for i = 1,5 do
  67.                 turtle.digDown()
  68.                 moved = false
  69.                 while not(moved) do
  70.                                 moved = turtle.down()
  71.                 end
  72.                 end
  73. tFuel(1)
  74. end
  75.  
  76. -- just cause im lazy for typing :D/>/>/>
  77. local function digginUpnDown()
  78. while turtle.detectUp() do
  79. turtle.digUp()
  80. end
  81. turtle.digDown()
  82. end
  83.  
  84. -- digs out the branch on both sides
  85. local function digBranch()
  86. for b = 1,branchl do
  87. moveForward()
  88. digginUpnDown()
  89. end
  90. turtle.turnLeft()
  91. moveForward()
  92. turtle.turnLeft()
  93. digginUpnDown()
  94. for b = 1,branchl do
  95. moveForward()
  96. digginUpnDown()
  97. end
  98. moveForward()
  99. digginUpnDown()
  100. for b = 1,branchl do
  101. moveForward()
  102. digginUpnDown()
  103. end
  104. turtle.turnLeft()
  105. moveForward()
  106. turtle.turnLeft()
  107. digginUpnDown()
  108. for b = 1,branchl do
  109. moveForward()
  110. digginUpnDown()
  111. end
  112. moveForward()
  113. digginUpnDown()
  114. end
  115.  
  116. -- dig the main Hall
  117. local function digHall()
  118. for h=0, distance do
  119. moveForward()
  120. digginUpnDown()
  121. if h%4 == 0 then
  122. turtle.turnRight()
  123. digBranch()
  124. turtle.turnLeft()
  125. end
  126. end
  127. turtle.turnLeft()
  128. moveForward()
  129. turtle.turnLeft()
  130. digginUpnDown()
  131. for h=0,distance do
  132. moveForward()
  133. digginUpnDown()
  134. end
  135. turtle.turnLeft()
  136. moveForward()
  137. turtle.turnLeft()
  138. digginUpnDown()
  139. end
  140.  
  141. -- going up to starting point again
  142. local function goback()
  143. if ladder == 1 then
  144. turtle.turnLeft()
  145. turtle.turnLeft()
  146. end
  147.  
  148. for i =1, loops*5+1 do
  149. if ladder == 1 then
  150. turtle.select(2)
  151. turtle.dig()
  152. turtle.place()
  153. moveUp()
  154. else
  155. moveUp()
  156. end
  157. end
  158. end
  159.  
  160. -- code excecution
  161. print("Work, work!")
  162. checkmaterials()
  163. for i=1,loops do
  164. tFuel(1)
  165. moveDown()
  166. digHall()
  167. end
  168. goback()
Advertisement
Add Comment
Please, Sign In to add comment