Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- ThaumComp = {
- }
- ThaumComp_mt = {__index = ThaumComp}
- function ThaumComp:create()--{{{
- local new_ThaumComp = {}
- setmetatable(new_ThaumpComp, ThaumComp_mt)
- return new_ThaumComp
- end--}}}
- function ThaumComp:getJars()--{{{
- self.jars = {}
- -- get ethereal jars
- local peripherals = peripheral.getNames()
- for n, p in pairs(peripherals) do
- local peripheral_type = peripheral.getType(p)
- if peripheral_type == "tilejar" or peripheral_type == "tileetherealjar" or peripheral_type == "tileessentiacontainer" or peripheral_type == "tilejarvoid" then
- table.insert(self.jars, peripheral.wrap(p))
- end
- end
- end--}}}
- function ThaumComp:displayJars()--{{{
- print(#self.jars)
- end--}}}
- function ThaumComp:takeInventory()--{{{
- -- reset inventory
- self.inventory = {}
- -- get jars
- self:getJars()
- -- get aspect of jar and quantity
- for jarnum, jar in pairs(self.jars) do
- jar_contents = jar.getAspects()
- if #jar_contents > 0 then
- -- if there is an aspect in jar
- if not self.inventory[jar_contents[1].name] then
- -- if aspect not in aspect list then set aspect to jar quantity
- self.inventory[jar_contents[1].name] = jar_contents[1].quantity
- else
- -- else add jar quantity to aspect value
- self.inventory[jar_contents[1].name] = self.inventory[jar_contents[1].name] + jar_contents[1].quantity
- end
- end
- end
- end--}}}
- function ThaumComp:displayInventory()--{{{
- term.clear()
- term.setCursorPos(1,1)
- for aspect, quantity in pairs(self.inventory) do
- write(aspect .. ": " .. quantity .. ", ")
- end
- end--}}}
- tc = ThaumComp
- tc.timer = os.startTimer(1)
- while true do
- local event, param1, param2, param3 = os.pullEvent()
- if event == "peripheral" then
- tc:takeInventory()
- elseif event == "timer" then
- tc:takeInventory()
- tc:displayInventory()
- tc.timer = os.startTimer(1)
- elseif event == "key" then
- if param1 == keys.s then
- tc:displayInventory()
- elseif param1 == keys.j then
- tc:getJars()
- elseif param1 == keys.k then
- tc:displayJars()
- elseif param1 == keys.i then
- tc:takeInventory()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement