CreativeItemStackHelper
com.jsmacrosce.jsmacros.client.api.helper.inventory.CreativeItemStackHelper
Wraps an ItemStackHelper stack with methods for changing its components. It holds the same stack, not a copy; setters mutate it and return this helper for chaining.
js
// build a named, enchanted, glowing tool
const stack = Client.getRegistryManager().getItemStack("minecraft:diamond_sword")
.getCreative()
.setName("Excalibur")
.addEnchantment("minecraft:sharpness", 5)
.addEnchantment("minecraft:unbreaking", 3)
.setDurability(1200)
.hideEnchantments(false);
Chat.log(`${stack.getName()} at ${stack.getDurability()} durability`);
for (const ench of stack.getEnchantments()) {
Chat.log(` ${ench.getRomanLevelName()}`);
}
// the helper and original refer to the same stack
Chat.log(`${stack.getCount()} of ${stack.getItemId()}`);Constructors
new CreativeItemStackHelper
Methods
addEnchantment
Upgrades or adds the identified enchantment at the requested level. The id may omit its namespace; the enchantment component handles level replacement and compatibility.
Parameters:
id: the id of the enchantmentlevel: the level of the enchantment
Returns: self for chaining.
Adds or upgrades the enchantment using the level carried by the helper. Registry-only helpers have no level; use the id-and-level overload when specifying one.
Parameters:
enchantment: the enchantment to add
Returns: self for chaining.
addLore
Appends lore lines. A TextHelper retains its styling, a TextBuilder is built first, and other values are converted to literal text using
toString.Parameters:
lore: the lore to add
Returns: self for chaining.
clearEnchantments
Replaces this stack's enchantments component with the empty component.
Returns: self for chaining.
clearLore
Sets this stack's lore to an empty list.
Returns: self for chaining.
hideCanDestroy
Hides or shows this stack's can-destroy component in its tooltip without changing the restriction itself.
Parameters:
hide: whether to hide the restriction in the tooltip
Returns: self for chaining.
hideCanPlace
Hides or shows this stack's can-place-on component in its tooltip without changing the restriction itself.
Parameters:
hide: whether to hide the restriction in the tooltip
Returns: self for chaining.
hideDye
Hides or shows this stack's dyed-color component in its tooltip without changing its color.
Parameters:
hide: whether to hide the dyed color in the tooltip
Returns: self for chaining.
hideEnchantments
Hides or shows the enchantment component in the stack's tooltip; this does not remove its enchantments.
Parameters:
hide: whether to hide the enchantments or not
Returns: self for chaining.
hideModifiers
Hides or shows the stack's attribute modifiers in its tooltip.
Parameters:
hide: whether to hide attributes and modifiers or not
Returns: self for chaining.
hideUnbreakable
Hides or shows the unbreakable component in the tooltip without changing whether the stack is unbreakable.
Parameters:
hide: whether to hide the unbreakable flag or not
Returns: self for chaining.
removeEnchantment
Removes all levels of the enchantment identified by the helper, preserving other enchantments.
Parameters:
enchantment: the enchantment to remove
Returns: self for chaining.
Removes all levels of the enchantment with this identifier, preserving other enchantments. The identifier must include its namespace.
Parameters:
id: the id of the enchantment to remove
Returns: self for chaining.
setCount
Sets the stack count without clamping it to the item's maximum stack size.
Parameters:
count: the new count of the item
Returns: self for chaining.
setDamage
Sets the damage value on this stack. Damage counts up; use setDurability(int) to specify the remaining durability instead.
Parameters:
damage: the damage the item should take
Returns: self for chaining.
setDurability
Sets remaining durability by storing the item's maximum damage minus this value.
Parameters:
durability: the new durability of this item
Returns: self for chaining.
setLore
Replaces this stack's lore with the supplied lines. Each argument is a line. A TextHelper is taken as text with whatever styling it carries, a TextBuilder is built and taken that way, and anything else is turned into literal text through its own
toString.Parameters:
lore: the new lore
Returns: self for chaining.
setName
Sets this stack's custom name to literal text; the item type's name is unchanged.
Parameters:
name: the new name of the item
Returns: self for chaining.
Sets this stack's custom name to the supplied text, including its styling.
Parameters:
name: the new name of the item
Returns: self for chaining.
setUnbreakable
Sets or removes the unbreakable component on this stack.
Parameters:
unbreakable: whether the item should be unbreakable or not
Returns: self for chaining.