Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Based on excavate from the original computercraft distribution
- -- written by hildenae
- local rubberwood=1
- local tool=2
- -- electric hat has 200 uses.
- -- my size is 2 rows of 6 threes
- -- with a maxheight of 7 - this leves 4 uses
- local width = 6
- local rows = 2
- local MAX_USES=200
- local uses = 0
- local depth = 0
- local xPos,zPos = 0,0
- local xDir,zDir = 0,1
- local function turnLeft()
- turtle.turnLeft()
- xDir, zDir = -zDir, xDir
- end
- local function turnRight()
- turtle.turnRight()
- xDir, zDir = zDir, -xDir
- end
- function goTo( x, y, z, xd, zd )
- while depth > y do
- if turtle.up() then
- depth = depth - 1
- else
- return false
- end
- end
- if xPos > x then
- while xDir ~= -1 do
- turnLeft()
- end
- while xPos > x do
- if turtle.forward() then
- xPos = xPos - 1
- else
- return false
- end
- end
- elseif xPos < x then
- while xDir ~= 1 do
- turnLeft()
- end
- while xPos < x do
- if turtle.forward() then
- xPos = xPos + 1
- else
- return false
- end
- end
- end
- if zPos > z then
- while zDir ~= -1 do
- turnLeft()
- end
- while zPos > z do
- if turtle.forward() then
- zPos = zPos - 1
- else
- return false
- end
- end
- elseif zPos < z then
- while zDir ~= 1 do
- turnLeft()
- end
- while zPos < z do
- if turtle.forward() then
- zPos = zPos + 1
- else
- return false
- end
- end
- end
- while depth < y do
- if turtle.down() then
- depth = depth + 1
- else
- return false
- end
- end
- while zDir ~= zd or xDir ~= xd do
- turnLeft()
- end
- return true
- end
- local function forward()
- turtle.forward()
- xPos = xPos + xDir
- zPos = zPos + zDir
- return true
- end
- local function down()
- if turtle.down() then
- depth = depth + 1
- return true
- else
- return false
- end
- end
- local function harvest()
- turtle.select(rubberwood)
- if turtle.compare() then
- turtle.select(tool)
- turtle.place()
- uses = uses + 1
- else
- print("not wood")
- end
- end
- local function downTree()
- local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
- repeat
- harvest()
- until not down()
- goTo( x,y,z,xd,zd )
- end
- local function moveRight()
- turnRight()
- forward()
- turnLeft()
- end
- local function moveLeft()
- turnLeft()
- forward()
- turnRight()
- end
- local function turn180()
- turnRight()
- turnRight()
- end
- local function harvestRow()
- local w = width
- while(w > 0) do
- downTree()
- moveRight()
- w = w -1
- end
- forward()
- turnLeft()
- downTree() -- check side for resin
- moveRight()
- turnLeft()
- w = width
- while(w > 0) do
- moveRight()
- downTree()
- w = w -1
- end
- moveRight()
- forward()
- turnLeft()
- downTree() -- check side for resin
- end
- run = true
- while run do
- local r = rows
- forward()
- while (r > 0) do
- harvestRow()
- moveLeft()
- forward()
- turnLeft()
- r = r -1
- end
- moveLeft() -- move out to the side
- turn180()
- for i = 0, rows, 2 do
- print ("moving forward 2")
- forward()
- forward()
- end
- print("uses: ")
- print (uses)
- -- go to charge station
- goTo(0,0,0,0,1)
- run = false
- end
Advertisement
Add Comment
Please, Sign In to add comment