Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- if #args < 1 then
- print("Required parameter: <size>")
- return
- elseif tonumber(args[1]) == nil then
- print("Size must be a number")
- return
- end
- local UP = 1
- local LEFT = 2
- local DOWN = 3
- local RIGHT = 4
- local DIRECTIONS = {
- [UP] = {x = 1, y = 0}, -- up
- [LEFT] = {x = 0, y = 1}, -- left
- [DOWN] = {x = -1, y = 0}, -- down
- [RIGHT] = {x = 0, y = -1}, -- right
- }
- local currentDirection = UP
- local currentPosition = {x = 0, y = 0}
- local TUNNEL_SIZE = tonumber(args[1])
- local lastMiningDirection = LEFT
- local function mineAndMoveForward()
- turtle.dig()
- success = turtle.forward()
- if success then
- if currentLevel ~= 0 then
- turtle.digUp()
- end
- turtle.digDown()
- currentPosition.x = currentPosition.x + DIRECTIONS[currentDirection].x
- currentPosition.y = currentPosition.y + DIRECTIONS[currentDirection].y
- return true
- end
- return false
- end
- local function turnLeft()
- turtle.turnLeft()
- currentDirection = currentDirection % 4 + 1
- end
- local function turnRight()
- turtle.turnRight()
- currentDirection = (currentDirection - 2) % 4 + 1
- end
- while turtle.getFuelLevel() > 0 do
- if currentDirection == UP then
- mineAndMoveForward()
- if lastMiningDirection == LEFT then
- turnRight()
- else
- turnLeft()
- end
- for i = 1, TUNNEL_SIZE do
- mineAndMoveForward()
- end
- if lastMiningDirection == LEFT then
- turnLeft()
- lastMiningDirection = RIGHT
- else
- turnRight()
- lastMiningDirection = LEFT
- end
- local coalCount = turtle.getItemCount()
- if coalCount > 1 then
- turtle.refuel(coalCount - 1)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement