Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- -- Init variables
- local size = args[1] or 5
- local maxSteps = size * size
- local step = 1
- local dir = true -- True for away, false for towards starting position
- local pos = {
- x = 1,
- y = 1,
- z = 0,
- f = 0
- }
- -- States:
- -- Mining
- -- PutToChest
- local state = "Mining"
- --Functions
- local function tryToRefuel( fuelNeeded )
- for i = 1, 16 do
- turtle.select(i)
- while turtle.refuel(0) and turtle.getFuelLevel() < fuelNeeded * 1.5 do
- turtle.refuel(1)
- end
- end
- turtle.select(1)
- if turtle.getFuelLevel() < fuelNeeded * 1.5 then
- return false
- else
- return true
- end
- end
- local function checkFuel()
- local fuelNeeded = math.abs(pos.z) + size * 2
- if turtle.getFuelLevel() < fuelNeeded then
- tryToRefuel(fuelNeeded) -- If false return to chest
- end
- end
- local function moveForward()
- checkFuel()
- while turtle.detect() do turtle.dig() end
- turtle.forward()
- if pos.f == 0 then pos.x = pos.x + 1 end
- if pos.f == 2 then pos.x = pos.x - 1 end
- if pos.f == 1 then pos.y = pos.y + 1 end
- if pos.f == 3 then pos.y = pos.y - 1 end
- step = step + 1
- end
- local function moveUp()
- while turtle.detectUp() do turtle.digUp() end
- turtle.up()
- pos.z = pos.z + 1
- end
- local function moveDown()
- while turtle.detectDown() do turtle.digDown() end
- turtle.down()
- pos.z = pos.z - 1
- end
- local function turnLeft()
- turtle.turnLeft()
- pos.f = (pos.f - 1) % 4
- end
- local function turnRight()
- turtle.turnRight()
- pos.f = (pos.f + 1) % 4
- end
- local function mine()
- if step == maxSteps then
- turnRight()
- turnRight()
- moveDown()
- step = 1
- dir = not dir
- end
- if dir then
- if pos.x == size and pos.f == 0 then
- turnRight()
- moveForward()
- turnRight()
- elseif pos.x == 1 and pos.f == 2 then
- turnLeft()
- moveForward()
- turnLeft()
- else
- moveForward()
- end
- else
- if pos.x == size and pos.f == 0 then
- turnLeft()
- moveForward()
- turnLeft()
- elseif pos.x == 1 and pos.f == 2 then
- turnRight()
- moveForward()
- turnRight()
- else
- moveForward()
- end
- end
- end
- -- Main Code
- moveDown()
- tryToRefuel(10)
- print("Quarry size: "..size)
- -- Main Loop
- while true do
- if state == "Mining" then
- mine()
- print(dir)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement