archlyn

Untitled

Dec 17th, 2022
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. --[[===============CONFIGURATION VARIABLES=======]]--
  2. --define void trash can for mod
  3. trashcan = "cyclic:trash"
  4.  
  5. --define chest for storage
  6. chest = "minecraft:chest"
  7.  
  8. --Low fuel level
  9. lowFuel = 500
  10.  
  11. --Length of edge of square to dig (in blocks)
  12. edgeLength = 4
  13. --[[==============================================]]--
  14.  
  15. --[[===============MACHINE STATE==================]]--
  16. --count the number of times the turtle has turned right (used to help turtle face forward
  17. turnCount = 0
  18.  
  19. --count position in column
  20. columnPostion = 0
  21.  
  22. --number of columns the turtle has dug
  23. columnCount = 0
  24.  
  25. --count the the number layers down the turtle has dug
  26. depthCounter = 0
  27.  
  28. --has the turtle hit bedrock?
  29. foundBedrock = false
  30. --[[==============================================]]--
  31.  
  32. term.clear()
  33.  
  34. function faceForward()
  35. for i = 1, 4 - turnCount do
  36. turtle.turnRight()
  37. end
  38. turnCount = 0
  39. end
  40.  
  41. function buildJunkTable() --add all items in turtle's inventory to junk table
  42. junk_table = {}
  43. local index = 1
  44. local data = {}
  45. for i = 1, 16 do
  46. turtle.select(i)
  47. if turtle.getItemCount(i) > 0 then
  48. junk_table[index] = turtle.getItemDetail().name
  49. index = index + 1
  50. end
  51. end
  52. turtle.select(1)
  53.  
  54. for i,v in ipairs(junk_table) do
  55. print (v)
  56. end
  57.  
  58. end
  59.  
  60. function confirmReadiness() --look for chest and trashcan
  61. local chestFound = chestExsists()
  62. faceForward()
  63. local trashcanFound = trashcanExsists()
  64. faceForward()
  65.  
  66. if (chestFound and not trashcanFound) then
  67. print ("Chest found but not trash can, place down trashcan from cyclic mod adjacent to the turtle!")
  68. return false
  69. else if (not chestFound and trashcanFound) then
  70. print("No chest found but trashcan found! Place standard minecraft chest adjacent to turtle")
  71. return false
  72. else if (not chestFound and not trashcanFound) then
  73. print ("Place standard minecraft chest and cyclic mod trashcan adjacent to turtle")
  74. return false
  75. else
  76. print("Chest AND Trashcan found! Ready!")
  77. return true
  78. end
  79. end
  80. end
  81. end
  82.  
  83. function chestExsists() --find chest for depositing inventory
  84.  
  85. local success, data = turtle.inspect()
  86.  
  87. for i = 0, 3 do
  88. turnCount = i
  89. success, data = turtle.inspect()
  90. if (data.name == chest and i == 0) then
  91. print("Please do not place chest directly in front of turtle!")
  92. return false
  93. elseif data.name == chest then
  94. return true
  95. else
  96. turtle.turnRight()
  97. end
  98. end
  99. return false
  100. end
  101.  
  102. function trashcanExsists() --find trashcan for garbage
  103.  
  104. local success, data = turtle.inspect()
  105. for i = 0, 3 do
  106. turnCount = i
  107. success, data = turtle.inspect()
  108. if (data.name == trashcan and i == 0) then
  109. print("Please do not place trashcan directly in front of turtle!")
  110. return false
  111. elseif data.name == trashcan then
  112. return true
  113. else
  114. turtle.turnRight()
  115. end
  116. end
  117. return false
  118. end
  119.  
  120. function deposit()
  121. if chestExsists() then
  122. for i = 1, 16 do
  123. turtle.select(i)
  124. turtle.drop()
  125. end
  126.  
  127. turtle.select(1)
  128. else
  129. print("Chest missing!")
  130. end
  131. end
  132.  
  133. function removeJunk()
  134.  
  135. if trashcanExsists() then
  136. for i = 1, 16 do
  137. turtle.select(i)
  138. for index, value in pairs(junk_table) do --This whole loop
  139. if turtle.getItemCount(i) > 0 then --itterates through
  140. if value == turtle.getItemDetail(i).name then --the values in the junk table
  141. turtle.drop() --compares them to the item names
  142. end --in the turtle's inventory and
  143. else --deletes them if they match
  144. break
  145. end
  146. end
  147. end
  148. turtle.select(1)
  149. else
  150. print("Trashcan missing!")
  151. return
  152. end
  153. end
  154.  
  155. function digColumn()
  156.  
  157. for columnPostion, edgeLength - 1 do
  158. if not turtle.forward() then
  159. turtle.dig()
  160. turtle.forward()
  161. end
  162. end
  163. end
  164.  
  165. function orient()
  166. if columnCount % 2 == 0 then
  167. turnCount = turnCount + 1
  168. turtle.turnRight()
  169. if turtle.detect() then
  170. turtle.dig()
  171. turtle.forward()
  172. turnCount = turnCount + 1
  173. turtle.turnRight()
  174. else
  175. turtle.forward()
  176. turnCount = turnCount + 1
  177. turtle.turnRight()
  178. end
  179. else
  180. turnCount = turnCount - 1
  181. turtle.turnLeft()
  182. if turtle.detect() then
  183. turtle.dig()
  184. turtle.forward()
  185. turnCount = turnCount - 1
  186. turtle.turnLeft()
  187. else
  188. turtle.forward()
  189. turnCount = turnCount - 1
  190. turtle.turnLeft()
  191. end
  192. end
  193. --columnCount = columnCount + 1
  194. end
  195.  
  196. function isInvetoryFull()
  197.  
  198. for i = 1,16 do
  199. if turtle.getItemCount(i) == 0 then
  200. return false
  201. end
  202. end
  203. return true
  204.  
  205. end
  206.  
  207. function digLayer()
  208.  
  209. for columnCount, (edgeLength - 1) do
  210. digColumn()
  211. orient()
  212. end
  213. digColumn()
  214.  
  215. turtle.turnRight()
  216.  
  217. for i = 1, edgeLength do
  218. turtle.forward()
  219. end
  220. turtle.turnRight()
  221. turnCount = 0
  222. columnCount = 0
  223. columnPostion = 0
  224. print ("Depth cout:" .. depthCounter)
  225.  
  226. end
  227.  
  228. function goHome()
  229. local oldTurnCount = turnCount
  230.  
  231. for i = 1,depthCounter do
  232. turtle.up()
  233. end
  234.  
  235. faceForward()
  236. turtle.turnLeft()
  237. turnCount = turnCount + 3
  238.  
  239. for i=1,columnCount do
  240. turle.forward()
  241. end
  242.  
  243. turtle.turnLeft()
  244. turnCount = turnCount - 1
  245.  
  246. for i=1,columnPostion do
  247. turtle.forward()
  248. end
  249.  
  250. turnCount = oldTurnCount
  251. end
  252.  
  253.  
  254. print("Current fuel level: "..turtle.getFuelLevel().."/"..turtle.getFuelLimit())
  255. if turtle.getFuelLevel() <= lowFuel then
  256. print("Please add more fuel")
  257. end
  258.  
  259.  
  260. if confirmReadiness() then
  261. buildJunkTable()
  262. deposit()
  263. faceForward()
  264. else
  265. return
  266. end
  267.  
  268. repeat
  269. digLayer()
  270. if not turtle.down() then
  271. turtle.digDown()
  272. turtle.down()
  273. end
  274. depthCounter = depthCounter + 1
  275. until isInvetoryFull() == true
  276. goHome()
Advertisement
Add Comment
Please, Sign In to add comment