Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Lazy Nub Chop Chop v0.01
- -- BY: LazyNub
- --
- -- These trees have issues with Lazy Nub chop chop
- -- Double size Fir trees will be recognized as single size
- -- Robust Twilight Oak isn't recognized correctly
- -- Redwood trees are not recognized correctly
- --
- -- Most all trees are at least detected as single trees and can be
- -- chopped down with multiple chops
- --
- --[[ Log Entries:
- Project Started May 17 '13
- First Release May 17 '13 LazyNub Chop Chop v0.01
- ]]--
- local treeSize = 1
- --[[ Robust Turtle
- Modified version of
- Robust Turtle API by SpeedR
- integrated
- ]]--
- --Digging with gravel/sand detection
- function dig()
- local tries = 0
- while turtle.detect() do
- turtle.dig()
- sleep(0.4)
- tries = tries + 1
- if tries>500 then
- print("Error: dug for too long.")
- return false
- end
- end
- return true
- end
- function digUp()
- local tries = 0
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0.4)
- tries = tries + 1
- if tries>500 then
- print("Error: dug up for too long.")
- return false
- end
- end
- return true
- end
- function digDown()
- local tries = 0
- while turtle.detectDown() do
- turtle.digDown()
- sleep(0.4)
- tries = tries + 1
- if tries>500 then
- print("Error: dug down for too long.")
- return false
- end
- end
- return true
- end
- --Traveling: Goes in the direction no matter what (almost)
- --Will not be stopped by blocks or mobs
- function forward(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.forward() ~= true do
- turtle.dig()
- turtle.attack()
- sleep(0.2)
- tries = tries + 1
- if tries>500 then
- print("Error: can't move forward.")
- return false
- end
- end
- end
- return true
- end
- function up(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.up() ~= true do
- turtle.digUp()
- turtle.attackUp()
- sleep(0.2)
- tries = tries + 1
- if tries>500 then
- print("Error: can't move up.")
- return false
- end
- end
- end
- return true
- end
- function down(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.down() ~= true do
- turtle.digDown()
- turtle.attackDown()
- sleep(0.2)
- tries = tries + 1
- if tries>500 then
- print("Error: can't move down.")
- return false
- end
- end
- end
- return true
- end
- function back(l)
- l=l or 1
- for i=1,l do
- if turtle.back() ~= true then
- turnAround()
- forward()
- turnAround()
- end
- end
- end
- --Place blocks
- --Does not place when there's already the right block.
- function place(block)
- turtle.select(block)
- if turtle.compare()==false then
- if turtle.getItemCount(block)==0 then
- outOfResource(block)
- end
- dig()
- turtle.place()
- end
- end
- function placeUp(block)
- turtle.select(block)
- if turtle.compareUp()==false then
- if turtle.getItemCount(block)==0 then
- outOfResource(block)
- end
- digUp()
- turtle.placeUp()
- end
- end
- function placeDown(block)
- turtle.select(block)
- if turtle.compareDown()==false then
- if turtle.getItemCount(block)==0 then
- outOfResource(block)
- end
- digDown()
- turtle.placeDown()
- end
- end
- local function outOfResource()
- print("Ran out of a resource. Block: ",block , ".")
- print("Refill, then say something to proceed.")
- read()
- end
- function placeRight(block)
- turtle.turnRight()
- place(block)
- turtle.turnLeft()
- end
- function placeLeft(block)
- turtle.turnLeft()
- place(block)
- turtle.turnRight()
- end
- function placeBack(block)
- turnAround()
- place(block)
- turnAround()
- end
- --place row e.g. placeRow(up, marble, forward, 15)
- function placeRow(placeDir, block, travelDir, l)
- l=l or 1
- for i=1,l do
- if placeDir == "forward" then
- place(block)
- elseif placeDir == "up" then
- placeUp(block)
- elseif placeDir == "down" then
- placeDown(block)
- elseif placeDir == "right" then
- placeRight(block)
- elseif placeDir == "left" then
- placeLeft(block)
- elseif placeDir == "back" then
- placeBack(block)
- else
- print('"', placeDir, '" is not a valid direction!')
- return false
- end
- if travelDir == "forward" then
- forward()
- elseif travelDir == "up" then
- up()
- elseif travelDir == "down" then
- down()
- elseif travelDir == "right" then
- strafeRight()
- elseif travelDir == "left" then
- strafeLeft()
- elseif travelDir == "back" then
- back()
- else
- print('"', travelDir, '" is not a valid direction!')
- return false
- end
- end
- return true
- end
- --Turning
- function turnAround()
- turtle.turnRight()
- turtle.turnRight()
- end
- function right()
- turtle.turnRight()
- end
- function left()
- turtle.turnLeft()
- end
- function goRight(l)
- l=l or 1
- turtle.turnRight()
- forward(l)
- end
- function goLeft(l)
- l=l or 1
- turtle.turnLeft()
- forward(l)
- end
- function strafeRight(l)
- l=l or 1
- goRight(l)
- turtle.turnLeft()
- end
- function strafeLeft(l)
- l=l or 1
- goLeft(l)
- turtle.turnRight()
- end
- --[[ End of Robust Turtle
- ]]--
- function plant() -- Plants a sapling to save the Planet
- if turtle.getItemCount(16) > 0 then
- print("Planting Sapling")
- place(16)
- end
- end
- function cutDouble() -- Cuts down a double wide tree
- local ifleft = false
- print("Cutting Double")
- turtle.select(1)
- while turtle.compareUp() do -- going up trunk
- digUp()
- up()
- end
- digUp()
- right()
- turtle.select(1)
- if turtle.compare() then
- print("Cutting from Left")
- isleft = false
- dig()
- forward()
- right()
- dig()
- forward()
- right()
- else
- print("Cutting from Right")
- isleft = true
- turnAround()
- dig()
- forward()
- left()
- dig()
- forward()
- left()
- end
- getfuel()
- print("Going Down")
- turtle.select(1)
- while turtle.compareDown() do -- going down beating leaves and last quarter of double tree
- for i = 1,4 do
- dig()
- left()
- end
- down()
- end
- for i = 1,4 do
- turtle.select(1)
- if turtle.compare() then
- dig()
- else
- turtle.select(16)
- turtle.suck()
- end
- right()
- end
- turtle.select(1)
- i = 0
- while turtle.compareDown() do -- see if stump continues down
- print("Getting Stump now")
- digDown()
- down()
- i = i+1
- end
- if i > 0 then
- for j = 1,i do
- up()
- end
- end
- forward()
- if isleft == true then
- left()
- else
- right()
- end
- end
- function cutTriple() -- Cuts down a triple wide tree
- local islayer = 1
- print("Cutting Triple")
- turtle.select(1)
- left()
- if turtle.compare() then -- Checking for location on trunk start
- turnAround()
- if turtle.compare() then
- islayer = 2
- print("Cutting from middle")
- back()
- else
- islayer = 3
- print("Cutting from Right side")
- turnAround()
- end
- else
- islayer = 1
- print("Cutting from Left side")
- turnAround()
- end
- while turtle.compareUp() or turtle.compare() do
- for i = 1,4 do
- dig()
- right()
- end
- digUp()
- up()
- end
- getfuel()
- forward()
- print("Going Down Middle")
- while not turtle.detectDown() do
- for i = 1,4 do
- dig()
- right()
- end
- down()
- end
- for i = 1,4 do
- dig()
- left()
- end
- forward()
- left()
- print("Going Back Up Last Time")
- while turtle.compareUp() or turtle.compare() do
- for i = 1,4 do
- dig()
- right()
- end
- digUp()
- up()
- end
- getfuel()
- print("Going Down Last Time")
- while not turtle.detectDown() do
- down()
- end
- if islayer == 3 then
- forward(2)
- left()
- forward(2)
- left()
- end
- if islayer == 2 then
- back(2)
- strafeLeft()
- end
- if islayer == 1 then
- back(2)
- strafeLeft(2)
- end
- print("Whew Done.")
- end
- function fellTree() -- Cuts down a tree
- treeSize = 1
- getfuel()
- turtle.select(1) -- Making sure initial chop goes into slot 1
- dig()
- forward()
- if turtle.detect() then -- Checks to see if there is another block ahead
- turtle.select(1) -- Makes Sure chopped log is selected for compare
- if turtle.compare() then
- print("Found double Maybe") -- If there is another matching block is double wide
- treeSize = 2
- turtle.select(1) -- Chop 2nd log and move forward to check for triple
- dig()
- forward()
- if turtle.detect() then -- Checks to see if there is another block ahead
- turtle.select(1) -- Makes sure chopped log is selected for compare
- if turtle.compare() then
- print("Found triple Maybe") -- If there is another matching block is triple wide
- treeSize = 3
- turtle.select(1)
- dig()
- end
- end
- end
- end -- Now we know if it is a single wide,
- -- double wide or triple wide tree.
- -- Divert to routine for type of tree we
- -- found and chop it down.
- if treeSize == 3 then
- cutTriple()
- end
- if treeSize == 2 then
- cutDouble()
- end
- -- must be single so get to cutting
- getfuel()
- turtle.select(1) -- Place logs in slot 1
- if treeSize == 1 then
- print ("Chop Chop Going up Single Tree")
- while turtle.detectUp() do -- going up trunk
- digUp()
- up()
- end
- turtle.select(16) -- Place saplings in slot 16
- print("At the top, Going Down")
- while not turtle.detectDown() do -- going down beating leaves
- for i = 1,4 do -- Spins and chops leaves on way down
- dig()
- left()
- turtle.suck() -- Tries to pick-up any saplings
- end
- down()
- end
- for i = 1,4 do -- One spin to catch saplings on ground
- right() -- Noted unique opposite spin technique
- turtle.suck()
- end
- turtle.select(1) -- Change back to log storage slot
- i = 0
- while turtle.compareDown() do -- Check if stump continues down
- print("Getting Stump")
- digDown()
- down()
- i = i+1
- end
- if i then
- turtle.select(16) -- Change to saplings slot
- print("Picking Up Saplings")
- for j = 1,i do
- for k = 1,4 do
- turtle.suck() -- pick-up saplings
- left()
- end
- up()
- end
- end
- end
- back()
- plant() -- Plant sapling when done to save planet
- end
- function getfuel() -- Checks if enough fuel and refuels
- print("Checking fuel levels")
- if turtle.getFuelLevel() < 160 then
- turtle.select(13)
- turtle.refuel(2)
- end
- if turtle.getFuelLevel() < 160 and turtle.getItemCount(13) == 0 then
- print("Emergency Fuel Needed!")
- print("Fuel Level: "..turtle.getFuelLevel())
- print("Using logs for fuel")
- i = 2
- while turtle.getFuelLevel() < 160 and i < 14 do
- turtle.select(i)
- turtle.refuel()
- i=i+1
- end
- end
- end
- --[[
- Main Program
- ]]--
- local running = true
- print("Lazy Nub Chop Chop v0.01")
- print("===============================")
- print("Slot 1-12 for harvested logs")
- print("Slot 13 for fueling")
- print("Slot 16 for harvested saplings")
- print("===============================")
- print(" Chop Chop Is On The Job")
- if turtle.getFuelLevel() < 160 then
- turtle.select(13)
- turtle.refuel()
- end
- if turtle.getFuelLevel() < 160 then
- print("Need more fuel in slot 13 please.")
- print("Place fuel in slot and restart me.")
- print("I want atleast 160 I have only: "..turtle.getFuelLevel())
- running = false
- end
- if running then
- fellTree()
- end
- --[[ THE END
- ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement