Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local currentDirection = nil
- function getCurrentDirection()
- local blockStatus, blockData = turtle.inspect()
- if (blockStatus == false)
- then
- 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
- else
- turnLeft()
- getCurrentDirection()
- 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, aboveTree)
- dpX = dp.x
- if (aboveTree ~= nil)
- then
- dpY = dp.y + 1
- else
- dpY = dp.y
- end
- 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 = -50,
- z = -399
- }
- local startingPoints = {
- {
- x = -1438,
- y = -50,
- z = -399
- },
- {
- x = -1438,
- y = -56,
- z = -398
- },
- {
- x = -1438,
- y = -56,
- z = -388
- },
- {
- x = -1440,
- y = -56,
- z = -388
- },
- {
- x = -1440,
- y = -56,
- z = -382
- },
- {
- x = -1440,
- y = -56,
- z = -377
- },
- {
- x = -1444,
- y = -56,
- z = -376
- },
- {
- x = -1445,
- y = -56,
- z = -380
- },
- {
- x = -1445,
- y = -56,
- z = -385
- },
- {
- x = -1449,
- y = -56,
- z = -386
- },
- {
- x = -1450,
- y = -56,
- z = -382
- },
- {
- x = -1450,
- y = -56,
- z = -377
- },
- {
- x = -1455,
- y = -56,
- z = -377
- },
- {
- x = -1455,
- y = -56,
- z = -380
- },
- {
- x = -1455,
- y = -56,
- z = -385
- },
- {
- x = -1460,
- y = -56,
- z = -382
- },
- {
- x = -1460,
- y = -56,
- z = -377
- },
- {
- x = -1464,
- y = -56,
- z = -376
- },
- {
- x = -1465,
- y = -56,
- z = -380
- },
- {
- x = -1465,
- y = -56,
- z = -385
- }
- }
- local trees = {
- {
- x = -1440,
- y = -57,
- z = -387
- },
- {
- x = -1440,
- y = -57,
- z = -382
- },
- {
- x = -1440,
- y = -57,
- z = -377
- },
- {
- x = -1444,
- y = -57,
- z = -376
- },
- {
- x = -1445,
- y = -57,
- z = -380
- },
- {
- x = -1445,
- y = -57,
- z = -385
- },
- {
- x = -1449,
- y = -57,
- z = -386
- },
- {
- x = -1450,
- y = -57,
- z = -382
- },
- {
- x = -1450,
- y = -57,
- z = -377
- },
- {
- x = -1455,
- y = -57,
- z = -377
- },
- {
- x = -1455,
- y = -57,
- z = -380
- },
- {
- x = -1455,
- y = -57,
- z = -385
- },
- {
- x = -1459,
- y = -57,
- z = -386
- },
- {
- x = -1460,
- y = -57,
- z = -382
- },
- {
- x = -1460,
- y = -57,
- z = -377
- },
- {
- x = -1464,
- y = -57,
- z = -376
- },
- {
- x = -1465,
- y = -57,
- z = -380
- },
- {
- x = -1465,
- y = -57,
- z = -385
- }
- }
- getCurrentDirection()
- gotoPoint(startingPoints[1])
- gotoPoint(startingPoints[2])
- gotoPoint(startingPoints[3])
- gotoPoint(startingPoints[4])
- gotoPoint(trees[1])
- local startingPointIndex = 4
- local treeIndex = 2
- while (treeIndex <= #trees)
- do
- shell.run("./lumber")
- getCurrentDirection()
- gotoPoint(startingPoints[startingPointIndex])
- gotoPoint(startingPoints[startingPointIndex + 1])
- gotoPoint(trees[treeIndex])
- startingPointIndex = startingPointIndex + 1
- treeIndex = treeIndex + 1
- end
- shell.run("./lumber")
- getCurrentDirection()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement