Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. local component = require("component")
  2. local sides = require("sides")
  3.  
  4. itemTable = {}
  5.  
  6. function checkCurrentChest()
  7. slot = 1
  8. while component.inventory_controller.getStackInSlot(sides.down, slot) ~= nil do
  9. itemInfo = component.inventory_controller.getStackInSlot(sides.down, slot)
  10. print(parseString(itemInfo.name) .. " " .. itemInfo.size)
  11. addToTable(parseString(itemInfo.name), itemInfo.size)
  12. slot = slot + 1
  13. end
  14. end
  15.  
  16. function parseString(myString) --Formats our item correctly.
  17. if string.find(myString, "minecraft:") then
  18. myString = string.gsub(myString, "minecraft:", "")
  19. return myString
  20. end
  21. if string.find(myString, "BuildCraft|Transport:") then
  22. modIdentifier = "BuildCraft:"
  23. myString = string.gsub(myString, "BuildCraft|Transport:", "")
  24. if(string.find(myString, "item.buildcraftPipe.")) then
  25. -- Now we need to build a new string to handle pipe naming
  26. --First we remove the item.buildcraftPipe
  27. myString = string.gsub(myString, "item.buildcraftPipe.", "")
  28. --Now we are left with the item in <pipe><type><material> format.
  29. if(string.find(myString, "power")) then
  30. pipeType = " Kenesis " --We specify our type.
  31. pipeMaterial = firstToUpper(string.gsub(myString, "pipepower", "")) --Grab the material
  32. myString = modIdentifier .. " " .. pipeMaterial .. pipeType .. "pipe" --And rebuild our string
  33. return myString --And then return it.
  34. end
  35. end
  36. end
  37. end
  38.  
  39. function addToTable(itemName, itemAmount) -- Adds an item/amount to the current item table.
  40. if itemTable[itemName] == nil then
  41. itemTable[itemName] = itemAmount
  42. else
  43. itemTable[itemName] = itemTable[itemName] + itemAmount
  44. end
  45. end
  46.  
  47. function pairsByKeys (t, f) -- Sorts a table into alphabetical order.
  48. local a = {}
  49. for n in pairs(t) do table.insert(a, n) end
  50. table.sort(a, f)
  51. local i = 0 -- iterator variable
  52. local iter = function () -- iterator function
  53. i = i + 1
  54. if a[i] == nil then return nil
  55. else return a[i], t[a[i]]
  56. end
  57. end
  58. return iter
  59. end
  60.  
  61. function firstToUpper(str) -- Changes the first letter of the input string to uppercase.
  62. return (str:gsub("^%l", string.upper))
  63. end
  64.  
  65. checkCurrentChest()
  66. for key,value in pairsByKeys(itemTable) do
  67. print(key, value)
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement