Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. local args = {...}
  2.  
  3. -- overall tunnel length
  4. local LENGTH = tonumber(args[1])
  5. if not LENGTH then print('usage: \'stripmine <length:int> [<throwaway:string>, ...]\'') return end
  6.  
  7. -- throwaway items
  8. local THROWAWAY = args
  9. for i = 2, #args do
  10. THROWAWAY['minecraft:' .. args[i]] = true
  11. end
  12.  
  13. local name = os.getComputerLabel()
  14. local CURRENT = 0
  15.  
  16. os.setComputerLabel(name .. ': Strip Mining')
  17.  
  18. local drop = function()
  19. for i = 1, 16 do
  20. turtle.select(i)
  21. if turtle.getItemDetail() and THROWAWAY[turtle.getItemDetail().name] then
  22. turtle.drop()
  23. end
  24. end
  25. end
  26.  
  27. local torch = function()
  28. for i = 1, 16 do
  29. turtle.select(i)
  30. if turtle.getItemDetail() and turtle.getItemDetail().name == 'minecraft:torch' then
  31. turtle.turnRight()
  32. turtle.placeUp()
  33. turtle.turnLeft()
  34. return true
  35. end
  36. end
  37. return false
  38. end
  39.  
  40. local refuel = function()
  41. local fuel = turtle.getFuelLevel()
  42. if fuel > 1 then
  43. return true
  44. end
  45.  
  46. for i = 1, 16 do
  47. turtle.select(i)
  48. if turtle.refuel(0) then
  49. turtle.refuel(math.ceil(turtle.getItemCount(i) / 2))
  50. return true
  51. end
  52. end
  53.  
  54. return false
  55. end
  56.  
  57. local return_origin = function()
  58. turtle.turnLeft()
  59. turtle.turnLeft()
  60.  
  61. for i = 1, CURRENT do
  62. turtle.forward()
  63. refuel()
  64. end
  65. end
  66.  
  67. local dig = function()
  68. if turtle.detect() then
  69. local success, data = turtle.inspect()
  70. if success then
  71. if data.name == 'minecraft:diamond_ore' then
  72. return true
  73. end
  74. end
  75. turtle.dig()
  76. end
  77.  
  78. return false
  79. end
  80.  
  81. local found
  82. while CURRENT < LENGTH do
  83. if not refuel() then
  84. print('program terminated: not enough fuel')
  85. os.setComputerLabel(name)
  86. return
  87. end
  88.  
  89. -- dig lower block
  90. found = dig()
  91. if found then break end
  92.  
  93. -- dig upper block
  94. turtle.up()
  95. found = dig()
  96. if found then turtle.down(); break end
  97.  
  98. -- reset turtle, check if we need to place a torch and move forward
  99. turtle.down()
  100. if CURRENT % 10 == 1 then
  101. if not torch() then
  102. print('program terminated: not enough torches')
  103. break
  104. end
  105. end
  106. turtle.forward()
  107. drop()
  108.  
  109. CURRENT = CURRENT + 1
  110. end
  111.  
  112. return_origin()
  113.  
  114. if found then
  115. os.setComputerLabel(name .. ': Found Diamond!')
  116. print('Found diamonds at xxxyyy!')
  117. else
  118. os.setComputerLabel(name .. ': Finished!')
  119. end
  120.  
  121. print('Press any key to return to CraftOS...')
  122. os.pullEventRaw('key')
  123. os.setComputerLabel(name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement