Guest User

Strip Mine Program

a guest
Dec 14th, 2023
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. args = {...}
  2.  
  3. chunkName = args[1]
  4.  
  5. chunksNum = 0
  6.  
  7. turtle.select(1)
  8.  
  9. queen = false
  10.  
  11. movingForward = true
  12.  
  13. turtID = 1
  14.  
  15. timeInMinutes = 1200
  16.  
  17. turnAroundTime = math.ceil(((timeInMinutes*60)/20)/2)
  18.  
  19.  
  20.  
  21. function fuelUp()
  22.  
  23. if turtle.getFuelLevel() < 50 then
  24.  
  25. print(turtle.getFuelLevel())
  26.  
  27. turtle.select(16)
  28. turtle.refuel()
  29.  
  30. turtle.select(15)
  31. turtle.refuel()
  32.  
  33.  
  34. end
  35.  
  36. turtle.select(1)
  37.  
  38. end
  39.  
  40.  
  41. function checkInventory(inventoryLimit)
  42.  
  43.  
  44. local isFull = true
  45.  
  46. for apple = 1, inventoryLimit do
  47. if turtle.getItemCount(apple) == 0 then
  48. isFull = false
  49. end
  50. end
  51. return isFull
  52. end
  53.  
  54.  
  55. function deposit()
  56.  
  57. if checkInventory(13) == true then
  58.  
  59. local bubble = 1
  60.  
  61. if queen == true then
  62.  
  63. bubble = 2
  64.  
  65. end
  66.  
  67. for apple = bubble, 13 do
  68. local data = turtle.getItemDetail(apple)
  69. if data ~= nil then
  70. if data.name ~= "create:crushed_copper_ore" and data.name ~= "create:crushed_zinc_ore" then
  71. turtle.select(apple)
  72. turtle.drop()
  73. end
  74. end
  75. end
  76.  
  77. if checkInventory(8) == true then
  78.  
  79. turtle.select(14)
  80.  
  81. while turtle.placeDown() == false do
  82.  
  83. turtle.digDown()
  84.  
  85. end
  86.  
  87. for apple = bubble, 13 do
  88.  
  89. if turtle.getItemCount(apple) ~= 0 then
  90.  
  91. turtle.select(apple)
  92. turtle.dropDown()
  93.  
  94. end
  95.  
  96.  
  97. end
  98.  
  99. turtle.select(14)
  100.  
  101. turtle.digDown()
  102.  
  103. end
  104.  
  105.  
  106. end
  107.  
  108. turtle.select(1)
  109.  
  110. end
  111.  
  112.  
  113. function move()
  114.  
  115. while turtle.forward() == false do
  116.  
  117. turtle.dig()
  118. deposit()
  119.  
  120. end
  121.  
  122. local has_block, data = turtle.inspectDown()
  123.  
  124. if data.name == "create:copper_ore" or data.name == "create:zinc_ore" then
  125.  
  126. turtle.digDown()
  127. deposit()
  128.  
  129. end
  130.  
  131.  
  132.  
  133. local has_block, data = turtle.inspectUp()
  134.  
  135. if data.name == "create:copper_ore" or data.name == "create:zinc_ore" then
  136. turtle.digUp()
  137. deposit()
  138. end
  139.  
  140.  
  141.  
  142. end
  143.  
  144.  
  145. function turnTurtleAround()
  146.  
  147. if tonumber(turtID) % 2 ~= 0 then
  148.  
  149. os.sleep(40)
  150.  
  151. end
  152.  
  153.  
  154. turtle.turnRight()
  155.  
  156. for x = 1, 14 do
  157.  
  158. move()
  159.  
  160. end
  161.  
  162. turtle.turnRight()
  163.  
  164. movingForward = false
  165.  
  166. end
  167.  
  168.  
  169. function mainCode()
  170.  
  171. for x = 1, turnAroundTime do
  172.  
  173.  
  174. while tonumber(message) ~= chunksNum do
  175.  
  176. print("message:"..message.."~=".."chunksNum:"..tostring(chunksNum))
  177.  
  178. for x = 1, 4 do
  179.  
  180. move()
  181.  
  182. fuelUp()
  183.  
  184. end
  185.  
  186. for x = 1, 8 do
  187.  
  188. while turtle.forward() == false do
  189.  
  190. turtle.dig()
  191. deposit()
  192.  
  193. end
  194.  
  195. end
  196.  
  197. for x = 1, 4 do
  198.  
  199. move()
  200.  
  201. fuelUp()
  202.  
  203. end
  204.  
  205. if movingForward == true then
  206.  
  207. chunksNum = chunksNum + 1
  208.  
  209. else
  210.  
  211. chunksNum = chunksNum -1
  212.  
  213. end
  214.  
  215. end
  216.  
  217. -- Rednet stuff
  218.  
  219. print("starting rednet")
  220.  
  221. if tonumber(turtID) == 8 then
  222.  
  223. while true do
  224.  
  225. rednet.broadcast(done, chunkName..tostring(turtID-1))
  226.  
  227. print("test1")
  228.  
  229. id, message = rednet.receive(chunkName.."chunk", 3)
  230.  
  231. print("test2")
  232.  
  233. if message ~= nil then
  234.  
  235. print("test3")
  236.  
  237. break
  238.  
  239. end
  240.  
  241. end
  242.  
  243. end
  244.  
  245. if tonumber(turtID) < 8 and tonumber(turtID) ~= 1 then
  246.  
  247. while true do
  248.  
  249. print("test1")
  250.  
  251. id, message = rednet.receive(chunkName..tostring(turtID))
  252.  
  253. print("test2")
  254.  
  255. rednet.broadcast(done, chunkName..tostring(turtID-1))
  256.  
  257. print("test3")
  258.  
  259. id, message = rednet.receive(chunkName.."chunk", 1.5)
  260.  
  261. print("test4")
  262.  
  263.  
  264. if message ~= nil then
  265.  
  266. print("test5")
  267.  
  268. break
  269.  
  270. end
  271.  
  272. end
  273.  
  274.  
  275. end
  276.  
  277. if tonumber(turtID) == 1 then
  278.  
  279.  
  280. turtle.equipRight(1)
  281.  
  282. rednet.open("right")
  283.  
  284. rednet.broadcast("Im stil going:"..chunksNum, "Margey"..chunkName)
  285.  
  286. while true do
  287.  
  288. print("test1")
  289.  
  290. id, message = rednet.receive(chunkName..tostring(turtID))
  291.  
  292. print("test2")
  293.  
  294. if movingForward == true then
  295.  
  296. rednet.broadcast(tostring(chunksNum + 1), chunkName.."chunk")
  297.  
  298. message = chunksNum + 1
  299.  
  300. else
  301.  
  302. rednet.broadcast(tostring(chunksNum - 1), chunkName.."chunk")
  303.  
  304. message = chunksNum - 1
  305.  
  306. end
  307.  
  308. print("test3")
  309.  
  310. break
  311.  
  312. end
  313.  
  314. turtle.equipRight(1)
  315.  
  316. end
  317.  
  318. print("stoping rednet")
  319.  
  320. end
  321.  
  322. end
  323.  
  324. fuelUp()
  325.  
  326.  
  327.  
  328. if args[2] ~= nil then
  329.  
  330. turtle.equipRight(1)
  331.  
  332. rednet.open("right")
  333.  
  334. queen = true
  335.  
  336. numberOfTurts = 1
  337.  
  338.  
  339. while numberOfTurts < 8 do
  340.  
  341. numberOfTurts = numberOfTurts + 1
  342.  
  343. id, message = rednet.receive(chunkName)
  344.  
  345. os.sleep(0.2)
  346.  
  347. rednet.broadcast(tostring(numberOfTurts), chunkName)
  348.  
  349. end
  350.  
  351. os.sleep(1.5)
  352.  
  353. rednet.broadcast(tostring(chunksNum + 1), chunkName.."chunk")
  354.  
  355. turtle.equipRight(1)
  356.  
  357. else
  358.  
  359. rednet.open("left")
  360.  
  361. rednet.broadcast("", chunkName)
  362.  
  363. id, turtID = rednet.receive(chunkName)
  364.  
  365.  
  366. end
  367.  
  368.  
  369.  
  370. print("Turtle Number "..turtID.." Is Ready!")
  371.  
  372.  
  373. if queen == false then
  374.  
  375. id, message = rednet.receive(chunkName.."chunk")
  376.  
  377. else
  378.  
  379. message = 1
  380.  
  381. end
  382.  
  383. mainCode()
  384.  
  385. turnTurtleAround()
  386.  
  387. message = tostring(tonumber(message) - 2)
  388.  
  389. mainCode()
  390.  
  391. if queen == true then
  392.  
  393. turtle.equipLeft(1)
  394.  
  395. end
  396.  
  397. print("Im done mining!!!!!!")
  398.  
Add Comment
Please, Sign In to add comment