Advertisement
demon012

Minecraft - Thaumcraft - Essentia Inventory

Mar 3rd, 2015
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. args = {...}
  2. ThaumComp = {
  3. }
  4. ThaumComp_mt = {__index = ThaumComp}
  5.  
  6. function ThaumComp:create()--{{{
  7.     local new_ThaumComp = {}
  8.     setmetatable(new_ThaumpComp, ThaumComp_mt)
  9.     return new_ThaumComp
  10. end--}}}
  11. function ThaumComp:getJars()--{{{
  12.     self.jars = {}
  13.  
  14.     -- get ethereal jars
  15.     local peripherals = peripheral.getNames()
  16.     for n, p in pairs(peripherals) do
  17.         local peripheral_type = peripheral.getType(p)
  18.         if peripheral_type == "tilejar" or peripheral_type == "tileetherealjar" or peripheral_type == "tileessentiacontainer" or peripheral_type == "tilejarvoid" then
  19.             table.insert(self.jars, peripheral.wrap(p))
  20.         end
  21.     end
  22. end--}}}
  23. function ThaumComp:displayJars()--{{{
  24.     print(#self.jars)
  25. end--}}}
  26.  
  27. function ThaumComp:takeInventory()--{{{
  28.     -- reset inventory
  29.     self.inventory = {}
  30.  
  31.     -- get jars
  32.     self:getJars()
  33.  
  34.     -- get aspect of jar and quantity
  35.     for jarnum, jar in pairs(self.jars) do
  36.         jar_contents = jar.getAspects()
  37.         if #jar_contents > 0 then
  38.             -- if there is an aspect in jar
  39.             if not self.inventory[jar_contents[1].name] then
  40.                 -- if aspect not in aspect list then set aspect to jar quantity
  41.                 self.inventory[jar_contents[1].name] = jar_contents[1].quantity
  42.             else
  43.                 -- else add jar quantity to aspect value
  44.                 self.inventory[jar_contents[1].name] = self.inventory[jar_contents[1].name] + jar_contents[1].quantity
  45.             end
  46.         end
  47.     end
  48. end--}}}
  49. function ThaumComp:displayInventory()--{{{
  50.     term.clear()
  51.     term.setCursorPos(1,1)
  52.     for aspect, quantity in pairs(self.inventory) do
  53.         write(aspect .. ": " .. quantity .. ", ")
  54.     end
  55. end--}}}
  56.  
  57. tc = ThaumComp
  58. tc.timer = os.startTimer(1)
  59.  
  60. while true do
  61.     local event, param1, param2, param3 = os.pullEvent()
  62.     if event == "peripheral" then
  63.         tc:takeInventory()
  64.     elseif event == "timer" then
  65.         tc:takeInventory()
  66.         tc:displayInventory()
  67.         tc.timer = os.startTimer(1)
  68.     elseif event == "key" then
  69.         if param1 == keys.s then
  70.             tc:displayInventory()
  71.         elseif param1 == keys.j then
  72.             tc:getJars()
  73.         elseif param1 == keys.k then
  74.             tc:displayJars()
  75.         elseif param1 == keys.i then
  76.             tc:takeInventory()
  77.         end
  78.     end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement