Advertisement
Paxon57

Untitled

Jun 17th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. args = {...}
  2.  
  3. -- Init variables
  4. local size = args[1] or 5
  5.  
  6. local maxSteps = size * size
  7. local step = 1
  8. local dir = true -- True for away, false for towards starting position
  9.  
  10. local pos = {
  11. x = 1,
  12. y = 1,
  13. z = 0,
  14. f = 0
  15. }
  16.  
  17. -- States:
  18. -- Mining
  19. -- PutToChest
  20. local state = "Mining"
  21.  
  22. --Functions
  23. local function tryToRefuel( fuelNeeded )
  24. for i = 1, 16 do
  25. turtle.select(i)
  26. while turtle.refuel(0) and turtle.getFuelLevel() < fuelNeeded * 1.5 do
  27. turtle.refuel(1)
  28. end
  29. end
  30. turtle.select(1)
  31.  
  32. if turtle.getFuelLevel() < fuelNeeded * 1.5 then
  33. return false
  34. else
  35. return true
  36. end
  37. end
  38.  
  39. local function checkFuel()
  40. local fuelNeeded = math.abs(pos.z) + size * 2
  41. if turtle.getFuelLevel() < fuelNeeded then
  42. tryToRefuel(fuelNeeded) -- If false return to chest
  43. end
  44. end
  45.  
  46. local function moveForward()
  47. checkFuel()
  48.  
  49. while turtle.detect() do turtle.dig() end
  50. turtle.forward()
  51.  
  52. if pos.f == 0 then pos.x = pos.x + 1 end
  53. if pos.f == 2 then pos.x = pos.x - 1 end
  54. if pos.f == 1 then pos.y = pos.y + 1 end
  55. if pos.f == 3 then pos.y = pos.y - 1 end
  56.  
  57. step = step + 1
  58. end
  59.  
  60. local function moveUp()
  61. while turtle.detectUp() do turtle.digUp() end
  62. turtle.up()
  63. pos.z = pos.z + 1
  64. end
  65.  
  66. local function moveDown()
  67. while turtle.detectDown() do turtle.digDown() end
  68. turtle.down()
  69. pos.z = pos.z - 1
  70. end
  71.  
  72. local function turnLeft()
  73. turtle.turnLeft()
  74. pos.f = (pos.f - 1) % 4
  75. end
  76.  
  77. local function turnRight()
  78. turtle.turnRight()
  79. pos.f = (pos.f + 1) % 4
  80. end
  81.  
  82. local function mine()
  83. if step == maxSteps then
  84. turnRight()
  85. turnRight()
  86. moveDown()
  87. step = 1
  88. dir = not dir
  89. end
  90.  
  91. if dir then
  92. if pos.x == size then
  93. turnRight()
  94. moveForward()
  95. turnRight()
  96. elseif pos.x == 1 then
  97. turnLeft()
  98. moveForward()
  99. turnLeft()
  100. else
  101. moveForward()
  102. end
  103. else
  104. if pos.x == size then
  105. turnLeft()
  106. moveForward()
  107. turnLeft()
  108. elseif pos.x == 1 then
  109. turnRight()
  110. moveForward()
  111. turnRight()
  112. else
  113. moveForward()
  114. end
  115. end
  116. end
  117. -- Main Code
  118.  
  119. moveDown()
  120. tryToRefuel(10)
  121. moveForward()
  122.  
  123. print("Quarry size: "..size)
  124.  
  125. -- Main Loop
  126. while true do
  127. if state == "Mining" then
  128. mine()
  129. print(dir)
  130. end
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement