dcchill

turt

Apr 24th, 2023 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. -- Initialize a variable to keep track of the turtle's current state
  2. local turtleState = "waiting"
  3.  
  4. while true do
  5. -- Check the turtle's current state
  6. if turtleState == "waiting" then
  7. -- Wait for redstone signal on the back to break a block
  8. while not rs.getInput("back") do
  9. sleep(0.1)
  10. end
  11.  
  12. -- Check if there's a block in front of the turtle
  13. if turtle.detect() then
  14. -- Set the turtle's state to "breaking"
  15. turtleState = "breaking"
  16.  
  17. -- Attempt to dig the block
  18. turtle.dig()
  19.  
  20. -- Wait for a few seconds to give the turtle time to break the block
  21. sleep(3)
  22.  
  23. -- Check if the block was successfully broken
  24. if not turtle.detect() then
  25. print("Block broken!")
  26. -- Set the turtle's state to "placing"
  27. turtleState = "placing"
  28. else
  29. print("Failed to break the block.")
  30. -- Set the turtle's state back to "waiting"
  31. turtleState = "waiting"
  32. end
  33. else
  34. print("No block to break.")
  35. end
  36. elseif turtleState == "breaking" then
  37. -- Wait for redstone signal on the back to place a block
  38. while not rs.getInput("back") do
  39. sleep(0.1)
  40. end
  41.  
  42. -- Check if the turtle has a block to place
  43. if turtle.getItemCount(1) > 0 then
  44. -- Wait for a redstone signal on the back before placing the block
  45. while not rs.getInput("back") do
  46. sleep(0.1)
  47. end
  48.  
  49. -- Place a block in front of the turtle
  50. turtle.place()
  51. print("Block placed.")
  52.  
  53. -- Set the turtle's state back to "waiting"
  54. turtleState = "waiting"
  55. else
  56. print("No block to place.")
  57. -- Set the turtle's state back to "waiting"
  58. turtleState = "waiting"
  59. end
  60. elseif turtleState == "placing" then
  61. -- Wait for redstone signal on the back to break a block
  62. while not rs.getInput("back") do
  63. sleep(0.1)
  64. end
  65.  
  66. -- Check if there's a block in front of the turtle
  67. if turtle.detect() then
  68. -- Set the turtle's state to "breaking"
  69. turtleState = "breaking"
  70.  
  71. -- Attempt to dig the block
  72. turtle.dig()
  73.  
  74. -- Wait for a few seconds to give the turtle time to break the block
  75. sleep(3)
  76.  
  77. -- Check if the block was successfully broken
  78. if not turtle.detect() then
  79. print("Block broken!")
  80. else
  81. print("Failed to break the block.")
  82. end
  83.  
  84. -- Set the turtle's state back to "placing"
  85. turtleState = "placing"
  86. else
  87. print("No block to break.")
  88. -- Set the turtle's state back to "placing"
  89. turtleState = "placing"
  90. end
  91. end
  92. end
  93.  
Advertisement
Add Comment
Please, Sign In to add comment