Skip to content

ItemStackComponentsHelper ​

com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemStackComponentsHelper

Since2.3.0

Reads the current components of an item stack. Typed getters and ID lookup include the item's defaults, with any changes or removals made to this stack. Use getIds() and get(String) to read components that have no typed getter, and ItemHelper.getStackWithNbt(String) to build a new stack from the same component syntax.
Use getChanges() to read only the saved changes. This view follows the stack passed to it; it does not follow a slot when the slot gets a different stack.

js
const components = Player.getPlayer()?.getMainHand().getComponents();  
if (components != null) {
 const maxDamage = components.getMaxDamage();  
 if (maxDamage !== null) Chat.log(`Maximum damage: ${maxDamage}`);  
 const effects = components.getPotionContents()?.getEffects();  
 if (effects != null) {
   for (const effect of effects) Chat.log(effect.getId());  
 }
}

Methods ​

get ​

Reads one component as a detached NBT tag. Prefer a typed getter when one is available. Use has(String) to distinguish a missing component from one that cannot be encoded. Without a connection, only built-in registries are available for encoding.

Parameters:

  • id: component ID; the minecraft: namespace can be omitted
Returns: the encoded value, or null if absent, unknown, invalid, or not encodable

getArmorTrim ​

getArmorTrim(): ArmorTrimHelper#
Reads the material and pattern of the applied armor trim.
Returns: the trim, or null if the stack is untrimmed

getAttributeModifiers ​

getAttributeModifiers(): List<ItemAttributeModifierHelper>#
Lists the stack's configured attribute modifiers and the equipment slots they apply to.
Returns: the modifier entries, or null if the component is absent

getBundleContents ​

getBundleContents(): BundleContentsHelper#
Reads the items, fullness, and selection of a bundle.
Returns: the bundle contents, or null if the component is absent

getChanges ​

Reads the stack's saved changes as a detached NBT compound. Added and replaced values use their component IDs as keys. Removals have keys such as "!minecraft:damage". Components that Minecraft does not save are omitted.
Returns: the saved changes, an empty compound when there are none, or null if a saved change cannot be encoded

getConsumable ​

Reads how this stack is consumed, including its use duration, animation, and configured effects.
Returns: the consumable component, or null if it is absent

getContainerContents ​

getContainerContents(): List<ItemStackHelper>#
Reads items stored in a stack such as a shulker box. List indices are zero-based slots; gaps appear as empty stacks, and trailing empty slots may be omitted.
Returns: copies in slot order, or null if the component is absent

getCustomData ​

Reads arbitrary NBT attached through the minecraft:custom_data component.
Returns: a copy of the custom data, or null if the component is absent

getCustomModelData ​

getCustomModelData(): CustomModelDataHelper#
Reads custom model data that resource packs can use to change the item's appearance.
Returns: the custom model data, or null if the component is absent

getDamage ​

getDamage(): Integer#
Reads the damage component before Minecraft clamps it to the stack's maximum damage.
Returns: damage taken, or null if the component is absent

getDyedColor ​

getDyedColor(): Integer#
Reads the dye color applied to a stack, for example dyed leather armor.
Returns: the 24-bit RGB color, or null if the component is absent

getEquippable ​

Reads the component that specifies how the stack can be equipped.
Returns: the equippable component, or null if it is absent

getFireworkExplosion ​

getFireworkExplosion(): FireworkExplosionHelper#
Reads the explosion stored on a firework star.
Returns: the explosion, or null if the component is absent

getFireworks ​

getFireworks(): FireworksHelper#
Reads a firework rocket's flight duration and explosions.
Returns: the rocket data, or null if the component is absent

getFood ​

Reads the nutrition of this stack, including any changes to the item's defaults.
Returns: the food properties, or null if the component is absent

getIds ​

getIds(): List<String>#
Lists the components present on this stack.
Returns: registered component IDs in sorted order

getLodestoneTracker ​

getLodestoneTracker(): LodestoneTrackerHelper#
Reads the lodestone tracker stored on the stack, such as a compass linked to a lodestone. A tracker can be present even after Minecraft has cleared its target.
Returns: the tracker, or null if the component is absent

getMapId ​

getMapId(): Integer#
Reads the numeric ID that identifies a filled map's saved data.
Returns: the map ID, which can be zero, or null if the stack has no map ID

getMaxDamage ​

getMaxDamage(): Integer#
Reads the stack's maximum damage, including a value inherited from the item.
Returns: maximum damage, or null if the component is absent

getPotionContents ​

getPotionContents(): PotionContentsHelper#
Reads the potion data stored on a stack, such as a potion or tipped arrow.
Returns: the potion contents, or null if the component is absent

getStoredEnchantments ​

getStoredEnchantments(): List<EnchantmentHelper>#
Reads enchantments stored for transfer to another item, such as those in an enchanted book. Use ItemStackHelper.getEnchantments() for enchantments applied to the stack itself.
Returns: the stored enchantments with levels, or null if the component is absent

getTool ​

Reads this stack's mining rules and durability cost per block.
Returns: the tool component, or null if it is absent

getUseCooldown ​

getUseCooldown(): UseCooldownHelper#
Reads the cooldown the item is configured to start on use. For the player's current cooldown progress, use ItemStackHelper.getCooldownProgress().
Returns: the cooldown settings, or null if the component is absent

getUseRemainder ​

getUseRemainder(): ItemStackHelper#
Reads the configured remainder after item use, such as the glass bottle left by a potion.
Returns: a copy of the remainder stack, or null if the component is absent

getWritableBookContents ​

getWritableBookContents(): WritableBookContentsHelper#
Reads the plain-text pages stored in a book and quill.
Returns: the writable book contents, or null if the component is absent

getWrittenBookContents ​

getWrittenBookContents(): WrittenBookContentsHelper#
Reads a signed book's metadata and formatted pages.
Returns: the written book contents, or null if the component is absent

has ​

has(String id): boolean#
Checks whether a component is present, even if it does not have an NBT representation.

Parameters:

  • id: component ID; the minecraft: namespace can be omitted
Returns: whether the component is present; false for unknown or invalid IDs