Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local currentDirection = nil
- function getCurrentDirection()
- local tp1X, tp1Y, tp1Z = gps.locate()
- turtle.forward()
- local tp2X, tp2Y, tp2Z = gps.locate()
- turtle.back()
- if (tp1X == tp2X)
- then
- if (tp1Z < tp2Z)
- then
- currentDirection = "South"
- else
- currentDirection = "North"
- end
- else
- if (tp1X < tp2X)
- then
- currentDirection = "East"
- else
- currentDirection = "West"
- end
- end
- end
- function turnLeft()
- if (currentDirection == "North")
- then
- currentDirection = "West"
- elseif (currentDirection == "West")
- then
- currentDirection = "South"
- elseif (currentDirection == "South")
- then
- currentDirection = "East"
- else
- currentDirection = "North"
- end
- turtle.turnLeft()
- end
- function turnRight()
- if (currentDirection == "North")
- then
- currentDirection = "East"
- elseif (currentDirection == "East")
- then
- currentDirection = "South"
- elseif (currentDirection == "South")
- then
- currentDirection = "West"
- else
- currentDirection = "North"
- end
- turtle.turnRight()
- end
- function gotoPoint(dp)
- dpX = dp.x
- dpY = dp.y
- dpZ = dp.z
- local clX, clY, clZ = gps.locate()
- while (clY ~= dpY)
- do
- if (clY > dpY)
- then
- turtle.down()
- else
- turtle.up()
- end
- clX, clY, clZ = gps.locate()
- end
- while (clX ~= dpX)
- do
- if (clX > dpX)
- then
- while (currentDirection ~= "West")
- do
- turnLeft()
- end
- else
- while (currentDirection ~= "East")
- do
- turnLeft()
- end
- end
- turtle.forward()
- clX, clY, clZ = gps.locate()
- end
- while (clZ ~= dpZ)
- do
- if (clZ > dpZ)
- then
- while (currentDirection ~= "North")
- do
- turnLeft()
- end
- else
- while (currentDirection ~= "South")
- do
- turnLeft()
- end
- end
- turtle.forward()
- clX, clY, clZ = gps.locate()
- end
- end
- local home = {
- x = -1437,
- y = -53,
- z = -399
- }
- local sp1 = {
- x = -1438,
- y = -53,
- z = -399
- }
- local wheatField1Start = {
- x = -1438,
- y = -56,
- z = -398
- }
- local wheatField2Start = {
- x = -1446,
- y = -56,
- z = -400
- }
- local potatoField1Start = {
- x = -1448,
- y = -56,
- z = -398
- }
- local potatoField2Start = {
- x = -1456,
- y = -56,
- z = -400
- }
- local carrotField1Start = {
- x = -1458,
- y = -56,
- z = -398
- }
- local carrotField2Start = {
- x = -1466,
- y = -56,
- z = -400
- }
- getCurrentDirection()
- turnRight()
- local wheatChest = peripheral.wrap("front")
- local wheatInfo = wheatChest.getItemDetail(wheatChest.size())
- if (wheatInfo == nil or wheatInfo.count ~= 64)
- then
- turtle.suck()
- turnLeft()
- gotoPoint(sp1)
- gotoPoint(wheatField1Start)
- shell.run("farm")
- gotoPoint(wheatField2Start)
- shell.run("farm")
- gotoPoint(wheatField1Start)
- gotoPoint(sp1)
- gotoPoint(home)
- turnLeft()
- local index = 0
- while (index < 16)
- do
- turtle.select(index + 1)
- turtle.drop()
- index = index + 1
- end
- turtle.select(1)
- turnLeft()
- else
- turnLeft()
- end
- turnLeft()
- local potatoChest = peripheral.wrap("front")
- local potatoInfo = potatoChest.getItemDetail(potatoChest.size())
- if (potatoInfo == nil or potatoInfo.count ~= 64)
- then
- turtle.suck()
- turnRight()
- gotoPoint(sp1)
- gotoPoint(wheatField1Start)
- gotoPoint(potatoField1Start)
- turnLeft()
- shell.run("farm")
- gotoPoint(potatoField2Start)
- shell.run("farm")
- gotoPoint(potatoField1Start)
- gotoPoint(wheatField1Start)
- gotoPoint(sp1)
- gotoPoint(home)
- turnRight()
- index = 0
- while (index < 16)
- do
- turtle.select(index + 1)
- turtle.drop()
- index = index + 1
- end
- turtle.select(1)
- turnRight()
- else
- turnRight()
- end
- turtle.up()
- turnRight()
- local carrotChest = peripheral.wrap("front")
- local carrotInfo = carrotChest.getItemDetail(carrotChest.size())
- if (carrotInfo == nil or carrotInfo.count ~= 64)
- then
- turtle.suck()
- turnLeft()
- turtle.down()
- gotoPoint(sp1)
- gotoPoint(wheatField1Start)
- gotoPoint(carrotField1Start)
- turnLeft()
- shell.run("farm")
- gotoPoint(carrotField2Start )
- shell.run("farm")
- gotoPoint(carrotField1Start)
- gotoPoint(wheatField1Start)
- gotoPoint(sp1)
- gotoPoint(home)
- turnLeft()
- turtle.up()
- index = 0
- while (index < 16)
- do
- turtle.select(index + 1)
- turtle.drop()
- index = index + 1
- end
- turtle.select(1)
- turnLeft()
- turtle.down()
- else
- turnLeft()
- turtle.down()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement