LibItemInfo
What is it for?
I wrote this library to use with my JunkIt Addon. When I added the ability to auto-loot items based on junk filters I found the need to be able to handle items by both (BagId, SlotId) and by Links. At the time a lot of the newer GetItemLink functions weren't available. So I wrote a library to handle gathering that information, and for other common tasks, whether I passed in a (bagId, SlotId) or a (link).

Scroll down for available functions

Instructions
To use it install the library folder into libs folder (your library folder or wherever)
Lua Code:
  1. -- <Your Addon Folder> --> <libs> --> <LibItemInfo-1.0>
  2. -- <Your Addon> --> <libs> --> <LibStub>
  3.  
  4. -- In your Addon.txt file Add a reference to the LibStub.lua file:
  5. libs\LibStub\LibStub.lua
  6.  
  7. -- Then Add a reference to the LibItemInfo-1.0.lua file:
  8. libs\LibItemInfo-1.0\LibItemInfo-1.0.lua

Then to use it in any of your code files, at the top of the file include the line:
Note: this must be done in each code file you wish to use the library in.
Lua Code:
  1. local LII = LibStub:GetLibrary("LibItemInfo-1.0")

The library can then be used to gather information with (BagId, SlotId) or a (link). For example each function can be called by either:
Lua Code:
  1. local LII = LibStub:GetLibrary("LibItemInfo-1.0")
  2.  
  3. LII:HasKnownTrait(iBagId, iSlotId)
  4. -- or
  5. LII:HasKnownTrait(lLink)

Available Functions

General Functions
Lua Code:
  1. ------------------------------------------------------------------------
  2. --  General Functions  --
  3. ------------------------------------------------------------------------
  4. -- Returns an unformatted link of the item
  5. function lii:GetItemLink(_BagIdOrLink, _iSlotId)
  6.  
  7. -- Returns a zo_strformat(..)'d Link --
  8. function lii:GetFormattedItemLink(_BagIdOrLink, _iSlotId)
  9.  
  10. -- Returns the zo_strformat(..)'d ToolTipName of the item
  11. function lii:GetItemToolTipName(_BagIdOrLink, _iSlotId)
  12.  
  13. -- Same returns as the built in GetItemInfo
  14. -- sIcon, iStack, iSellPrice, bMeetsUsageRequirement, bLocked, iEquipType, iItemStyle, iItemQuality
  15. -- Links do not have stack sizes or a locked property
  16. -- If you pass in a link iStack & bLocked will return nil
  17. function lii:GetItemInfo(_BagIdOrLink, _iSlotId)

Item SubType
Lua Code:
  1. ------------------------------------------------------------------------
  2. --  Item SubType (ArmorType/WeaponType) Info  --
  3. ------------------------------------------------------------------------
  4. -- Returns the appropriate ArmorType, WeaponType,
  5. -- or 0 if not a piece of Armor or Weapon
  6. -- 0 is the same value as WEAPONTYPE_NONE & ARMORTYPE_NONE
  7. function lii:GetSubType(_BagIdOrLink, _iSlotId)

Item Properties
Lua Code:
  1. ------------------------------------------------------------------------
  2. --  ItemType Group Properties  --
  3. ------------------------------------------------------------------------
  4. -- Returns: true/false if the item is jewelry
  5. function lii:IsJewelry(_BagIdOrLink, _iSlotId)
  6.  
  7. -- Returns: true/false if the item is a one handed weapon
  8. function lii:IsWeaponOneHanded(_BagIdOrLink, _iSlotId)
  9.  
  10. -- Returns: true/false if the item is a two handed weapon
  11. function lii:IsWeaponTwoHanded(_BagIdOrLink, _iSlotId)
  12.  
  13. -- Returns: true/false if the item is a crafting mat
  14. -- NOTE: This include Glyphs. Does not include Style material or trait stones.
  15. function lii:IsCrafingMaterial(_BagIdOrLink, _iSlotId)
  16.  
  17. -- Returns: true/false if the item is a glyph
  18. function lii:IsGlyph(_BagIdOrLink, _iSlotId)

Crafting Info
Lua Code:
  1. ------------------------------------------------------------------------
  2. --  Crafting Info Functions --
  3. ------------------------------------------------------------------------
  4. -- Pass in a CraftingSkill Type and it Returns a zo_strFormat(..)'d name for the CraftingSkillType in the games current language or CRAFTING_TYPE_INVALID
  5. -- In English it returns:
  6. -- CRAFTING_TYPE_ALCHEMY returns "Alchemy"
  7. -- CRAFTING_TYPE_BLACKSMITHING returns "Blacksmithing"
  8. -- CRAFTING_TYPE_CLOTHIER returns "Clothing"
  9. -- CRAFTING_TYPE_ENCHANTING returns "Enchanting"
  10. -- CRAFTING_TYPE_INVALID returns CRAFTING_TYPE_INVALID (NOT a formatted string, it returns 0)
  11. -- CRAFTING_TYPE_PROVISIONING returns "Provisioning"
  12. -- CRAFTING_TYPE_WOODWORKING  returns "Woodworking"
  13. function lii:GetCraftingSkillTypeLabelName(_iCraftingSkillType)
  14.  
  15. -- Possible Returns: CRAFTING_TYPE_CLOTHIER, CRAFTING_TYPE_BLACKSMITHING, CRAFTING_TYPE_WOODWORKING, or CRAFTING_TYPE_INVALID
  16. -- Returns: the CraftingSkillType of an item IF it is a researchable ItemType
  17. -- Returns: CRAFTING_TYPE_INVALID if it is not a researchable ItemType
  18. function lii:GetResearchableCraftingSkillType(_BagIdOrLink, _iSlotId)

