Advertisement
Guest User

startup

a guest
Oct 22nd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.31 KB | None | 0 0
  1. shell.run("pastebin run eE0AQbnV")
  2. local modem = peripheral.wrap("bottom")
  3. local me = "turtle_29"
  4. _G.chests = modem.getNamesRemote()
  5. local itemNames = {}
  6. local mon = peripheral.wrap("monitor_21")
  7. mon.clear()
  8. local tempChests = {}
  9. for i = 1,#chests do
  10.     if string.find(chests[i],"chest") then
  11.         table.insert(tempChests,chests[i])
  12.     end
  13. end
  14. _G.chests = tempChests
  15.  
  16. --for i = 1,#chests do
  17.     --print(chests[i])
  18.     --local meth = peripheral.getMethods(chests[i])
  19.     --for j = 1,#meth do
  20.         --print("    "..meth[j])
  21.     --end
  22. --end
  23.  
  24. _G.chestSize = {}
  25. _G.inv = {}
  26. _G.chestNames = {}
  27. for i = 1,#chests do
  28.     chestSize[i] = peripheral.call(chests[i],"size")
  29.     chestNames[i] = chests[i]
  30.     chests[i] = peripheral.wrap(chests[i])
  31. end
  32. function initinv()
  33.     _G.inv = {}
  34.     for i = 1,#chests do
  35.         for j = 1,chestSize[i] do
  36.             local temp = chests[i].getItem(j)
  37.            
  38.             if temp ~= nil then
  39.                 local data = temp.getMetadata()
  40.                 --for k,v in pairs(data) do
  41.                     --print(k..":"..tostring(v))
  42.                 --end
  43.                 if inv[data.displayName] == nil then
  44.                     inv[data.displayName] = data
  45.                     table.insert(itemNames,data.displayName)
  46.                 end
  47.                 inv[data.displayName].count = inv[data.displayName].count + data.count
  48.             end
  49.         end
  50.     end
  51. end
  52. initinv()
  53. function storeItem()
  54.     local myItem = turtle.getItemDetail(1)
  55.     if myItem == nil then
  56.         return
  57.     end
  58.     local count = myItem.count
  59.     local myinv = peripheral.wrap("right")
  60.     for i = 1,#chests do
  61.         for j = 1,chestSize[i] do
  62.             local temp = chests[i].getItem(j)
  63.             if temp == nil then
  64.                 chests[i].pullItems(me,1,nil,j)
  65.                 return
  66.             else
  67.                 local data = temp.getMetadata()
  68.                 if data.displayName == myItem.displayName then
  69.                     chests[i].pullItems(me,1,nil,j)
  70.                     count = count - (data.maxCount-data.count)
  71.                     if count <= 0 then
  72.                         return
  73.                     end
  74.                 end
  75.             end
  76.         end
  77.     end    
  78. end
  79.  
  80. function takeItem(name,count)
  81.     for i = 1,#chests do
  82.         for j =1,chestSize[i] do
  83.             local temp = chests[i].getItem(j)
  84.             if temp == nil then
  85.                
  86.             else
  87.                 local data = temp.getMetadata()
  88.                 if data.displayName == name then
  89.                     if data.count < count then
  90.                         chests[i].pushItems(me,j,data.count)
  91.                         count = count - data.count
  92.                         inv[data.displayName].count = inv[data.displayName].count - data.count
  93.                     else
  94.                         chests[i].pushItems(me,j,count)
  95.                         inv[data.displayName].count = inv[data.displayName].count - count
  96.                         return
  97.                     end
  98.                 end
  99.             end
  100.         end
  101.     end
  102. end
  103.  
  104. if inv == nil then
  105.     _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}}
  106.     _G.inv = {}
  107.     for t=1,#items do
  108.       inv[items[t][1]] = {displayName=items[t][1],count=items[t][2]}
  109.     end
  110. end
  111. _G.iScr = 0
  112. _G.tItems = 0
  113. _G.iSelect = 2
  114. _G.iAmount = 0
  115. _G.iStack = false
  116. _G.items = {}
  117. _G.gS = 9 -- Grid Size
  118. for k,v in pairs(inv) do
  119.   _G.items[#_G.items+1] = v
  120. end
  121. function regenScreen()
  122.   term.setBackgroundColor(colors.black)
  123.   tX,tY = term.getSize()
  124.   mX = math.ceil(tX/2)
  125.   mwm.clear()
  126.   mwm.setColor(colors.lightGray)
  127.   mwm.rect(1,tY-2,tX,3)
  128.   mwm.setColor(colors.red)
  129.   mwm.rect(1,tY-2,2,1)
  130.   mwm.rect(1,tY,2,1)
  131.   mwm.setColor(colors.lime)
  132.   mwm.rect(tX-1,tY-2,2,1)
  133.   mwm.rect(tX-1,tY,2,1)
  134.   mwm.setColor(colors.black)
  135.   mwm.print(string.char(30),1,tY-2)
  136.   mwm.print(string.char(30)..string.char(30),1,tY)
  137.   mwm.print(string.char(31),tX,tY-2)
  138.   mwm.print(string.char(31)..string.char(31),tX-1,tY)
  139.   gX = 1 -- Grid X coord
  140.   gY = 1 -- Grid Y coord
  141.   tItemstemp = 0 -- Total Items on screen
  142.   cT = 1+iScr
  143.   if tX/2 == math.floor(tX/2) then
  144.     rW = 4
  145.   else
  146.     rW = 3
  147.   end
  148.   mwm.setColor(colors.white)
  149.   mwm.rect(mX-1,tY-1,rW,1)
  150.   mwm.setColor(colors.red)
  151.   mwm.rect(mX-2,tY-1,1,1)
  152.   mwm.setColor(colors.lime)
  153.   mwm.rect(mX+2,tY-1,1,1)
  154.   if string.len(iAmount) > rW and _G.iStack == false then
  155.     _G.iStack = true
  156.   end
  157.   if iStack == true then
  158.     mwm.setColor(colors.orange)
  159.   else
  160.     mwm.setColor(colors.gray)
  161.   end
  162.   mwm.rect(mX-3,tY-1,1,1)
  163.   if items[iSelect] ~= nil and iAmount > 0 then
  164.     mwm.setColor(colors.orange)
  165.   else
  166.     mwm.setColor(colors.gray)
  167.   end
  168.   mwm.rect(mX+4,tY-2,6,3)
  169.   mwm.setColor(colors.gray)
  170.   mwm.rect(mX-8,tY-2,4,1)
  171.   mwm.rect(mX-8,tY,4,1)
  172.   mwm.setColor(colors.black)
  173.   if string.len(iAmount) > rW then
  174.     iAmount = math.floor(iAmount/64)*64
  175.     mwm.print(math.floor(iAmount/64).."S",mX-1,tY-1)
  176.     if _G.iStack == false then
  177.       _G.iStack = true
  178.     end
  179.   else
  180.     mwm.print(iAmount,mX-1,tY-1)
  181.   end
  182.   mwm.print("Zoom",mX-8,tY-1)
  183.   mwm.setColor(colors.white)
  184.   mwm.print("Take",mX+5,tY-1)
  185.   mwm.print("-",mX-2,tY-1)
  186.   mwm.print("+",mX+2,tY-1)
  187.   mwm.print("S",mX-3,tY-1)
  188.   mwm.print("/\\",mX-7,tY-2)
  189.   mwm.print("\\/",mX-7,tY)
  190.   for t=1+iScr,#items do
  191.     v = items[t]
  192.     if gX+gS-1 > tX then
  193.       gY = gY+2
  194.       gX = 1
  195.       if math.floor((gY+1)/4) ~= (gY+1)/4 then
  196.         cT = 1+iScr
  197.       else
  198.         cT = 2+iScr
  199.       end
  200.     end
  201.     if gX+gS-1 <= tX and gY <= tY-4 then
  202.       tItemstemp = tItemstemp+1
  203.       if iSelect == t then
  204.         mwm.setColor(colors.orange)
  205.       elseif math.floor(cT/2) == cT/2 then
  206.         mwm.setColor(colors.lightBlue)
  207.       else
  208.         mwm.setColor(colors.cyan)
  209.       end
  210.       mwm.rect(gX,gY,gS,2)
  211.       mwm.setColor(colors.black)
  212.       if v.displayName == nil then
  213.         mwm.print(items[t][1],gX,gY)
  214.         mwm.print("?",gX,gY+1)
  215.       else
  216.         mwm.print(string.sub(v.displayName,1,gS),gX,gY)
  217.         mwm.print(string.sub(tostring(v.count),1,gS),gX,gY+1)
  218.       end
  219.     end
  220.     gX = gX+gS
  221.     cT = cT+1
  222.   end
  223.   if _G.tItems < tItemstemp then
  224.     _G.tItems = tItemstemp
  225.   end
  226.   mwm.setColor(colors.gray)
  227.   mwm.print((iScr+1).."-"..(iScr+tItems),4,tY-2)
  228.   mwm.print("of",4,tY-1)
  229.   mwm.print(#items,4,tY)
  230. end
  231. regenScreen()
  232. mwm.render()
  233. tX,tY = term.getSize()
  234. mX = math.ceil(tX/2)
  235. while true do
  236.   event,button,x,y = os.pullEvent()
  237. --  term.setBackgroundColor(colors.lightGray)
  238. --  term.setCursorPos(3,tY)
  239.   if event == "turtle_inventory" then
  240.     storeItem()
  241.     initinv()
  242.   elseif event == "mouse_click" then
  243. --    print(event..","..button..","..x..","..y)
  244.     if y < tY-2 then
  245.       gX = 1
  246.       gY = 1
  247.       for t=1+iScr,#items do
  248.         if gX+gS-1 > tX then
  249.           gY = gY+2
  250.           gX = 1
  251.         end
  252.         if x >= gX and x <= gX+gS-1 and y >= gY and y <= gY+1 then
  253.             _G.iSelect = t
  254.             break
  255.         end
  256.         gX = gX+gS
  257.       end
  258.       regenScreen()
  259.       mwm.render()
  260.     elseif y >= tY-2 then
  261.       if x >= mX+4 and x <= mX+9 and items[iSelect] ~= nil and iAmount > 0 then -- take item
  262.         takeItem(items[iSelect].displayName,iAmount)
  263.         turtle.drop()
  264.         iAmount = 0
  265.         initinv()
  266.         regenScreen()
  267.         mwm.render()
  268.       elseif x >= mX-8 and x <= mX-5 then -- zoom
  269.         if y == tY-2 and _G.gS < tX then
  270.           _G.gS = gS+1
  271.         elseif y == tY and _G.gS > 1 then
  272.           _G.gS = gS-1
  273.         end
  274.         regenScreen()
  275.         mwm.render()
  276.       elseif x >= tX-1 and x <= tX then
  277.         if y == tY-2 then
  278.           _G.iScr = iScr+math.floor(tX/gS)
  279.           regenScreen()
  280.           mwm.render()
  281.         elseif y == tY then
  282.           _G.iScr = _G.iScr+tItems
  283.           regenScreen()
  284.           mwm.render()
  285.         end
  286.       elseif x >= 1 and x <= 2 then
  287.         if y == tY-2 and iScr > 0 then
  288.           _G.iScr = iScr-math.floor(tX/gS)
  289.           regenScreen()
  290.           mwm.render()
  291.         elseif y == tY and iScr >= tItems then
  292.           _G.iScr = _G.iScr-tItems
  293.           regenScreen()
  294.           mwm.render()
  295.         end
  296.       elseif x == mX-2 and y == tY-1 and items[iSelect] ~= nil and iAmount > 0 then
  297.         if iStack == true and iAmount >= 64 then
  298.           iAmount = iAmount-64
  299.         else
  300.           iAmount = iAmount-1
  301.         end
  302.         regenScreen()
  303.         mwm.render()
  304.       elseif x == mX+2 and y == tY-1 and items[iSelect] ~= nil then
  305.         if iStack == true then
  306.           iAmount = iAmount+64
  307.         else
  308.           iAmount = iAmount+1
  309.         end
  310.         if iAmount > items[iSelect].count then
  311.             iAmount = items[iSelect].count
  312.         end
  313.         regenScreen()
  314.         mwm.render()
  315.       elseif x == mX-3 and y == tY-1 then
  316.         if iStack == true then
  317.           _G.iStack = false
  318.         else
  319.           _G.iStack = true
  320.         end
  321.         regenScreen()
  322.         mwm.render()
  323.       end
  324.     end
  325.   end
  326. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement