Advertisement
superjaja05

Untitled

Sep 15th, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. local args = {...}
  2.  
  3. turn1 = 0
  4. RX = 0
  5. RZ = 0
  6. done2 = false
  7. block1 = turtle.getItemDetail()["name"]
  8.  
  9. textutils.slowPrint("Selected block: "..block1)
  10.  
  11. function rs()
  12. if args[1] == "up" then
  13. turtle.digUp()
  14. turtle.placeUp()
  15. end
  16. if args[1] == "down" then
  17. turtle.digDown()
  18. turtle.placeDown()
  19. end
  20. end
  21.  
  22. function turn()
  23. if (turn1 % 2 == 0) then
  24. turtle.turnRight()
  25. if turtle.inspect() == true then
  26. done2 = true
  27. end
  28. turtle.forward()
  29. turtle.turnRight()
  30. else
  31. turtle.turnLeft()
  32. if turtle.inspect() == true then
  33. done2 = true
  34. end
  35. turtle.forward()
  36. turtle.turnLeft()
  37. end
  38. turn1 = turn1+1
  39. RZ = RZ+1
  40. end
  41.  
  42. function insD()
  43. if turtle.inspectDown() then
  44. X1, X2 = turtle.inspectDown()
  45. return X2
  46. end
  47. end
  48.  
  49.  
  50. function search()
  51. print("Initalizing search for: "..block1)
  52. slot1 = 1
  53. done1 = false
  54. repeat
  55. print("Searching slot "..slot1)
  56. if turtle.getItemDetail(slot1) ~= nil then
  57. if turtle.getItemDetail(slot1)["name"] == block1 then
  58. turtle.select(slot1)
  59. turtle.transferTo(1)
  60. turtle.select(1)
  61. break
  62. else
  63. slot1 = slot1+1
  64. end
  65. else
  66. slot1 = slot1+1
  67. end
  68. if slot1 == 16 and turtle.getItemDetail(16) == nil then
  69. os.sleep(2)
  70. textutils.slowPrint("Not found.. rebooting")
  71. os.reboot()
  72. end
  73. until done1 == true
  74. term.clear()
  75. end
  76.  
  77. rs()
  78. repeat
  79. repeat
  80. if turtle.getItemDetail() ~= nil then
  81. if turtle.getItemDetail()["name"] ~= block1 then
  82. search()
  83. end
  84. end
  85. if turtle.getItemDetail() == nil then
  86. search()
  87. end
  88. turtle.forward()
  89. if (turn1 % 2 == 0) then
  90. RX = RX+1
  91. else
  92. RX = RX-1
  93. end
  94. if insD() ~= nil then
  95. if insD()["name"] ~= block1 then
  96. rs()
  97. end
  98. else
  99. if turtle.inspectDown() == false then
  100. rs()
  101. end
  102. end
  103. until turtle.inspect() == true
  104. turn()
  105. if done2 == true then break end
  106. if insD() ~= nil then
  107. if insD()["name"] ~= block1 then
  108. rs()
  109. end
  110. else
  111. if turtle.inspectDown() == false then
  112. rs()
  113. end
  114. end
  115. until turtle.inspect() == true or done2 == true
  116. print("Done!")
  117.  
  118. turtle.turnRight()
  119. i1 = 0
  120. repeat
  121. turtle.forward()
  122. i1 = i1+1
  123. until i1 == RZ
  124.  
  125. turtle.turnRight()
  126.  
  127. if RX ~= 0 then
  128. i2 = 0
  129. repeat
  130. turtle.back()
  131. i2 = i2+1
  132. until i2 == RX
  133. end
  134.  
  135. print("Layer Replacement Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement