Advertisement
sosochka

stripMineClient.lua

Dec 21st, 2022 (edited)
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. local function findFuel()
  2. for i=1, 16 do
  3. turtle.select(i)
  4. local itemDetails = turtle.getItemDetail()
  5. if itemDetails ~= nil then
  6. if itemDetails.name == "minecraft:coal" then
  7. turtle.refuel()
  8. break
  9. end
  10. end
  11. end
  12. turtle.select(1)
  13. end
  14.  
  15. counter = 0
  16.  
  17. local function findAndPlaceTorch()
  18. if counter ~= 6 then
  19. counter = counter + 1
  20. return
  21. end
  22. counter = 1
  23. for i=1, 16 do
  24. turtle.select(i)
  25. local itemDetails = turtle.getItemDetail()
  26. if itemDetails ~= nil then
  27. if itemDetails.name == "minecraft:torch" then
  28. turtle.placeDown()
  29. break
  30. end
  31. end
  32. end
  33. turtle.select(1)
  34. end
  35.  
  36. local function cleanInventory()
  37. local blocksToClean = {
  38. "minecraft:cobblestone",
  39. "minecraft:deepslate",
  40. "minecraft:cobbled_deepslate",
  41. "minecraft:granite",
  42. "minecraft:diorite",
  43. "minecraft:gravel",
  44. "minecraft:dirt",
  45. "indreb:raw_uranium",
  46. "mekanism:raw_uranium",
  47. "minecraft:calcite",
  48. "minecraft:amethyst_block",
  49. "minecraft:tuff",
  50. "minecraft:smooth_basalt"
  51. }
  52. for i=1, 16 do
  53. turtle.select(i)
  54. local itemDetails = turtle.getItemDetail()
  55. if itemDetails ~= nil then
  56. for i=1,#blocksToClean do
  57. if itemDetails.name == blocksToClean[i] then
  58. turtle.dropDown()
  59. break
  60. end
  61. end
  62. end
  63. end
  64. turtle.select(1)
  65. end
  66.  
  67. -------------------------------------------------------------
  68.  
  69. --Locales
  70. local useTorches = false
  71. local movementSync = false
  72. local modem = nil
  73. local syncHostID = -1
  74. local transmitChannel = 228
  75. local recieveChannel = 229
  76.  
  77. --Sync channel setup
  78. term.clear()
  79. term.setCursorPos(1, 1)
  80. print("Is sync enabled?[y/n]")
  81. local input = io.stdin:read()
  82. if input == "y" then
  83. movementSync = true
  84. modem = peripheral.find("modem") or error("No modem found")
  85. if not modem.isWireless() then
  86. error("Modem not wireless")
  87. end
  88. modem.closeAll()
  89. modem.open(recieveChannel)
  90. end
  91.  
  92.  
  93. --Placing torches setup
  94. print("Do I need to place torches?[y/n]")
  95. input = io.stdin:read()
  96. if input == "y" then
  97. useTorches = true
  98. end
  99.  
  100. local hostStart = false
  101. while not hostStart do
  102. print("Waiting for host confirmation")
  103. local event, side, channel, replyChannel, message = os.pullEvent("modem_message")
  104. if message == "start" then
  105. hostStart = true
  106. end
  107. end
  108.  
  109. print("Started")
  110. sleep(5)
  111.  
  112. while true do
  113. --Fuel logic
  114. while turtle.getFuelLevel() == 0 do
  115. print("Fuel level 0 please refil")
  116. findFuel()
  117. end
  118. if turtle.getFuelLevel() <= 10 then
  119. print("Fuel level low, please refil")
  120. findFuel()
  121. end
  122.  
  123. --Fuel main digging and torch if specified
  124. turtle.dig()
  125.  
  126. if movementSync then
  127. while true do
  128. modem.transmit(transmitChannel, transmitChannel, "completedTurn")
  129. print("Message sent to host")
  130. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  131. if message == "continue" then
  132. break
  133. end
  134. end
  135. print("Recieved host message to continue")
  136. end
  137.  
  138. local didGoForward = turtle.forward()
  139. while not didGoForward do
  140. turtle.dig()
  141. didGoForward = turtle.forward()
  142. end
  143. turtle.digUp()
  144. turtle.digDown()
  145.  
  146. if useTorches then
  147. findAndPlaceTorch()
  148. end
  149.  
  150. --Fuel ouput
  151. print("Fuel level: " .. turtle.getFuelLevel())
  152.  
  153. --Cleaing inventory logic
  154. cleanInventory()
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement