Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. --[[
  2. How about no.
  3. ]]
  4.  
  5. local CHEST_SLOT = 16
  6. local PIT_WIDTH = 3
  7. local PIT_LENGTH = 3
  8. local PIT_DEPTH = 45
  9.  
  10. local function log(str, ...)
  11. print(string.format(str, ...))
  12. end
  13.  
  14. local function transfer_inventory()
  15. local move_above_chest = turtle.up()
  16. if move_above_chest then
  17. turtle.select(CHEST_SLOT)
  18. local chest_slot_info = turtle.getItemDetail()
  19. if chest_slot_info and chest_slot_info.name == 'enderstorage:ender_storage' then
  20. local place_chest_belove = turtle.placeDown(CHEST_SLOT)
  21. if place_chest_belove then
  22. for slot = 1, 15 do
  23. turtle.select(slot)
  24. local slot_items = turtle.getItemCount(slot)
  25. if slot_items > 0 then
  26. turtle.select(slot)
  27. local transfered_item = turtle.dropDown(slot_items)
  28. if transfered_item then
  29. log('Transfered %i items from slot %i to ME system.', slot_items, slot)
  30. end
  31. end
  32. end
  33. turtle.select(16)
  34. turtle.digDown()
  35. for slot = 1, 16 do
  36. turtle.select(slot)
  37. local chest_info = turtle.getItemDetail()
  38. if chest_info and chest_info.name == 'enderstorage:ender_storage' then
  39. turtle.transferTo(CHEST_SLOT)
  40. break
  41. end
  42. end
  43. else
  44. log('Unable to place our Ender Chest below us, what happened?')
  45. end
  46. else
  47. log("Place an Ender Chest in slot 16!")
  48. end
  49. turtle.down()
  50. end
  51. end
  52.  
  53. local function check_inventory()
  54. local total_slots = 15
  55. local used_slots = 0
  56. for slot = 1, total_slots do
  57. local count = turtle.getItemCount(slot)
  58. if count > 0 then
  59. used_slots = used_slots + 1
  60. end
  61. end
  62. if used_slots >= total_slots then
  63. log('Inventory full, transfering...')
  64. transfer_inventory()
  65. end
  66. end
  67.  
  68.  
  69. local function forward()
  70. local success = turtle.forward()
  71. if not success then
  72. turtle.dig()
  73. local second_try = turtle.forward()
  74. return second_try
  75. end
  76. return success
  77. end
  78.  
  79. local function pit()
  80. local direction = 'forwards'
  81. local moving = 'right'
  82. local first = true
  83. local start_x, start_z, start_y = gps.locate(5)
  84.  
  85. log('Starting at layer %i', start_y)
  86. log('Going to layer %i', PIT_DEPTH)
  87.  
  88. for y = start_y, PIT_DEPTH, -1 do
  89. for x = 1, PIT_WIDTH do
  90. for z = 1, PIT_LENGTH - 1 do
  91. check_inventory()
  92. turtle.digDown()
  93. forward()
  94. end
  95.  
  96. turtle.digDown()
  97.  
  98. if x < PIT_WIDTH then
  99. if moving == 'right' then
  100. if direction == 'forwards' then
  101. turtle.turnRight()
  102. forward()
  103. turtle.digDown()
  104. turtle.turnRight()
  105. direction = 'backwards'
  106. else
  107. turtle.turnLeft()
  108. forward()
  109. turtle.digDown()
  110. turtle.turnLeft()
  111. direction = 'forwards'
  112. end
  113. else
  114. if direction == 'forwards' then
  115. turtle.turnLeft()
  116. forward()
  117. turtle.digDown()
  118. turtle.turnLeft()
  119. direction = 'backwards'
  120. else
  121. turtle.turnRight()
  122. forward()
  123. turtle.digDown()
  124. turtle.turnRight()
  125. direction = 'forwards'
  126. end
  127. end
  128. end
  129. end
  130.  
  131. if moving == 'right' then
  132. if direction == 'forwards'then
  133. turtle.turnRight()
  134. turtle.turnRight()
  135. direction = 'backwards'
  136. moving = 'left'
  137. else
  138. turtle.turnLeft()
  139. turtle.turnLeft()
  140. direction = 'forwards'
  141. moving = 'right'
  142. end
  143. else
  144. if direction == 'forwards'then
  145. turtle.turnLeft()
  146. turtle.turnLeft()
  147. direction = 'backwards'
  148. moving = 'left'
  149. else
  150. turtle.turnRight()
  151. turtle.turnRight()
  152. direction = 'forwards'
  153. moving = 'right'
  154. end
  155. end
  156.  
  157. if y > PIT_DEPTH then
  158. log('Moving down, starting layer %i', y - 1)
  159. turtle.down()
  160. end
  161. end
  162.  
  163. local end_x, end_z, end_y = gps.locate(5)
  164. for z = end_y, start_y do
  165. if z > start_y then
  166. turtle.up()
  167. end
  168. end
  169.  
  170. transfer_inventory()
  171. end
  172.  
  173. pit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement