Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("left")
- local me = "turtle_30"
- local chests = modem.getNamesRemote()
- local itemNames = {}
- local mon = peripheral.wrap("monitor_22")
- mon.clear()
- local tempChests = {}
- for i = 1,#chests do
- if string.find(chests[i],"chest") then
- table.insert(tempChests,chests[i])
- end
- end
- chests = tempChests
- --for i = 1,#chests do
- --print(chests[i])
- --local meth = peripheral.getMethods(chests[i])
- --for j = 1,#meth do
- --print(" "..meth[j])
- --end
- --end
- local chestSize = {}
- local inv = {}
- local chestNames = {}
- for i = 1,#chests do
- chestSize[i] = peripheral.call(chests[i],"size")
- chestNames[i] = chests[i]
- chests[i] = peripheral.wrap(chests[i])
- for j = 1,chestSize[i] do
- local temp = chests[i].getItem(j)
- if temp ~= nil then
- local data = temp.getMetadata()
- --for k,v in pairs(data) do
- --print(k..":"..tostring(v))
- --end
- if inv[data.name] == nil then
- inv[data.name] = data
- table.insert(itemNames,data.displayName)
- end
- inv[data.name].count = inv[data.name].count + data.count
- end
- end
- end
- function storeItem()
- local myItem = turtle.getItemDetail(1)
- local count = myItem.count
- local myinv = peripheral.wrap("right")
- for i = 1,#chests do
- for j = 1,chestSize[i] do
- local temp = chests[i].getItem(j)
- if temp == nil then
- chests[i].pushItems(me,j,count)
- return
- else
- local data = temp.getMetadata()
- if data.name == myItem.name then
- chests[i].pushItems(me,j,count)
- count = count - (data.maxCount-data.count)
- if count <= 0 then
- return
- end
- end
- end
- end
- end
- end
- function takeItem(name,count)
- for i = 1,#chests do
- for j =1,chestSize[i] do
- local temp = chests[i].getItem(j)
- if temp == nil then
- else
- local data = temp.getMetadata()
- if data.displayName == name then
- if data.count < count then
- chests[i].pushItems(me,j,data.count)
- count = count - data.count
- else
- chests[i].pushItems(me,j,count)
- return
- end
- end
- end
- end
- end
- end
- for k,v in pairs(inv) do
- print(v.displayName..": "..v.count)
- end
- function display()
- local w,h = mon.getSize()
- local col = math.floor(w/7)
- local row = math.floor((h-5)/1)
- local x = 0
- local y = 1
- for k,v in pairs(inv) do
- local name = string.sub(v.displayName,1,4)
- mon.setCursorPos((x*7)+1,y*1)
- if (x+y)%2==0 then
- mon.setBackgroundColor(colors.lightGray)
- mon.setTextColor(colors.black)
- else
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- end
- if v.count <= 99 then
- mon.write(name.."-"..tostring(v.count))
- else
- mon.write(name.."-"..tostring(math.floor(v.count/64)).."S")
- end
- x=x+1
- if x >= col then
- x = 0
- y = y + 1
- end
- end
- end
- while true do
- display()
- write("take, list or drop? (t/l/d)")
- input = read()
- if input == "t" then
- write("obtain item:")
- local name = read()
- write("how many:")
- local count = tonumber(read())
- takeItem(name,count)
- print("item taken!")
- elseif input == "l" then
- term.clear()
- term.setCursorPos(1,1)
- for i,v in pairs(inv) do
- print(inv[i].displayName..": "..tostring(inv[i].count))
- end
- elseif input == "d" then
- if turtle.getItemCount(1) > 0 then
- storeItem()
- print("item gone!")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement