Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local term = require("term")
- local robot = require("robot")
- term.write("Enter length (number): ")
- local length = term.read()
- term.write("Enter width (number): ")
- local width = term.read()
- term.write("Enter depth (number): ")
- local depth = term.read()
- local right = true
- function turn()
- if (right) then robot.turnRight() else robot.turnLeft() end
- end
- function trySwing()
- if (robot.durability() and robot.durability() == 0) then
- term.write("Tool durability is low! Mining stopped.\n")
- trySwing()
- else
- robot.swing()
- end
- end
- function trySwingDown()
- if (robot.durability() and robot.durability() == 0) then
- term.write("Tool durability is low! Mining stopped.\n")
- trySwingDown()
- else
- robot.swingDown()
- end
- end
- function tryForward()
- trySwing()
- if (not robot.forward()) then tryForward() end
- end
- function tryDown()
- trySwingDown()
- if (not robot.down()) then tryDown() end
- end
- function mineX(j)
- for i = length, 1, -1 do
- trySwingDown()
- if (i > 1) then
- tryForward()
- elseif (j > 1) then
- turn()
- trySwingDown()
- tryForward()
- turn()
- end
- end
- end
- function mineY(j)
- for i = width, 0, -1 do
- if (i > 0) then
- mineX(i)
- right = not right
- elseif (j > 1) then
- tryDown()
- robot.turnAround()
- right = not right
- end
- end
- end
- for i = depth, 1, -1 do
- mineY(i)
- end
- tryDown()
- term.write("Done mining! Going back to original position.\n")
- if (depth % 2 == 0) then
- robot.turnAround()
- elseif (width % 2 == 0) then
- robot.turnRight()
- for i = width, 2, -1 do
- tryForward()
- end
- robot.turnRight()
- else
- robot.turnAround()
- for i = length, 2, -1 do
- tryForward()
- end
- robot.turnRight()
- for i = width, 2, -1 do
- tryForward()
- end
- end
- term.write("Done.\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement