Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- curPos = {
- x = 0,
- y = 0,
- z = 0,
- rot = 0
- }
- function Forward(num)
- local i = 0
- while i < num do
- if curPos.rot == 0 then
- if turtle.forward() then
- curPos.z = curPos.z + 1
- end
- elseif curPos.rot == 180 then
- if turtle.forward() then
- curPos.z = curPos.z - 1
- end
- elseif curPos.rot == -90 then
- if turtle.forward() then
- curPos.x = curPos.x - 1
- end
- elseif curPos.rot == 90 then
- if turtle.forward() then
- curPos.x = curPos.x + 1
- end
- end
- i = i + 1
- end
- end
- function Up(num)
- local i = 0
- while i < num do
- if turtle.up() then
- curPos.y = curPos.y + 1
- end
- i = i + 1
- end
- end
- function Down(num)
- local i = 0
- while i < num do
- if turtle.down() then
- curPos.y = curPos.y - 1
- end
- i = i + 1
- end
- end
- function RotateLeft(num)
- local i = 0
- while i < num do
- if turtle.turnLeft() then
- curPos.rot = curPos.rot - 90
- end
- if curPos.rot == -180 then
- curPos.rot = 180
- end
- i = i + 1
- end
- end
- function RotateRight(num)
- local i = 0
- while i < num do
- if turtle.turnRight() then
- curPos.rot = curPos.rot + 90
- end
- if curPos.rot > 180 then
- curPos.rot = -90
- end
- i = i + 1
- end
- end
- function ReturnHome()
- while curPos.x ~= 0 do
- if curPos.x > 0 then
- if curPos.rot ~= -90 then
- RotateLeft(1)
- else
- Forward(curPos.x)
- end
- elseif curPos.x < 0 then
- if curPos.rot ~= 90 then
- RotateRight(1)
- else
- Forward(curPos.x)
- end
- end
- end
- while curPos.y ~= 0 do
- if curPos.y > 0 then
- Down(curPos.y)
- elseif curPos.y < 0 then
- Up(curPos.y)
- end
- end
- while curPos.z ~= 0 do
- if curPos.z > 0 then
- if curPos.rot ~= 180 then
- RotateLeft(1)
- else
- Forward(curPos.z)
- end
- elseif curPos.z < 0 then
- if curPos.rot ~= 0 then
- RotateRight(1)
- else
- Forward(curPos.z)
- end
- end
- end
- RotateLeft(2)
- end
- function Dig(UpDownOnly)
- turtle.digUp()
- turtle.digDown()
- if not UpDownOnly then
- turtle.dig()
- end
- end
- function FuelCheck(x, y, z)
- if turtle.getFuelLevel() < x*y*z then
- print("Turtle needs atleast " .. x*y*z .. " more fuel")
- while turtle.getFuelLevel() < x*y*z do
- turtle.refuel()
- sleep(1)
- end
- end
- end
- function Clear(x, y, z)
- FuelCheck(x, y, z)
- Up(1)
- Dig()
- Digging = true
- while Digging do
- Forward(1)
- Dig(false)
- if curPos.x == x and curPos.z == z and CurPos.y == y then
- ReturnHome()
- elseif curPos.x == x and curPos.z == z then
- ReturnHome()
- RotateLeft(2)
- Up(1)
- Dig(true)
- Up(1)
- Dig(false)
- elseif curPos.x == x then
- RotateLeft(1)
- Dig(false)
- Forward(1)
- RotateLeft(1)
- Dig(false)
- elseif curPos.x == 0 then
- RotateRight(1)
- Dig(false)
- Forward(1)
- RotateRight(1)
- Dig(false)
- end
- end
- end
- Clear(60, 20, 60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement