Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- config
- local rsIn = "top"
- local rsOut = "front"
- local chestPrefix = "minecraft:chest"
- local genPrefix = "xu2:tilemachineprovider"
- -- end of config
- local chest = false
- local function get(tb)
- local tab = {}
- for k, v in pairs(peripheral.getNames()) do
- if string.find(v, tb) then
- tab[#tab + 1] = v
- end
- end
- return tab
- end
- local function moveToGenerator(genName)
- local gen = peripheral.wrap(genName)
- if gen then
- local i = gen.list()
- local flg = true
- for k, v in pairs(i) do
- flg = false
- break
- end
- if flg then
- print("Stocking peripheral " .. tostring(genName) .. ".")
- local dat = chest.list()
- for i = 1, chest.size() do
- if dat[i] then
- if chest.pushItems(genName,i,1) then
- print("Peripheral stocked.")
- return
- end
- end
- end
- else
- print("Peripheral " .. tostring(genName) .. " is already stocked.")
- end
- else
- printError("Warning: Peripheral " .. tostring(genName) .. " doesn't actually exist!")
- end
- end
- local function moveToGenerators()
- local genNames = get(genPrefix)
- chest = peripheral.find(chestPrefix)
- if chest then
- local itm = chest.list()
- local flg = false
- for i = 1,#itm do
- if itm[i] then
- flg = true break -- check if there are items in the chest.
- end
- end
- if not flg then
- print("The chest is empty.")
- return
- end -- if no items in the chest, exit.
- -- if not, move items to generators.
- for i = 1,#genNames do
- moveToGenerator(genNames[i])
- end
- else
- printError("Warning: Failed to find chest.")
- end
- end
- local function rsWatch()
- while true do
- if rs.getInput(rsIn) then
- rs.setOutput(rsOut, true)
- print("GENERATORS ON\n-------- rsWatch")
- else
- rs.setOutput(rsOut, false)
- print("GENERATORS OFF\n-------- rsWatch")
- end
- os.sleep(1)
- end
- end
- local function main()
- local i = 1
- while true do
- moveToGenerators()
- print("--------", i)
- i = i + 1
- os.sleep(10)
- end
- end
- local ok, err = pcall(parallel.waitForAny, main, rsWatch)
- if not ok then
- printError(err)
- print()
- print("Restarting in 15 seconds")
- os.sleep(15)
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement