oxgon

Volcano/Taint block Remover

Apr 5th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. x=0
  2. y=0
  3. z=0 --[this is called globally because it's used and shared in all subs; it is used to return the turtle to ground level after completing its task.]--
  4. function forward()
  5. local count = 0
  6. repeat
  7. turtle.select(1)
  8. if turtle.compare() then
  9. turtle.dig()
  10. else
  11. if turtle.detect() then
  12. while turtle.detectUp() do
  13. turtle.back()
  14. end
  15. turtle.up()
  16. z = z + 1
  17. end
  18. end
  19. until turtle.forward()
  20. for count=0,3 do
  21. turtle.select(1)
  22. if turtle.compare() then
  23. turtle.dig()
  24. end
  25. turtle.turnLeft()
  26. end
  27. --[The turtle will check if the block in front of it is the target blocktype and mine it if it is. If it is a nontarget block, the turtle will reverse until it is able to climb a level]--
  28. end
  29. function up()
  30. turtle.select(1)
  31. local alt=0
  32. local count=0
  33. repeat
  34. if turtle.detectUp() then
  35. turtle.digUp()
  36. turtle.up()
  37. else
  38. turtle.up()
  39. alt=alt+1
  40. z=z+1
  41. end
  42. --[If the turtle has free air above it, it will ascend. It will increment 'alt' only when it ascends in free air. If it does not have free air, it will break the block above it (no matter the block) and move up. This behaviour is to help it escape caves, if required.]--
  43. for count=0,3 do
  44. turtle.select(1)
  45. if turtle.compare() then
  46. alt=0
  47. turtle.dig()
  48. end
  49. turtle.turnLeft()
  50. end --[the turtle will check each facing for target blocks. If it finds one, it will mine it and set 'alt' to zero.]--
  51. if alt==2 then
  52. turtle.down()
  53. turtle.down()
  54. z=z-2
  55. end
  56. until alt==2 --[if the turtle has gone up through free air 3 blocks and found no minable blocks or is sitting under a non-target block, it will end the sub.]--
  57. end
  58. function down()
  59. local cave = 0
  60. local count = 0
  61. repeat
  62. if turtle.detectDown() then
  63. turtle.select(1)
  64. if turtle.compareDown() then
  65. turtle.digDown()
  66. end
  67. else
  68. turtle.down()
  69. if turtle.compareDown() then
  70. turtle.digDown()
  71. end
  72. z = z - 1
  73. cave = cave + 1
  74. if cave == 3 then
  75. for count=0,4 do
  76. turtle.up()
  77. z=z+1
  78. end
  79. break --[If turtle thinks it's in a cave, it'll go back to the last known surface and quit the sub, returning to the For loop at forward()]--
  80. end
  81. end
  82. for count = 0,3 do
  83. turtle.select(1)
  84. if turtle.compare() then
  85. turtle.dig()
  86. cave = 0
  87. end
  88. turtle.turnLeft()
  89. end
  90. --[If the turtle finds target blocks on any of its 4 facings, it will mine them and reset the 'cave' counter to zero. Suspect it will check twice for every downward movement.]--
  91. until turtle.detectDown() --[Ends the sub (if it hasn't been ended by being in a cave) when the turtle is sitting on a block.]--
  92. end
  93. print "Width (chunk is 16)"
  94. x = tonumber(read())
  95. print "Depth (chunk is 16)"
  96. y = tonumber(read())
  97. print "And we're off. If your code doesn't work as intended, I'll be mining the clouds."
  98. os.pullEvent("key")
  99. leftright = "left" --[global because it's used in the harness.]--
  100. x=x/2
  101. y=y/2
  102. --[since the turtle moves forward twice for each iteration of the loop]--
  103. for count = 1,x do
  104. for notcount = 1, y do
  105. down()
  106. forward()
  107. up()
  108. forward()
  109. end
  110. if leftright=="right" then
  111. turtle.turnRight()
  112. forward()
  113. forward()
  114. forward()
  115. turtle.turnRight()
  116. leftright="left"
  117. else
  118. turtle.turnLeft()
  119. forward()
  120. forward()
  121. forward()
  122. turtle.turnLeft()
  123. leftright="right"
  124. end
  125.  
  126. end --[Will run the turtle down until it hits a non-target block or a cave, advance it one block, run it up until alt=3 or non target block, forward and repeat. 'If' statement should make the turtle alternate left-right turns at end of y-rows.]--
  127. repeat
  128. if z>0 then
  129. turtle.down()
  130. else
  131. turtle.up()
  132. end
  133. until z == 0
Add Comment
Please, Sign In to add comment