Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x1 = -37;
- local y1 = 97;
- local z1 = 188;
- local x2 = -51;
- local y2 = 98;
- local z2 = 200;
- local xDir = math.abs(x2 - x1);
- local yDir = math.abs(y2 - y1);
- local zDir = math.abs(z2 - z1);
- local movedX = 0;
- local movedY = 0;
- local movedZ = 0;
- local left = true;
- function log(message)
- term.write(message);
- local cursorX, cursorY = term.getCursorPos();
- term.setCursorPos(cursorX, cursorY + 1);
- end
- function isComplete()
- return movedX >= xDir and movedY >= yDir and movedZ >= zDir;
- end
- function shouldMoveZ()
- return movedX >= xDir;
- end
- function shouldMoveY()
- return movedZ >= zDir;
- end
- function moveX()
- if turtle.detect() then
- turtle.dig();
- end
- log("Moving in X direction!");
- checkFuel();
- turtle.forward();
- movedX = movedX + 1;
- if not shouldMoveZ() then
- return;
- end
- moveZ();
- end
- function moveZ()
- if shouldMoveY() then
- moveY();
- return;
- end
- if left then
- turtle.turnLeft();
- else
- turtle.turnRight();
- end
- if turtle.detect() then
- turtle.dig();
- end
- log("Moving in Z direction!");
- checkFuel();
- turtle.forward();
- movedZ = movedZ + 1;
- if left then
- turtle.turnLeft();
- else
- turtle.turnRight();
- end
- left = not left;
- movedX = 1;
- end
- function moveY()
- if isComplete() then
- log("Completed!");
- return;
- end
- if turtle.detectUp() then
- log("Digging up!");
- turtle.digUp();
- end
- log("Moving up!");
- checkFuel();
- turtle.moveUp();
- turtle.turnLeft();
- turtle.turnLeft();
- left = not left;
- movedZ = 1;
- movedX = 1;
- movedY = movedY + 1;
- end
- function checkFuel()
- if turtle.getFuelLevel() > 0 then
- return;
- end
- log("Refuelling!");
- turtle.refuel(1);
- end
- while not isComplete() do
- moveX();
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement