Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local sides = require("sides")
- itemTable = {}
- function checkCurrentChest()
- slot = 1
- while component.inventory_controller.getStackInSlot(sides.down, slot) ~= nil do
- itemInfo = component.inventory_controller.getStackInSlot(sides.down, slot)
- print(parseString(itemInfo.name) .. " " .. itemInfo.size)
- addToTable(parseString(itemInfo.name), itemInfo.size)
- slot = slot + 1
- end
- end
- function parseString(myString) --Formats our item correctly.
- if string.find(myString, "minecraft:") then
- myString = string.gsub(myString, "minecraft:", "")
- return myString
- end
- if string.find(myString, "BuildCraft|Transport:") then
- modIdentifier = "BuildCraft:"
- myString = string.gsub(myString, "BuildCraft|Transport:", "")
- if(string.find(myString, "item.buildcraftPipe.")) then
- -- Now we need to build a new string to handle pipe naming
- --First we remove the item.buildcraftPipe
- myString = string.gsub(myString, "item.buildcraftPipe.", "")
- --Now we are left with the item in <pipe><type><material> format.
- if(string.find(myString, "power")) then
- pipeType = " Kenesis " --We specify our type.
- pipeMaterial = firstToUpper(string.gsub(myString, "pipepower", "")) --Grab the material
- myString = modIdentifier .. " " .. pipeMaterial .. pipeType .. "pipe" --And rebuild our string
- return myString --And then return it.
- end
- end
- end
- end
- function addToTable(itemName, itemAmount) -- Adds an item/amount to the current item table.
- if itemTable[itemName] == nil then
- itemTable[itemName] = itemAmount
- else
- itemTable[itemName] = itemTable[itemName] + itemAmount
- end
- end
- function pairsByKeys (t, f) -- Sorts a table into alphabetical order.
- local a = {}
- for n in pairs(t) do table.insert(a, n) end
- table.sort(a, f)
- local i = 0 -- iterator variable
- local iter = function () -- iterator function
- i = i + 1
- if a[i] == nil then return nil
- else return a[i], t[a[i]]
- end
- end
- return iter
- end
- function firstToUpper(str) -- Changes the first letter of the input string to uppercase.
- return (str:gsub("^%l", string.upper))
- end
- checkCurrentChest()
- for key,value in pairsByKeys(itemTable) do
- print(key, value)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement