Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get LbxkYAYh tree.lua
- -- [SETTINGS]
- -- tree farm perimeter
- pointA = { -- CURRENTLY STORED: SMP with da Boys
- ['x'] = -1002,
- ['z'] = 702,
- ['y'] = 91
- }
- pointB = {
- ['x'] = -1002,
- ['z'] = 706,
- ['y'] = 91
- }
- -- specifics
- treeRows = 1
- -- turtle
- location = {
- ['x'] = -998,
- ['z'] = 704,
- ['y'] = 91
- }
- direction = {
- ['x'] = 0,
- ['z'] = -1;
- }
- -- NORTH -z, SOUTH z
- -- WEST -x, EAST x
- -- check fuel
- fuelLevel = turtle.getFuelLevel()
- if(fuelLevel < 5000)
- then
- write("fuel level too low \n")
- write("by " .. (5000-fuelLevel) .. " fuel \n")
- else
- write("sufficient fuel \n")
- end
- -- implement break when fuel too low
- -- [ LOCATE COORDINATES ]
- --> Y-Axis
- write("checking Y-Axis ... \n")
- if(location['y'] ~= pointA['y'])
- then
- while(location['y'] ~= pointA['y'])
- do
- if(location['y'] > pointA['y'])
- then -- go down
- if(turtle.down() == false) then
- write("removing obstacle... \n")
- turtle.digDown()
- turtle.down()
- end
- write("moved down... \n")
- location['y'] = location['y'] - 1
- else -- go up
- if(turtle.up() == false) then
- write("removing obstacle... \n")
- turtle.digUp()
- turtle.up()
- end
- write("moved up... \n")
- location['y'] = location['y'] + 1
- end
- end
- write("reached target Y-Axis ! \n")
- else
- write("already on target Y-Axis \n")
- end
- --> Z-Axis
- if(direction["z"] == 0) then -- TURN TO NORTH
- if(direction["x"] == 1)
- then -- turn south
- turtle.turnLeft()
- else -- turn north? XD
- turtle.turnRight()
- end
- direction["z"] = -1
- direction["x"] = 0
- write("turned to Z-Axis \n")
- end
- write("checking Z-Axis ... \n")
- if(location['z'] ~= pointA['z']) -- is on target?
- then
- while(location['z'] ~= pointA['z']) -- while isn't on target
- do
- if(location['z'] > pointA['z']) -- if target is north
- then -- go forward
- if(direction['z'] == -1) -- make sure to face north
- then
- if(turtle.forward() == false) then
- write("removing obstacle... \n")
- turtle.dig()
- turtle.forward()
- end
- write("moved forward... \n")
- location['z'] = location['z'] - 1
- else -- turn 18
- turtle.turnRight()
- turtle.turnRight()
- direction["z"] = -1
- write("adjusted direction... \n")
- end
- else -- go back
- if(direction['z'] == 1) -- make sure to face south
- then
- if(turtle.forward() == false) then
- write("removing obstacle... \n")
- turtle.dig()
- turtle.forward()
- end
- write("moved forward... \n")
- location['z'] = location['z'] + 1
- else
- -- turn 180
- turtle.turnRight()
- turtle.turnRight()
- direction["z"] = 1
- write("adjusted direction... \n")
- end
- end
- end
- write("reached target Z-Axis ! \n")
- else
- write("already on target Z-Axis \n")
- end
- --> X-Axis
- if(direction["x"] == 0) --
- then
- if(direction["z"] == 1)
- then -- turn
- turtle.turnRight()
- else -- turn XD
- turtle.turnLeft()
- end
- direction["x"] = -1
- direction["z"] = 0
- write("turned to X-Axis \n")
- end
- write("checking X-Axis ... \n")
- if(location['x'] ~= pointA['x']) -- is on target?
- then
- while(location['x'] ~= pointA['x']) -- while isn't on target
- do
- if(location['x'] > pointA['x']) -- if target is north
- then -- go forward
- if(direction['x'] == -1) -- make sure to face north
- then
- if(turtle.forward() == false) then
- write("removing obstacle... \n")
- turtle.dig()
- turtle.forward()
- end
- write("moved forward... \n")
- location['x'] = location['x'] - 1
- else -- turn 18
- turtle.turnRight()
- turtle.turnRight()
- direction["x"] = -1
- write("adjusted direction... \n")
- end
- else -- go back
- if(direction['x'] == 1) -- make sure to face south
- then
- if(turtle.forward() == false) then
- write("removing obstacle... \n")
- turtle.dig()
- turtle.forward()
- end
- write("moved forward... \n")
- location['x'] = location['x'] + 1
- else
- -- turn 180
- turtle.turnRight()
- turtle.turnRight()
- direction["x"] = 1
- write("adjusted direction... \n")
- end
- end
- end
- write("reached target X-Axis ! \n")
- else
- write("already on target X-Axis \n")
- end
- write("ALLAHU AKBAR ! \n")
- -- WIP
- -- [locate tree row]
- -- locate long side
- -- NORTH OR SOUTH
- if(pointA["z"] > pointB["z"])
- then
- lenZ = pointA["z"] - pointB["z"]
- tarDir["z"] = -1
- else
- lenZ = pointB["z"] - pointA["z"]
- tarDir["z"] = 1
- end
- -- WEST OR EAST
- if(pointA["x"] > pointB["x"])
- then
- lenX = pointA["x"] - pointB["x"]
- tarDir["x"] = -1
- else
- lenX = pointB["x"] - pointA["x"]
- tarDir["X"] = 1
- end
- if(LenZ > lenX)
- then
- -- change dir
- else
- -- change dir
- end
- -- look at direction of point B
- -- move 2 forward
- -- turn left
- -- move 1 forward
- -- LOOP !!
- -- [chop tree]
- -- dig
- -- forward
- -- digUp & Up till no obstacle (count for every time went up)
- -- go COUNT down
- -- go 1 backwards
- -- replant
- -- turn right
- -- move 3 forward
- -- turn left
- -- check if obstacle ? continue loop : position next row and do again
- -- [Clear inventory]
- -- get to drop off station
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- -- [Refueling]
- -- * get to refuel station
- if turtle.getFuelLevel() < 5000 then
- end
- -- wait (for fuel efficiency, so the turtle doesn't waste fuel walking around ungrown trees
- -- VERSIONING AND OPTIMISATIONS TO CODE
Advertisement
Add Comment
Please, Sign In to add comment