Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local clr, cp = term.clear, term.setCursorPos
- local function ensure(func, ...) -- Thanks Fatboychummy
- local args = table.pack(...)
- while not func() do
- for i = 1, args.n do
- args[i]()
- end
- end
- end
- local function find(item)
- local slot = 1
- while slot ~= 17 do
- local data = turtle.getItemDetail(slot)
- if data then
- if data.name == item then return slot end
- end
- slot = slot + 1
- end
- return false
- end
- local function refuel()
- if turtle.getFuelLevel() == 0 then
- print("Refueling...")
- turtle.select(find("minecraft:coal_block") or find("minecraft:coal") or 1)
- turtle.refuel(1)
- if turtle.getFuelLevel() == 0 then
- print("Refuel Needed.")
- while turtle.getFuelLevel() == 0 do
- sleep(.5) turtle.select(find("minecraft:coal") or 1) turtle.refuel(1)
- end
- end
- end
- end
- local function forward() refuel() write("F") ensure(turtle.forward) end
- local function reverse() refuel() write("B") ensure(turtle.back) end
- local function up() refuel() write("U") ensure(turtle.up) end
- local function down() refuel() write("D") ensure(turtle.down) end
- local function turn(d) write("2") if d == 1 then ensure(turtle.turnRight) else ensure(turtle.turnLeft) end end
- --[[
- Only when idle: <<= create the config only when it is time to move
- - config file does not exist
- Only while moving forward: <<= only edit config when starting to turn
- - config file exists with:
- - turned = false
- Only while turning: <<== edit on every stage of turn
- - config file exists with:
- - turned = true
- - stage = x
- --]]
- local wait = 5
- local tbl = {}
- local function reset()
- local d = tbl.data or {farmed = 0}
- tbl = {waittimes = {wait, 0}, running = false, staging = false, stage = 0, ended = 0, data=d}
- end reset()
- local function save()
- write("*")
- local f = fs.open("/ft_config.lua", "w") f.write(textutils.serialize(tbl)) f.close()
- end
- if fs.exists("/ft_config.lua") then
- local f = fs.open("/ft_config.lua", "r")
- if not f then return printError("Failed to open ft_config.lua") end
- tbl = textutils.unserialize(f.readAll()) f.close()
- if type(tbl) ~= "table" then return printError("Failed to read ft_config.lua") end
- end
- clr()
- print("Rebooted:")
- print(textutils.serialize(tbl)) sleep(3) clr()
- local stages = {
- turtle.dig,
- forward,
- turtle.digUp,
- up,
- turtle.digUp,
- up,
- turtle.digUp,
- up,
- turtle.digUp,
- up,
- turtle.digUp,
- down,
- down,
- down,
- down,
- reverse,
- }
- --[[
- if turtle.detect() then
- if tbl.stage == 2 or tbl.stage == 5 then tbl.staging, tbl.ended = false, 1 return end
- end
- if tbl.stage == 6 then tbl.staging = false end
- if tbl.stage > 6 then tbl.stage = 1 end
- local tmp = tbl.stage
- if tbl.stage == 3 then tbl.staging = false end save()
- if tbl.ended ~= 1 then write("4["..tbl.stage.."]") stages[tmp]() end
- --]]
- local function doStage()
- tbl.stage = tbl.stage + 1
- if tbl.stage > #stages then tbl.stage, tbl.running = 0, false end save()
- if tbl.running then stages[tbl.stage]() else
- clr() local b,c = false, false
- for i=1, 16 do
- local a = turtle.getItemDetail(i)
- if a then
- if a.name == "minecraft:sapling" and not b then
- b=true
- turtle.select(i)
- turtle.transferTo(2,64)
- elseif a.name == "minecraft:coal_block" and not c then
- c=true
- turtle.select(i)
- turtle.transferTo(1,64)
- else
- turtle.select(i)
- turtle.dropDown(64)
- end
- end
- end
- end
- end
- while true do
- if tbl.running then
- doStage()
- else
- cp(1,1) print("Farmed: "..tbl.data.farmed)
- sleep(1) local a,b = turtle.inspect() if a then if b.name == "minecraft:log" then tbl.running = true end else local a = find("minecraft:sapling") if a ~= false then turtle.select(a) turtle.place() end end
- turtle.suckUp()
- turtle.suck()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment