Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("apis/tortoise.lua")
- local id,x,z=...
- id=tonumber(id)
- x=tonumber(x)
- z=tonumber(z)
- local position = {x=0,y=0,z=0}
- local turns = 0
- local fuelChestPos = {x=1,y=0,z=4}
- local oreChestPos = {x=1,y=0,z=1}
- local function moveX(dist)
- local relTurns = turns%4
- if relTurns == 0 then
- tortoise.forceForward(dist)
- elseif relTurns == 1 then
- tortoise.turnLeft()
- tortoise.forceForward(dist)
- tortoise.turnRight()
- elseif relTurns == 2 then
- tortoise.forceBack(dist)
- else
- tortoise.turnRight()
- tortoise.forceForward(dist)
- tortoise.turnLeft()
- end
- position.x = position.x + dist
- end
- local function moveY(dist)
- tortoise.forceDown(dist)
- position.y = position.y + dist
- end
- local function moveZ(dist)
- tortoise.turnRight()
- moveX(dist)
- tortoise.turnLeft()
- position.x = position.x - dist
- position.z = position.z + dist
- end
- if id==1 then
- moveX(1)
- elseif id==2 then
- moveX(1)
- moveZ(z*0.5)
- moveY(1)
- position.y=0
- elseif id==3 then
- moveX(x*0.5)
- moveY(2)
- position.y=0
- elseif id==4 then
- moveX(x*0.5)
- moveZ(z*0.5)
- moveY(3)
- position.y=0
- else
- print("no ID specified. quitting")
- return
- end
- local function turnLeft(times)
- if times == 0 then return end
- tortoise.turnLeft(times)
- turns = turns - times
- end
- local function turnRight(times)
- if times == 0 then return end
- tortoise.turnRight(times)
- turns = turns + times
- end
- local function distanceFromHome()
- return position.x + position.y + position.z
- end
- local function checkFuel()
- if turtle.getFuelLevel() + (80 * turtle.getItemCount()) < distanceFromHome()+10 then
- local oldPos = position
- moveY(-position.y)
- moveX(fuelChestPos.x-position.x)
- moveZ(fuelChestPos.z-position.z)
- turnLeft(turns)
- turnLeft(2)
- turtle.suck(64)
- moveZ(-2)
- for i=2,16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- turnRight(2)
- moveY(oldPos.y)
- moveX(oldPos.x-position.x)
- moveZ(oldPos.z-position.z)
- end
- end
- local function checkInv()
- for i=2,16 do
- if turtle.getItemCount(i) == 0 then
- return
- end
- end
- local oldPos = position
- moveY(-position.y)
- moveX(oreChestPos.x - position.x)
- moveZ(oreChestPos.z - position.z)
- turnLeft(turns)
- turnLeft(2)
- for i=2,16 do
- turtle.select(i)
- turtle.drop()
- end
- moveZ(3)
- turtle.select(1)
- turtle.suck(64-turtle.getItemCount())
- turnRight(2)
- moveX(oldPos.x - position.x)
- moveZ(oldPos.z - position.z)
- moveY(position.y)
- end
- while true do
- for i=1,x/2 do
- for _=1,z/2 do
- turnLeft(turns)
- checkFuel()
- checkInv()
- turtle.digDown()
- if turtle.detectDown() then
- moveY(-position.y - id)
- moveX(x)
- print("finished.")
- return
- end
- if i%2==1 then moveZ(1)
- else moveZ(-1) end
- end
- if position.y%2==1 then moveX(1)
- else moveX(-1) end
- end
- moveY(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment