Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("robot")
- function init()
- term.write('Neue Position? [j/n]')
- i = read()
- if i == 'j' then
- robot.initGPS()
- elseif i == 'n' then
- robot.load()
- else
- term.clear()
- term.setCursorPos(0, 0)
- init()
- end
- end
- init()
- IGNORE_COUNT = 4
- CHUNKS = 1
- MIN_HEIGHT = 8
- MAX_HEIGHT = 38
- Y_STEPS = 3
- LAYERS = math.floor((MAX_HEIGHT - MIN_HEIGHT) / Y_STEPS)
- STEPS_PER_CHUNK = 16
- LENGTH = CHUNKS * STEPS_PER_CHUNK
- STEPS = LENGTH - 1
- X_START = robot.getX()
- Y_START = robot.getY()
- Z_START = robot.getZ()
- DIR_START = robot.getDirection()
- current_layer = 0
- moves_per_layer = LENGTH * LENGTH + LENGTH - 2
- moves_y = (Y_START - (MAX_HEIGHT - MIN_HEIGHT)) * LAYERS * 2
- moves = moves_per_layer * LAYERS + moves_y
- fuel_level_start = turtle.getFuelLevel()
- function checkDown()
- for i = 1, IGNORE_COUNT do
- if robot.compareDownTo(i) then
- return false
- end
- end
- return true
- end
- function checkUp()
- for i = 1, IGNORE_COUNT do
- if robot.compareUpTo(i) then
- return false
- end
- end
- return true
- end
- function compare()
- if checkUp() then turtle.digUp() end
- if checkDown() then turtle.digDown() end
- end
- function mine()
- for current_layer = 0, LAYERS - 1 do
- robot.moveToY(MIN_HEIGHT + current_layer * Y_STEPS)
- for i = 1, LENGTH / 2 do
- robot.moveZ(STEPS, compare)
- robot.moveX(1, compare)
- robot.moveZ(-STEPS, compare)
- if i < LENGTH / 2 then
- robot.moveX(1, compare)
- end
- for j = 1, IGNORE_COUNT do
- robot.drop(j, -1)
- for k = IGNORE_COUNT + 1, 16 do
- if robot.compareItems(j, k) then
- robot.drop(k)
- end
- end
- end
- end
- robot.moveToX(X_START)
- robot.moveToZ(Z_START)
- robot.turnTo(DIR_START)
- robot.moveToY(Y_START)
- term.clear()
- term.setCursorPos(1, 1)
- cur_layer = current_layer + 1
- moves_done = fuel_level_start - turtle.getFuelLevel()
- print("layer "..cur_layer.."/"..LAYERS)
- print(moves_done.."/"..moves.." moves")
- for j = IGNORE_COUNT+1, 16 do
- robot.drop(j)
- end
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Total moves: " .. moves)
- print("Fuel: " .. fuel_level_start)
- fuel = fuel_level_start - moves
- if fuel < 0 then
- fuel = math.abs(fuel)
- coal_needed = math.ceil(fuel/80)
- print("Not enough fuel - "..fuel.." fuel needed. ("..coal_needed.." coal)")
- else
- os.sleep(3)
- mine()
- end
Add Comment
Please, Sign In to add comment