Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("pastebin run eE0AQbnV")
- local modem = peripheral.wrap("bottom")
- local me = "turtle_29"
- _G.chests = modem.getNamesRemote()
- local itemNames = {}
- local mon = peripheral.wrap("monitor_21")
- mon.clear()
- local tempChests = {}
- for i = 1,#chests do
- if string.find(chests[i],"chest") then
- table.insert(tempChests,chests[i])
- end
- end
- _G.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
- _G.chestSize = {}
- _G.inv = {}
- _G.chestNames = {}
- for i = 1,#chests do
- chestSize[i] = peripheral.call(chests[i],"size")
- chestNames[i] = chests[i]
- chests[i] = peripheral.wrap(chests[i])
- end
- function initinv()
- _G.inv = {}
- for i = 1,#chests do
- 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.displayName] == nil then
- inv[data.displayName] = data
- table.insert(itemNames,data.displayName)
- end
- inv[data.displayName].count = inv[data.displayName].count + data.count
- end
- end
- end
- end
- initinv()
- function storeItem()
- local myItem = turtle.getItemDetail(1)
- if myItem == nil then
- return
- end
- 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].pullItems(me,1,nil,j)
- return
- else
- local data = temp.getMetadata()
- if data.displayName == myItem.displayName then
- chests[i].pullItems(me,1,nil,j)
- 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
- inv[data.displayName].count = inv[data.displayName].count - data.count
- else
- chests[i].pushItems(me,j,count)
- inv[data.displayName].count = inv[data.displayName].count - count
- return
- end
- end
- end
- end
- end
- end
- if inv == nil then
- _G.items = {{"Redstone",11},{"Stone",135},{"Andesite",17},{"Diamond",5593},{"Iron",9235},{"Banner",999999},{"Gold",2549},{"Idfk",325},{"Something",2350},{"Hello",125},{"Argghh",13},{"Pirate Hat",15},{"Flex Tape",135},{"Cool Music",315},{"Hello there",15},{"Nice",69},{"Beep beep",159},{"Test item",150},{"Another Test Item",153},{"Wew",95},{"Yellow Dye",65},{"Yip yip",96},{"Nonsense",92},{"Arr matey",32},{"When can I stop",159},{"Boring stuff",1},{"Sex toys",99991},{"a",1},{"b",1},{"c",1},{"d",1},{"e",1},{"f",1},{"g",1},{"h",1},{"i",1},{"j",1},{"k",1},{"l",1},{"m",4},{"n",6},{"o",2},{"p",67},{"q",2498},{"r",12},{"s",32},{"t",2462},{"u",53},{"v",426},{"w",91},{"x",296},{"y",85},{"z",29},{"one",1},{"two",2},{"three",3},{"four",4},{"five",5},{"six",6},{"seven",7},{"eight",8},{"nine",9},{"ten",10},{"eleven",11},{"twelve",12},{"thirteen",13},{"doom",666},{"heart",2}}
- _G.inv = {}
- for t=1,#items do
- inv[items[t][1]] = {displayName=items[t][1],count=items[t][2]}
- end
- end
- _G.iScr = 0
- _G.tItems = 0
- _G.iSelect = 2
- _G.iAmount = 0
- _G.iStack = false
- _G.items = {}
- _G.gS = 9 -- Grid Size
- for k,v in pairs(inv) do
- _G.items[#_G.items+1] = v
- end
- function regenScreen()
- term.setBackgroundColor(colors.black)
- tX,tY = term.getSize()
- mX = math.ceil(tX/2)
- mwm.clear()
- mwm.setColor(colors.lightGray)
- mwm.rect(1,tY-2,tX,3)
- mwm.setColor(colors.red)
- mwm.rect(1,tY-2,2,1)
- mwm.rect(1,tY,2,1)
- mwm.setColor(colors.lime)
- mwm.rect(tX-1,tY-2,2,1)
- mwm.rect(tX-1,tY,2,1)
- mwm.setColor(colors.black)
- mwm.print(string.char(30),1,tY-2)
- mwm.print(string.char(30)..string.char(30),1,tY)
- mwm.print(string.char(31),tX,tY-2)
- mwm.print(string.char(31)..string.char(31),tX-1,tY)
- gX = 1 -- Grid X coord
- gY = 1 -- Grid Y coord
- tItemstemp = 0 -- Total Items on screen
- cT = 1+iScr
- if tX/2 == math.floor(tX/2) then
- rW = 4
- else
- rW = 3
- end
- mwm.setColor(colors.white)
- mwm.rect(mX-1,tY-1,rW,1)
- mwm.setColor(colors.red)
- mwm.rect(mX-2,tY-1,1,1)
- mwm.setColor(colors.lime)
- mwm.rect(mX+2,tY-1,1,1)
- if string.len(iAmount) > rW and _G.iStack == false then
- _G.iStack = true
- end
- if iStack == true then
- mwm.setColor(colors.orange)
- else
- mwm.setColor(colors.gray)
- end
- mwm.rect(mX-3,tY-1,1,1)
- if items[iSelect] ~= nil and iAmount > 0 then
- mwm.setColor(colors.orange)
- else
- mwm.setColor(colors.gray)
- end
- mwm.rect(mX+4,tY-2,6,3)
- mwm.setColor(colors.gray)
- mwm.rect(mX-8,tY-2,4,1)
- mwm.rect(mX-8,tY,4,1)
- mwm.setColor(colors.black)
- if string.len(iAmount) > rW then
- iAmount = math.floor(iAmount/64)*64
- mwm.print(math.floor(iAmount/64).."S",mX-1,tY-1)
- if _G.iStack == false then
- _G.iStack = true
- end
- else
- mwm.print(iAmount,mX-1,tY-1)
- end
- mwm.print("Zoom",mX-8,tY-1)
- mwm.setColor(colors.white)
- mwm.print("Take",mX+5,tY-1)
- mwm.print("-",mX-2,tY-1)
- mwm.print("+",mX+2,tY-1)
- mwm.print("S",mX-3,tY-1)
- mwm.print("/\\",mX-7,tY-2)
- mwm.print("\\/",mX-7,tY)
- for t=1+iScr,#items do
- v = items[t]
- if gX+gS-1 > tX then
- gY = gY+2
- gX = 1
- if math.floor((gY+1)/4) ~= (gY+1)/4 then
- cT = 1+iScr
- else
- cT = 2+iScr
- end
- end
- if gX+gS-1 <= tX and gY <= tY-4 then
- tItemstemp = tItemstemp+1
- if iSelect == t then
- mwm.setColor(colors.orange)
- elseif math.floor(cT/2) == cT/2 then
- mwm.setColor(colors.lightBlue)
- else
- mwm.setColor(colors.cyan)
- end
- mwm.rect(gX,gY,gS,2)
- mwm.setColor(colors.black)
- if v.displayName == nil then
- mwm.print(items[t][1],gX,gY)
- mwm.print("?",gX,gY+1)
- else
- mwm.print(string.sub(v.displayName,1,gS),gX,gY)
- mwm.print(string.sub(tostring(v.count),1,gS),gX,gY+1)
- end
- end
- gX = gX+gS
- cT = cT+1
- end
- if _G.tItems < tItemstemp then
- _G.tItems = tItemstemp
- end
- mwm.setColor(colors.gray)
- mwm.print((iScr+1).."-"..(iScr+tItems),4,tY-2)
- mwm.print("of",4,tY-1)
- mwm.print(#items,4,tY)
- end
- regenScreen()
- mwm.render()
- tX,tY = term.getSize()
- mX = math.ceil(tX/2)
- while true do
- event,button,x,y = os.pullEvent()
- -- term.setBackgroundColor(colors.lightGray)
- -- term.setCursorPos(3,tY)
- if event == "turtle_inventory" then
- storeItem()
- initinv()
- elseif event == "mouse_click" then
- -- print(event..","..button..","..x..","..y)
- if y < tY-2 then
- gX = 1
- gY = 1
- for t=1+iScr,#items do
- if gX+gS-1 > tX then
- gY = gY+2
- gX = 1
- end
- if x >= gX and x <= gX+gS-1 and y >= gY and y <= gY+1 then
- _G.iSelect = t
- break
- end
- gX = gX+gS
- end
- regenScreen()
- mwm.render()
- elseif y >= tY-2 then
- if x >= mX+4 and x <= mX+9 and items[iSelect] ~= nil and iAmount > 0 then -- take item
- takeItem(items[iSelect].displayName,iAmount)
- turtle.drop()
- iAmount = 0
- initinv()
- regenScreen()
- mwm.render()
- elseif x >= mX-8 and x <= mX-5 then -- zoom
- if y == tY-2 and _G.gS < tX then
- _G.gS = gS+1
- elseif y == tY and _G.gS > 1 then
- _G.gS = gS-1
- end
- regenScreen()
- mwm.render()
- elseif x >= tX-1 and x <= tX then
- if y == tY-2 then
- _G.iScr = iScr+math.floor(tX/gS)
- regenScreen()
- mwm.render()
- elseif y == tY then
- _G.iScr = _G.iScr+tItems
- regenScreen()
- mwm.render()
- end
- elseif x >= 1 and x <= 2 then
- if y == tY-2 and iScr > 0 then
- _G.iScr = iScr-math.floor(tX/gS)
- regenScreen()
- mwm.render()
- elseif y == tY and iScr >= tItems then
- _G.iScr = _G.iScr-tItems
- regenScreen()
- mwm.render()
- end
- elseif x == mX-2 and y == tY-1 and items[iSelect] ~= nil and iAmount > 0 then
- if iStack == true and iAmount >= 64 then
- iAmount = iAmount-64
- else
- iAmount = iAmount-1
- end
- regenScreen()
- mwm.render()
- elseif x == mX+2 and y == tY-1 and items[iSelect] ~= nil then
- if iStack == true then
- iAmount = iAmount+64
- else
- iAmount = iAmount+1
- end
- if iAmount > items[iSelect].count then
- iAmount = items[iSelect].count
- end
- regenScreen()
- mwm.render()
- elseif x == mX-3 and y == tY-1 then
- if iStack == true then
- _G.iStack = false
- else
- _G.iStack = true
- end
- regenScreen()
- mwm.render()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement