Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local trees = 23
- local currentPos = 0
- local lastStatus = 0
- local status = 0 -- 0Clueless-1Starting-2Harvesting-3Returning-4onRail
- --todo: if no fuel in fuelslot, return immediatly.
- --todo: fix status updating to work with y-level
- --todo:
- -- refuel the turtle with slot 1, coal
- function Refuel()
- turtle.select(1)
- if not turtle.refuel(3) then
- status = 3
- end
- end
- --grabs fuel from coal chest
- function GrabFuel()
- turtle.turnLeft()
- turtle.select(1)
- turtle.suck()
- turtle.turnRight()
- end
- -- This function checks where the turtle is located on the rail, it's needed in case the program boots while the
- -- turtle is not at the start of the dropoff location
- function UpdateStatus()
- local s, under = turtle.inspectDown()
- local s2, front = turtle.inspect()
- lastStatus = status
- if s then
- if under.name == "minecraft:cobblestone" then
- status = 1
- end
- if under.name == "minecraft:torch" then
- status = 4
- end
- if under.name == "minecraft:dirt" then
- turtle.back()
- turtle.turnLeft()
- end
- end --todo: check if on right y level, should be if s is false
- if s2 then
- if front.name == "minecraft:chest" then
- turtle.turnLeft()
- turtle.turnLeft()
- status = 1
- end
- if front.name == "minecraft:log" or front.name == "minecraft:sapling" then
- turtle.turnLeft()
- UpdateStatus()
- end
- if front.name == "minecraft:gravel" then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- elseif status == 4 then
- turtle.forward()
- end
- print("Updated Status: " .. lastStatus .. " to " .. status)
- end
- function CheckTree(side)
- if side == 1 then
- turtle.turnLeft()
- turtle.suck()
- elseif side == 2 then
- turtle.turnRight()
- turtle.suck()
- end
- local s, d = turtle.inspect()
- if s and d.name == "minecraft:log" then
- return true
- elseif s and d.name == "minecraft:sapling" then
- return false
- else
- Replant()
- return false
- end
- end
- function ChopTree(side)
- if CheckTree(side) then
- turtle.dig()
- for i = 1, 5 do
- print("Chopping up: " .. i)
- if not turtle.up() then
- turtle.digUp()
- turtle.up()
- end
- turtle.dig()
- end
- while true do
- sleep(0.1)
- local s, d = turtle.inspectDown()
- if s and d.name ~= "minecraft:torch" then
- print("Going down but leaves in way?")
- turtle.digDown()
- turtle.down()
- end
- if s and d.name == "minecraft:torch" then
- print("I'm back down now")
- break
- end
- turtle.down()
- print("Moving down..")
- end
- Replant()
- end
- if side == 1 then
- turtle.turnRight()
- elseif side == 2 then
- turtle.turnLeft()
- end
- end
- function Replant()
- turtle.select(2)
- if turtle.getItemCount(2) > 0 then
- if turtle.getItemDetail(2).name == "minecraft:sapling" then
- turtle.place()
- end
- end
- end
- function Forward()
- turtle.forward()
- end
- function RefuelIfNeeded()
- if turtle.getFuelLevel() < 5 then
- print("Refueling..")
- Refuel()
- end
- end
- -- main loop
- -- reset -> refuel -> pickup fuel -> chop -> deposit
- while true do
- print("Breaking")
- -- first get the turtle back to start
- if status == 0 or status == 4 then
- print("Updating status..")
- UpdateStatus()
- end
- --grab fuel if at start and needed
- if turtle.getItemCount(1) < 16 and status == 1 then
- print("Grabbing Fuel..")
- GrabFuel()
- end
- --refuel if needed
- RefuelIfNeeded()
- -- Ready to begin harvesting, dump inventory and load saplings first
- if status == 1 then
- turtle.turnRight()
- print("Now dumping saplings")
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:sapling" then
- turtle.select(i)
- turtle.drop()
- end
- end
- turtle.turnRight()
- print("Now dumping logs")
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:log" then
- turtle.select(i)
- turtle.drop()
- end
- end
- print("Now dumping apples")
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:apple" then
- turtle.select(i)
- turtle.drop()
- end
- end
- status = 2
- turtle.turnLeft()
- turtle.select(2)
- turtle.suck()
- turtle.turnLeft()
- end
- --Move forward Once, check for trees on left then right, chop them if it finds any.
- if status == 2 then
- turtle.forward()
- RefuelIfNeeded()
- local s, d = turtle.inspect()
- if s and d.name == "minecraft:gravel" then
- status = 4
- end
- turtle.suckDown()
- ChopTree(1)
- ChopTree(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement