Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local clients = peripheral.call("back", "getNamesRemote")
- local chests = {}
- local items = {}
- local function DiscoverChests()
- for k,client in pairs(clients) do
- if (string.sub(peripheral.getType(client), 1, 19) == "minecraft:ironchest") then
- table.insert(chests, client)
- end
- end
- end
- local function DiscoverItems()
- for _k,_chest in pairs(chests) do
- local chest = peripheral.wrap(_chest)
- for k,_item in pairs(chest.list()) do
- local item = chest.getItem(k)
- local itemTable = {}
- itemTable.metaData = item.getMetadata()
- itemTable.displayName = itemTable.metaData.displayName
- itemTable.name = _item.name
- itemTable.count = _item.count
- itemTable.chest = _chest
- table.insert(items, itemTable)
- end
- end
- end
- local function Deposit()
- local chest = peripheral.wrap("left")
- local depositChest = nil
- for k, v in pairs(chests) do
- local depChest = peripheral.wrap(v)
- if (#depChest.list() < depChest.size()) then
- depositChest = v
- end
- end
- if (depositChest == nil) then
- print("No available chest space")
- read()
- end
- for k, item in pairs(chest.list()) do
- chest.pullItems(depositChest, k)
- end
- end
- local function main()
- term.clear()
- term.setCursorPos(1,1)
- chests = {}
- items = {}
- DiscoverChests()
- DiscoverItems()
- for k,v in pairs(items) do
- print(v.displayName..": "..v.count.." in "..string.sub(v.chest, 20))
- end
- print("Type 'dep' to deposit items into storage\nType 'req <itemindex> <itemcount>' to retreive items from storage\nPress enter to refresh item list")
- local input = read()
- if (string.lower(string.sub(input, 1, 3)) == "dep") then
- Deposit()
- end
- main()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement