Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SLOT_COUNT = 16
- colLength = 0
- rowLength = 0
- function refuelTurtle()
- for slot = 1, SLOT_COUNT, 1 do
- turtle.select(slot)
- local item = turtle.getItemDetail(slot)
- if (turtle.refuel(2)) then
- print("Turtle refueled")
- return true
- end
- end
- end
- function checkFuel()
- local fuel = turtle.getFuelLevel()
- if(fuel < 20) then
- refuelTurtle()
- else
- print("No fuel needed")
- end
- end
- function detectStartPoint()
- local state, itemName = turtle.inspectDown()
- if(itemName.name == "minecraft:log") then
- checkFuel()
- defx,defy,defz = gps.locate()
- print("Default GPS coords: ",defx,defy,defz)
- turtle.up()
- turtle.forward()
- end
- end
- function detectFieldColSize()
- while turtle.detect() == false do
- turtle.forward()
- end
- local state, itemName = turtle.inspect()
- if(itemName.name == "minecraft:fence") then
- local x,y,z = gps.locate()
- print("GPS coords: ",x,y,z)
- leng = math.abs(defx-x)
- if(leng > 0) then
- colLength = leng
- else
- colLength = math.abs(defz-z)
- end
- print("Column length:",colLength)
- end
- turtle.turnRight()
- detectFieldRowSize()
- end
- function detectFieldRowSize()
- while turtle.detect() == false do
- turtle.forward()
- end
- local state, itemName = turtle.inspect()
- if(itemName.name == "minecraft:fence") then
- local x,y,z = gps.locate()
- print("GPS coords: ",x,y,z)
- leng = math.abs(defz-z)
- if(leng > 0) then
- rowLength = leng
- else
- rowLength = math.abs(defz-z)
- end
- print("Row length:",rowLength)
- end
- turtle.turnRight()
- returnHome()
- end
- function returnHome()
- col = colLength
- row = rowLength
- while col > 0 do
- turtle.forward()
- col = col-1
- end
- turtle.turnRight()
- while row > 0 do
- turtle.forward()
- row = row-1
- end
- local x,y,z = gps.locate()
- print("Position:", x," ,", y, " ,", z)
- print("Return Home completed")
- turtle.turnRight()
- turtle.down()
- end
- function moveFarmer()
- turtle.forward()
- end
- function turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- end
- function turnRight()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- function start()
- checkFuel()
- detectStartPoint()
- detectFieldColSize()
- print("Field Detected, starting harvest")
- turtle.up()
- rowLength = rowLength+1
- for col = 1, rowLength, 1 do
- for row = 1, colLength, 1 do
- moveFarmer()
- print(string.format("position: column %d row %d ",col,row))
- end
- --start of each col
- checkFuel()
- if(math.fmod(col,2) == 0) then
- turnLeft()
- else
- turnRight()
- end
- end
- print("Column length:",colLength)
- print("Row length:",rowLength)
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement