Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sel = 1;
- turtle.select(sel);
- select = function(n)
- sel = n;
- return turtle.select(n);
- end
- getSelected = function()
- return sel;
- end
- saplingSlot = 1
- logSlot = 2
- chestSlot = 3
- function moveMethod(m)
- local r = function()
- local moved = m()
- if not moved then
- cantMove(m)
- end
- return moved
- end
- return r
- end
- function moveThenSuckMethod(m)
- local r = function()
- local moved = m()
- if not moved then
- cantMove(m)
- end
- turtle.suckDown()
- return moved
- end
- return r
- end
- up = moveMethod(turtle.up)
- down = moveMethod(turtle.down)
- forward = moveThenSuckMethod(turtle.forward)
- back = moveMethod(turtle.back)
- function clearChestSlot()
- if turtle.getItemCount(chestSlot) > 0 then
- select(chestSlot)
- for i=1,16 do
- if turtle.getItemCount(i) == 0 then
- if i ~= saplingSlot and i ~= logSlot and i ~= chestSlot then
- turtle.transferTo(i)
- end
- else
- if i~= chestSlot and turtle.compareTo(i) and turtle.getItemSpace(i) > 0 then
- turtle.transferTo(i)
- clearChestSlot()
- end
- end
- end
- end
- end
- cantMove = function(move)
- if turtle.getFuelLevel() > 0 then
- select(logSlot)
- if turtle.compare() then
- turtle.dig()
- forward()
- turtle.digDown()
- if turtle.getItemCount(saplingSlot) > 0 then
- select(saplingSlot)
- turtle.placeDown()
- select(logSlot)
- end
- local n = 0
- local didCheck = false -- encountered a bug that stops the turtle short sometimes
- local keepChopping = turtle.compareUp()
- while keepChopping do
- turtle.digUp()
- up()
- select(saplingSlot)
- for i=1,4 do
- turtle.dig()
- turtle.turnRight()
- end
- n = n + 1
- select(logSlot)
- if turtle.compareUp() then
- keepChopping = true
- didCheck = false
- else
- if didCheck then
- keepChopping = false
- else
- didCheck = true
- end
- select(saplingSlot)
- end
- end
- while n > 0 do
- down()
- n = n - 1
- end
- else
- while not move() do
- sleep(1)
- end
- end
- else
- local dig, place, drop, suck = nil
- select(logSlot)
- if not turtle.detectUp() then
- dig = turtle.digUp
- place = turtle.placeUp
- drop = turtle.dropUp
- suck = turtle.suckUp
- else
- dig = turtle.dig
- place = turtle.place
- drop = turtle.drop
- suck = turtle.suck
- end
- dig()
- select(chestSlot)
- place()
- for i=1,16 do
- select(i)
- if i~=logSlot then
- drop()
- end
- end
- if turtle.getItemCount(logSlot) > 3 then
- turtle.craft(3)
- turtle.refuel()
- end
- select(1)
- while suck() do end
- clearChestSlot()
- select(chestSlot)
- dig()
- select(saplingSlot)
- suck()
- move()
- end
- end
- actions = {u=up,d=down,f=forward,b=back,tl=turtle.turnLeft,tr=turtle.turnRight}
- function doInstructions(arr)
- for i,v in ipairs(arr) do
- if type(v) == 'function' then
- v()
- else
- local p = v:find(":")
- local a = {}
- if p == nil then
- a = {v, 1}
- else
- a = {v:sub(1, p-1), tonumber(v:sub(p+1))}
- end
- if actions[a[1]] ~= nil then
- for vari=1,a[2],1 do
- actions[a[1]]()
- end
- end
- end
- end
- end
- function max(j, k)
- if j > k then
- return j
- else
- return k
- end
- end
- function dropOffItems()
- for i=1,16 do
- select(i)
- if i == logSlot then
- turtle.dropDown(max(turtle.getItemCount(logSlot) - 12, 0))
- elseif i ~= saplingSlot and i ~= chestSlot then
- turtle.dropDown()
- end
- end
- end
- inst = {'u', 'f', 'tr', 'f:15', 'tr', 'f:3', 'tr', 'f:12', 'tl', 'f:3', 'tl', 'f:12', 'tr', 'f:3', 'tr', 'f:12', 'tl', 'f:3', 'tl', 'f:12', 'tr', 'f:3', 'tr', 'f:15', 'tr', 'f:14', 'd', dropOffItems}
- while true do
- select(logSlot)
- --[[while not turtle.compare() do
- sleep(5)
- end]]--
- doInstructions(inst)
- sleep(5)
- --doInstructions(inst)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement