Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chests = {}
- local cobbleCount = 0
- local maxCobble = 0
- local outputTurtle = "570"
- local turtles = {}
- local modem = peripheral.wrap("right")
- modem.open(1)
- local mX,mY = term.getSize()
- term.clear()
- local function writeAt(x,y,wr,fg,bg)
- fg = fg or colors.black
- bg = bg or colors.white
- local clr = string.rep(" ",mX)
- term.setCursorPos(1,y)
- term.write(clr)
- term.setCursorPos(x,y)
- term.write(wr)
- end
- local function refreshTurtles()
- turtles = {}
- for k,v in pairs(peripheral.getNames()) do
- if v:find("turtle") and not v:find(outputTurtle) then
- table.insert(turtles,v)
- end
- end
- end
- local function startTurtle(t)
- t = peripheral.wrap(t)
- if type(t) == "table" and type(t.turnOn) == "function" then
- t.turnOn()
- end
- end
- local function refreshChests()
- local all = peripheral.getNames()
- chests = {}
- for k,v in pairs(all) do
- if v:find("chest") or v:find("cache") then
- table.insert(chests,v)
- end
- end
- end
- local function refreshItems()
- refreshChests()
- cobbleCount = 0
- maxCobble = 0
- for i = 1,#chests do
- if chests[i]:find("cache") then
- maxCobble = maxCobble + 20000
- local cChest = peripheral.wrap(chests[i])
- local itm = cChest.list()[1]
- if itm then
- cobbleCount = cobbleCount + itm.count
- end
- else
- local cChest = peripheral.wrap(chests[i])
- local items = cChest.list()
- local sz = cChest.size()
- maxCobble = maxCobble+(sz*64)
- local chestEmptyCount = 0
- for o = 1,sz do
- if items[o] then
- if items[o].name == "minecraft:cobblestone" and items[o].damage == 0 then
- cobbleCount = cobbleCount + items[o].count
- end
- end
- end
- end
- end
- end
- local function wait(t)
- for i = t,0,-1 do
- writeAt(1,1,"Waiting " .. tostring(i) .. " second(s).")
- os.sleep(1)
- end
- end
- local function main()
- while true do
- local lastEmptyChest = 1
- writeAt(1,1,"Starting move cycle...")
- refreshTurtles()
- refreshItems()
- writeAt(1,2,tostring(cobbleCount) .. "/" .. tostring(maxCobble))
- if cobbleCount < maxCobble-256 then
- for i = 1,#turtles do
- startTurtle(turtles[i])
- local cTurt = peripheral.wrap(turtles[i])
- local items = cTurt.list()
- for k,v in pairs(items) do
- for o = lastEmptyChest,#chests do
- writeAt(1,3,"Last empty chest: " .. tostring(chests[lastEmptyChest]))
- writeAt(1,4,", index " .. tostring(lastEmptyChest))
- if cTurt.pushItems(chests[o],k,64) > 0 then
- break
- else
- lastEmptyChest = o+1
- end
- end
- end
- for i = 3,4 do
- writeAt(1,i,"")
- end
- end
- writeAt(1,1,"End of move cycle...")
- refreshItems()
- writeAt(1,2,tostring(cobbleCount) .. "/" .. tostring(maxCobble))
- else
- writeAt(1,1,"Inventory full, no move.")
- writeAt(1,3,"Shutting down turtles.")
- modem.transmit(1,1,"shutdown")
- end
- wait(30)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement