ItemStackComponentsHelper
com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemStackComponentsHelper
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
get(String id): NBTElementHelper<?>#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; theminecraft:namespace can be omitted
Returns: the encoded value, or
null if absent, unknown, invalid, or not encodablegetArmorTrim
getArmorTrim(): ArmorTrimHelper#Reads the material and pattern of the applied armor trim.
Returns: the trim, or
null if the stack is untrimmedgetAttributeModifiers
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 absentgetBrewingFuel
getBrewingFuel(): BrewingFuelHelper#Reads how this stack fuels a brewing stand, including any speed multiplier. Uses and speed can be fixed values or resolve through data-pack number providers.
Returns: the fuel settings, or
null if the component is absentgetBundleContents
getBundleContents(): BundleContentsHelper#Reads the items, fullness, and selection of a bundle.
Returns: the bundle contents, or
null if the component is absentgetChanges
getChanges(): NBTElementHelper.NBTCompoundHelper#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 encodedgetConsumable
getConsumable(): ConsumableComponentHelper#Reads how this stack is consumed, including its use duration, animation, and configured effects.
Returns: the consumable component, or
null if it is absentgetContainerContents
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 absentgetCookingFuel
getCookingFuel(): CookingFuelHelper#Reads how this stack fuels a furnace, including any speed multiplier. Burn time and speed can be fixed values or resolve through data-pack number providers.
Returns: the fuel settings, or
null if the component is absentgetCustomData
getCustomData(): NBTElementHelper.NBTCompoundHelper#Reads arbitrary NBT attached through the
minecraft:custom_data component.Returns: a copy of the custom data, or
null if the component is absentgetCustomModelData
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 absentgetDamage
getDyedColor
getEquippable
getEquippable(): EquippableComponentHelper#Reads the component that specifies how the stack can be equipped.
Returns: the equippable component, or
null if it is absentgetFireworkExplosion
getFireworkExplosion(): FireworkExplosionHelper#Reads the explosion stored on a firework star.
Returns: the explosion, or
null if the component is absentgetFireworks
getFireworks(): FireworksHelper#Reads a firework rocket's flight duration and explosions.
Returns: the rocket data, or
null if the component is absentgetFood
getFood(): FoodComponentHelper#Reads the nutrition of this stack, including any changes to the item's defaults.
Returns: the food properties, or
null if the component is absentgetIds
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 absentgetMapId
getMaxDamage
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 absentgetStoredEnchantments
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 absentgetTool
getTool(): ToolComponentHelper#Reads this stack's mining rules and durability cost per block.
Returns: the tool component, or
null if it is absentgetUseCooldown
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 absentgetUseRemainder
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 absentgetWritableBookContents
getWritableBookContents(): WritableBookContentsHelper#Reads the plain-text pages stored in a book and quill.
Returns: the writable book contents, or
null if the component is absentgetWrittenBookContents
getWrittenBookContents(): WrittenBookContentsHelper#Reads a signed book's metadata and formatted pages.
Returns: the written book contents, or
null if the component is absent