Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --name BatteryManager
- --version 1.0a
- local version = "1.0a"
- local side = {}
- side.batbox = 0
- side.chest = 4
- side.output = 1
- local batteryId = {}
- batteryId.full = 38041
- batteryId.empty = 5272
- local inventory = {}
- inventory.batbox = "Empty"
- inventory.chest = false
- inventory.chestFull = 0
- inventory.chestEmpty = 0
- inventory.output = "Not found..."
- local function output(str)
- term.clear()
- term.setCursorPos(1,1)
- print(string.format("BattMgr (v%s)",version))
- print("By BigTwisty")
- print(str)
- end
- local sorter = peripheral.wrap("back")
- local monitor = peripheral.wrap("bottom")
- term.redirect(monitor)
- monitor.setTextScale(0.5)
- while true do
- inventory.batbox = "Not Found..."
- x = sorter.list(side.batbox)
- if x ~= nil then
- inventory.batbox = "Empty"
- for id,qty in pairs(x) do
- if id == batteryId.full then
- inventory.batbox = "Full"
- else
- inventory.batbox = "Charging"
- end
- end
- end
- inventory.chestFull = 0
- inventory.chestEmpty = 0
- inventory.chestOther = 0
- x = sorter.list(side.chest)
- if x == nil then
- inventory.chest = false
- else
- inventory.chest = true
- for id,qty in pairs(x) do
- if id == batteryId.full then
- inventory.chestFull = inventory.chestFull + qty
- elseif id == batteryId.empty then
- inventory.chestEmpty = inventory.chestEmpty + qty
- end
- end
- end
- x = sorter.list(side.output)
- if x == nil then
- inventory.output = "Not found..."
- else
- inventory.output = "Ready"
- for id,qty in pairs(x) do
- if id == batteryId.full then
- inventory.output = "Full"
- end
- end
- end
- output(string.format("\n-- Status:\nBatbox: %s\nOutput: %s",
- inventory.batbox,
- inventory.output))
- write(string.format("-- Inventory:\nCharged: %d\nEmpty: %d\n",
- inventory.chestFull,
- inventory.chestEmpty))
- if (inventory.batbox == "Full") and (inventory.output == "Ready") then
- sorter.extract(side.batbox, batteryId.full, side.output, 1)
- elseif inventory.batbox == "Empty" then
- sorter.extract(side.chest, batteryId.empty, side.batbox, 1)
- end
- os.sleep(0.3)
- end
Advertisement
Add Comment
Please, Sign In to add comment