Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local direction = 0
- function refuelTurtle()
- if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 50 then
- local fuelCounter = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- local data = turtle.getItemDetail(i)
- if data.name == "minecraft:coal" then
- turtle.select(i)
- if turtle.refuel() then
- print("Refueled...")
- else
- print("For some reason I found fuel but I couldn't load it, master...")
- end
- end
- else
- fuelCounter = fuelCounter + 1
- end
- end
- if fuelCounter == 16 then
- print("I'm all out of fuel, master...")
- fuelCounter = 0
- end
- else
- print("Refueling unnecessary...")
- end
- end
- function checkInventory()
- local emptyInvSlots = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- emptyInvSlots = emptyInvSlots + 1
- end
- end
- if emptyInvSlots == 0 then
- print("My inventory is full, master...")
- emptyInvSlots = 0
- else
- print("Still ", emptyInvSlots, " empty inventory slots remaining...")
- emptyInvSlots = 0
- end
- end
- function move()
- refuelTurtle()
- checkInventory()
- if turtle.forward() then
- print("1..2..1..2..")
- else
- print("I'm stuck, master...")
- end
- findTree()
- end
- function moveAround()
- turtle.turnRight()
- if turtle.forward() then
- moveRight()
- else
- turtle.turnLeft()
- moveLeft()
- end
- end
- function moveRight()
- turtle.turnLeft()
- if turtle.forward() then
- if turtle.forward() then
- turtle.turnLeft()
- if turtle.forward() then
- turtle.turnRight()
- print("I moved around the tree.")
- move()
- else
- print("Couldn't go right, trying left...")
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- moveLeft()
- end
- else
- print("Couldn't go right, trying left...")
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- moveLeft()
- end
- else
- print("Couldn't go right, trying left...")
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- moveLeft()
- end
- end
- function moveLeft()
- turtle.turnLeft()
- if turtle.forward() then
- turtle.turnRight()
- if turtle.forward() then
- if turtle.forward() then
- turtle.turnRight()
- if turtle.forward() then
- turtle.turnLeft()
- print("I moved around the tree.")
- move()
- else
- print("I'm seriously stuck, master...")
- end
- else
- print("I'm seriously stuck, master...")
- end
- else
- print("I'm seriously stuck, master...")
- end
- else
- print("I'm seriously stuck, master...")
- end
- end
- function findTree()
- local success, data = turtle.inspect()
- if success then
- if data.name == "minecraft:log" then
- cut()
- elseif data.name == "minecraft:fence" then
- if direction == 0 then
- turtle.turnRight()
- if turtle.forward() then
- turtle.turnRight()
- direction = 1
- move()
- else
- print("Couldn't turn right, trying left...")
- turtle.turnLeft()
- turtle.turnLeft()
- if turtle.forward() then
- turtle.turnLeft()
- move()
- else
- print("Couldn't turn left either, so I'm stuck, master...")
- end
- end
- elseif direction == 1 then
- turtle.turnLeft()
- if turtle.forward() then
- turtle.turnLeft()
- direction = 0
- move()
- else
- print("Couldn't turn left, trying right...")
- turtle.turnRight()
- turtle.turnRight()
- if turtle.forward() then
- turtle.turnRight()
- move()
- else
- print("Couldn't turn right either, so I'm stuck, master...")
- end
- end
- else
- print("I've lost my way, master...")
- end
- else
- moveAround()
- end
- else
- move()
- end
- print(direction)
- end
- function cut()
- local movesUp = 0
- local success, data = turtle.inspect()
- while success do
- success, data = turtle.inspect()
- if localData.name == "minecraft:log" then
- turtle.dig()
- turtle.digUp()
- turtle.up()
- movesUp = movesUp + 1
- print("Cutting the log")
- end
- print("Looping...")
- end
- print("Done cutting the tree")
- for i = 1, movesUp do
- turtle.down()
- print("Moving down again...")
- end
- if turtle.forward() then
- if turtle.forward() then
- turtle.turnLeft()
- turtle.turnLeft()
- placeSapling()
- else
- print("Couldn't move forward, master...")
- end
- else
- print("Couldn't move forward, master...")
- end
- end
- function placeSapling()
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- local data = turtle.getItemDetail(i)
- if data.name == "minecraft:sapling" then
- turtle.select(i)
- turtle.place()
- turtle.turnLeft()
- turtle.turnLeft()
- move()
- end
- end
- end
- end
- move()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement