Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. local C1 = {}
  2.  
  3. for _, name in pairs(peripheral.getNames()) do
  4. if peripheral.getType(name) == "crystal" then --# change "monitor" to your peripheral type.
  5. table.insert(myPeripherals, name)
  6. end
  7. end
  8.  
  9. local m = peripheral.wrap("left")
  10. local itemList = { } --# place this at or near the beginning of your code
  11.  
  12. local function drawScreen()
  13. m.setBackgroundColor(colors.blue)
  14. m.clear()
  15. local tmpY = 1
  16. m.setCursorPos(1,tmpY)
  17. for i = 1, #itemList do
  18. m.write(itemList[i].name .. ": " .. tostring(itemList[i].qty))
  19. tmpY = tmpY + 1
  20. m.setCursorPos(1,tmpY)
  21. end
  22. end
  23.  
  24. function CheckItems()
  25. itemList = { }
  26. local InvSize = C1.getInventorySize()
  27. for CurrSlot = 1, InvSize-1 do
  28. local slot = C1.getStackInSlot(CurrSlot)
  29. if slot ~= nil then -- Slots with stuff in them
  30. local match = false
  31. if #itemList == 0 then --# if there are no entries yet, add the first one
  32. itemList[1] = { name = slot.name }
  33. itemList[1].slots = { }
  34. itemList[1].slots[1] = { slot = CurrSlot }
  35. itemList[1].slots[1].qty = slot.qty
  36. itemList[1].qty = slot.qty
  37. else
  38. for i = 1, #itemList do
  39. if slot.name == itemList[i].name then
  40. itemList[i].slots[#itemList[i].slots+1] = { }
  41. itemList[i].slots[#itemList[i].slots] = { slot = CurrSlot }
  42. itemList[i].slots[#itemList[i].slots].qty = slot.qty
  43. itemList[i].qty = itemList[i].qty + slot.qty
  44. match = true
  45. break
  46. end
  47. end
  48. if not match then
  49. itemList[#itemList+1] = { name = slot.name }
  50. itemList[#itemList].slots = { }
  51. itemList[#itemList].slots[1] = { slot = CurrSlot }
  52. itemList[#itemList].slots[1].qty = slot.qty
  53. itemList[#itemList].qty = slot.qty
  54. end
  55. end
  56. end
  57. end
  58. end
  59.  
  60. while true do
  61. CheckItems()
  62. drawScreen()
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement