Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not fs.exists("/cfg.lua") then local f = fs.open("cfg.lua", "w") f.close() end
- local f = fs.open("cfg.lua","r")
- if f then t = textutils.unserialize(f.readAll()) f.close() end
- if not t then t = {} end
- if not t.active then t.active = false end
- if not t.state then t.state = 1 end
- if not t.cycles then t.cycles = 0 end
- local states = {
- turtle.dig,
- turtle.forward,
- turtle.digUp,
- turtle.up,
- turtle.digUp,
- turtle.up,
- turtle.digUp,
- turtle.up,
- turtle.digUp,
- turtle.down,
- turtle.down,
- turtle.down,
- turtle.back,
- }
- local function refuel()
- turtle.select(1)
- term.setCursorPos(1,1) print("Refueling...")
- while turtle.getFuelLevel() == 0 do print("Requires More Fuel.") sleep(1) turtle.refuel(1) end
- end
- local function cleanInv()
- term.clear() term.setCursorPos(1,1) print("Cleaning Inventory...") sleep(2)
- for i=1, 16 do -- first 8 slots
- local info = turtle.getItemDetail(i)
- if info then
- turtle.select(i)
- if i == 1 then
- if info.name == "minecraft:oak_sapling" then
- local info = turtle.getItemDetail(2)
- if info then
- if info.name ~= "minecraft:oak_sapling" then
- turtle.select(2)
- turtle.dropDown()
- end
- turtle.select(i)
- end
- turtle.transferTo(2,64-turtle.getItemCount(2))
- end
- if info.name ~= "minecraft:charcoal" then
- turtle.dropDown()
- end
- elseif i == 2 then
- if info.name == "minecraft:coal" or info.name == "minecraft:charcoal" then
- local info = turtle.getItemDetail(1)
- if info then
- if info.name ~= "minecraft:coal" or info.name ~= "minecraft:charcoal" then
- turtle.select(2)
- turtle.dropDown()
- end
- turtle.select(i)
- end
- turtle.transferTo(1,64-turtle.getItemCount(1))
- end
- if info.name ~= "minecraft:oak_sapling" then
- turtle.dropDown()
- end
- elseif info.name == "minecraft:oak_sapling" and i ~= 2 then -- toss to slot 2
- if turtle.getItemCount(2) ~= 64 then
- turtle.transferTo(2,64-turtle.getItemCount(2))
- end
- turtle.select(i)
- turtle.dropDown()
- elseif info.name == "minecraft:charcoal" and i ~= 1 then -- toss to slot 1
- if turtle.getItemCount(1) ~= 64 then
- turtle.transferTo(1,64-turtle.getItemCount(1))
- end
- turtle.select(i)
- turtle.dropDown()
- else
- turtle.dropDown()
- end
- end
- end
- end
- local function doStates()
- term.clear() term.setCursorPos(1,1)
- print("Executing Program...")
- t.active = true
- while t.state < #states+1 do
- term.setCursorPos(1,2) print("Stage: ["..t.state.." / "..#states.."]")
- if turtle.getFuelLevel() == 0 then refuel() end
- states[t.state]()
- t.state = t.state + 1
- local f = fs.open("cfg.lua", "w")
- f.write(textutils.serialize(t)) f.close()
- sleep(.1)
- end
- t.active = false
- t.state = 1 -- just to make sure
- t.cycles = t.cycles+1
- local f = fs.open("cfg.lua", "w")
- f.write(textutils.serialize(t)) f.close()
- cleanInv()
- end
- term.clear()
- if t.active then print("Picking up...") sleep(2) doStates() end
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("Status: Idle")
- print("Cycles: "..t.cycles)
- print("Fuel Remaining: "..turtle.getFuelLevel().." ("..math.floor(turtle.getFuelLevel()/8).." Cycles)")
- local s,d = turtle.inspect()
- if s then
- if d.name == "minecraft:oak_log" then
- doStates()
- end
- end
- turtle.suck(64)
- turtle.suckUp(64)
- local info = turtle.getItemDetail(2)
- if info and not turtle.detect() then
- if info.name == "minecraft:oak_sapling" then turtle.select(2) turtle.place() end
- end
- sleep(1)
- end
Add Comment
Please, Sign In to add comment