Research Specific
Lua Code:
  1. ------------------------------------------------------------------------
  2. --  Research Specific Functions --
  3. ------------------------------------------------------------------------
  4. -- Returns: bool IsResearchableItem, integer CraftingSkillType, Integer ResearchLineIndex, integer TraitIndex
  5. --
  6. -- IsResearchableItem: Returns: True if itemType is researchable AND has a researchable trait on it, But that does not mean it is an unknown trait --
  7. -- CraftingSkillType: Returns the CraftingSkillType of an item IF it is a researchable ItemType or CRAFTING_TYPE_INVALID (item does not have to have a trait on it to return a CraftingSkillType)
  8. -- GetResearchLineIndex: Returns the ResearchLineIndex for an item if it is a researchable ItemType Or returns CRAFTING_TYPE_INVALID (item does not have to have a trait on it to return a ResearchLineIndex) --
  9. -- TraitIndex: Returns the TraitIndex of the trait on the item or CRAFTING_TYPE_INVALID (Armor/Weapon Trait Stones will return a TraitIndex)
  10. function lii:GetResearchInfo(_BagIdOrLink, _iSlotId)
  11.  
  12. -- Returns: True if the ItemType is Armor or Weapon and the subtype is not WEAPONTYPE_RUNE and not xxx_NONE --
  13. function lii:IsResearchableItemType(_BagIdOrLink, _iSlotId)
  14.  
  15. -- Returns: True if itemType is researchable AND has a researchable trait on it --
  16. -- That does not mean it is an unknown trait --
  17. -- Make sure you note the distinction between this & HasResearchableTrait, they are not the same --
  18. -- (Armor/Weapon Trait Stones will return false)
  19. function lii:IsResearchableItem(_BagIdOrLink, _iSlotId)
  20.  
  21. -- Returns: True or False
  22. -- True if the item is a researchable ItemType, it has a researchable trait
  23. --   on it that is unknown, and that trait is not currently being researched
  24. function lii:NeedForResearch(_BagIdOrLink, _iSlotId)
  25.  
  26. -- Possible Returns: The Items ResearchLine Index or CRAFTING_TYPE_INVALID
  27. -- Returns: The ResearchLineIndex for an item if it is a researchable ItemType
  28. --      This does not mean it has a trait on it.
  29. -- Returns: CRAFTING_TYPE_INVALID if the item is not a Researchable ItemType
  30. function lii:GetResearchLineIndex(_BagIdOrLink, _iSlotId)

Trait Specific
Lua Code:
  1. ------------------------------------------------------------------------
  2. --  Item Trait Specific Functions --
  3. ------------------------------------------------------------------------
  4. -- Returns: the TraitIndex of the trait on an item or CRAFTING_TYPE_INVALID
  5. -- Does not mean the ItemType is researchable (Armor/Weapon Trait Stones will return a TraitIndex)
  6. function lii:GetTraitIndex(_BagIdOrLink, _iSlotId)
  7.  
  8. -- Returns true if the itemType is researchable and has a known researchable trait
  9. function lii:HasKnownTrait(_BagIdOrLink, _iSlotId)
  10.  
  11. -- Returns true/false if the itemType is researchable and has an unknown researchable trait
  12. function lii:HasUnKnownTrait(_BagIdOrLink, _iSlotId)
  13.  
  14. -- Returns true/false if the item has a researchable trait
  15. --      This does not mean the trait is unknown to you or that it is
  16. -- a researchable ItemType only that it is one of the researchable
  17. -- TraitTypes (Armor/Weapon Trait Stones will return true)
  18. -- Make sure you note the distinction between this & IsResearchableItem, they are not the same --
  19. function lii:HasResearchableTrait(_BagIdOrLink, _iSlotId)
  20.  
  21. -- If the TraitType on the item is currently being researched
  22. --      Returns: True, TotalResearchTime, timeLeftInSeconds
  23. -- If the TraitType on the item is not currently being researched
  24. --      Returns: False, nil, nil
  25. function lii:IsItemTraitBeingResearched(_BagIdOrLink, _iSlotId)

Recipe
Lua Code:
  1. ------------------------------------------------------------------------
  2. --  Recipe Functions  --
  3. ------------------------------------------------------------------------
  4. -- If the recipe is know it returns:
  5. -- Returns: bool IsKnownRecipe, string (ToolTipFormatted)RecipeName, integer RecipeListIndex, integer RecipeIndex
  6. -- If the recipe is unknown it returns:
  7. -- Returns: false, nil, nil, nil
  8. function lii:GetRecipeInfo(_BagIdOrLink, _iSlotId)