Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local xPos, zPos = 0,0
- local xDir, zDir = 0,1
- local depth = 0
- local function turnLeft()
- turtle.turnLeft()
- xDir, zDir = -zDir, xDir
- end
- local function turnRight()
- turtle.turnRight()
- xDir, zDir = zDir, -xDir
- end
- local function tryForwards()
- -- TODO: check fuel levels
- while not turtle.forward() do
- if turtle.detect() then
- --blocked and we're a pacifist so wait
- sleep(0.5)
- end
- end
- xPos = xPos + xDir
- zPos = zPos + zDir
- return true
- end
- function goTo( x, y, z, xd, zd )
- while depth > y do
- if turtle.up() then
- depth = depth - 1
- elseif turtle.digUp() or turtle.attackUp() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- if xPos > x then
- while xDir ~= -1 do
- turnLeft()
- end
- while xPos > x do
- if turtle.forward() then
- xPos = xPos - 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- elseif xPos < x then
- while xDir ~= 1 do
- turnLeft()
- end
- while xPos < x do
- if turtle.forward() then
- xPos = xPos + 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- end
- if zPos > z then
- while zDir ~= -1 do
- turnLeft()
- end
- while zPos > z do
- if turtle.forward() then
- zPos = zPos - 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- elseif zPos < z then
- while zDir ~= 1 do
- turnLeft()
- end
- while zPos < z do
- if turtle.forward() then
- zPos = zPos + 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- end
- while depth < y do
- if turtle.down() then
- depth = depth + 1
- elseif turtle.digDown() or turtle.attackDown() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- while zDir ~= zd or xDir ~= xd do
- turnLeft()
- end
- end
- function findSeeds()
- for n=1,16 do
- local slotData = turtle.getItemDetail(n)
- if slotData then
- if (slotData.name == "Natura:barley.seed") then
- turtle.select(n)
- end
- end
- end
- end
- function inspectCrop()
- if turtle.detectDown() then
- local success, data = turtle.inspectDown()
- if success then
- if ((data.name == "Natura:N Crops") and (data.metadata == 8)) then
- turtle.digDown()
- findSeeds()
- turtle.placeDown()
- end
- end
- end
- end
- function advanceRow()
- if xPos % 2 == 0 then
- turnRight()
- tryForwards()
- turnRight()
- else
- turnLeft()
- tryForwards()
- turnLeft()
- end
- end
- function walkRow()
- for n=1,6 do
- tryForwards()
- inspectCrop()
- end
- end
- function turnAround()
- turnLeft()
- turnLeft()
- end
- if turtle.up() then
- depth = depth - 1
- end
- -- currently this only works on my test farm ;-)
- for i=1,8 do
- walkRow()
- advanceRow()
- print("My position is: X"..xPos.." Z:"..zPos)
- end
- goTo(0,0,0,0,-1)
- turnAround()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement