Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get Q5RsfX0A ly2
- local util = require("util")
- function go()
- gridStep = 4
- gridSize = 3
- while true do
- travel()
- if shouldRestock() then
- restock()
- end
- print("all done, sleeping...")
- for i = 1, 12 do
- os.sleep(10)
- print("sleeping... " .. i .. "/12")
- end
- end
- end
- function travel()
- local cb = turtle.suck
- local goRight = true
- for j=1, gridSize do
- print("column " .. tostring(j))
- for i=1, gridSize do
- doCell()
- util.moveForward(1)
- end
- if goRight then
- util.turnRight()
- util.moveForward(3, cb)
- util.turnRight()
- util.moveForward(1)
- goRight = false
- else
- util.turnLeft()
- util.moveForward(3, cb)
- util.turnLeft()
- util.moveForward(1, cb)
- goRight = true
- end
- end
- util.moveForward(8, cb)
- util.turnRight()
- util.moveForward(9, cb)
- util.turnRight()
- end
- function doCell()
- -- turtle ends up on the OTHER side of the cell
- local _, insp = turtle.inspect()
- if insp ~= nil then
- if (insp.name == "minecraft:log" or insp.name == "traverse:fir_log") then
- chopTree()
- elseif insp.name == "minecraft:sapling" or insp.name == "traverse:fir_sapling" then
- util.moveAround(turtle.suck)
- else
- if selectSapling() then
- turtle.place()
- end
- util.moveAround(turtle.suck)
- end
- end
- end
- function chopTree()
- turtle.dig()
- util.moveForward(1)
- while turtle.digUp() do
- turtle.up()
- end
- while turtle.down() do
- turtle.dig()
- end
- util.moveForward(1)
- if selectSapling() then
- util.turnAround()
- turtle.place()
- util.turnAround()
- end
- end
- function selectSapling()
- for i = 1,16 do
- local detail = turtle.getItemDetail(i)
- if detail and (detail.name == "minecraft:sapling" or detail.name == "traverse:fir_sapling") then
- turtle.select(i)
- return i
- end
- end
- print("did not find sapling")
- return false
- end
- function shouldRestock()
- return turtle.getFuelLevel() < 100 or isFull()
- end
- function dropWood()
- for i=1,16 do
- local detail = turtle.getItemDetail(i)
- if detail and (detail.name == "minecraft:log" or detail.name == "traverse:fir_log") then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- function refuelPls()
- local s = turtle.suck()
- if s then
- useCoalAndDrop()
- end
- end
- function isFull()
- turtle.select(15)
- local detail = turtle.getItemDetail(15)
- if detail and detail.count > 0 then
- return true
- end
- return false
- end
- function useCoalAndDrop()
- local cIndex = -1
- for i=1,16 do
- local detail = turtle.getItemDetail(i)
- if detail and detail.name == "minecraft:coal" then
- cIndex = i
- end
- end
- if cIndex == -1 then return end
- turtle.select(cIndex)
- turtle.refuel(3)
- turtle.drop()
- end
- function restock()
- util.turnAround()
- util.moveForward(1)
- dropWood()
- util.turnRight()
- refuelPls()
- util.turnRight()
- util.moveForward(1)
- end
- go()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement