Skip to content

CreativeItemStackHelper ​

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

Since1.8.4

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 ​

new CreativeItemStackHelper(ItemStack itemStack)#
Wraps the supplied stack for component editing; the helper retains the same stack reference.

Parameters:

  • itemStack: the stack to wrap and edit

Methods ​

addEnchantment ​

addEnchantment(String id, int level): CreativeItemStackHelperSince1.8.4#
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 enchantment
  • level: the level of the enchantment
Returns: self for chaining.
addEnchantment(EnchantmentHelper enchantment): CreativeItemStackHelperSince1.8.4#
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 ​

addLore(Object... lore): CreativeItemStackHelperSince1.8.4#
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 ​

clearEnchantments(): CreativeItemStackHelperSince1.8.4#
Replaces this stack's enchantments component with the empty component.
Returns: self for chaining.

clearLore ​

clearLore(): CreativeItemStackHelperSince1.8.4#
Sets this stack's lore to an empty list.
Returns: self for chaining.

hideCanDestroy ​

hideCanDestroy(boolean hide): CreativeItemStackHelperSince1.8.4#
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 ​

hideCanPlace(boolean hide): CreativeItemStackHelperSince1.8.4#
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 ​

hideDye(boolean hide): CreativeItemStackHelperSince1.8.4#
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 ​

hideEnchantments(boolean hide): CreativeItemStackHelperSince1.8.4#
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 ​

hideModifiers(boolean hide): CreativeItemStackHelperSince1.8.4#
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 ​

hideUnbreakable(boolean hide): CreativeItemStackHelperSince1.8.4#
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 ​

removeEnchantment(EnchantmentHelper enchantment): CreativeItemStackHelperSince1.8.4#
Removes all levels of the enchantment identified by the helper, preserving other enchantments.

Parameters:

  • enchantment: the enchantment to remove
Returns: self for chaining.
removeEnchantment(String id): CreativeItemStackHelperSince1.8.4#
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 ​

setCount(int count): CreativeItemStackHelperSince1.8.4#
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 ​

setDamage(int damage): CreativeItemStackHelperSince1.8.4#
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 ​

setDurability(int durability): CreativeItemStackHelperSince1.8.4#
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 ​

setLore(Object... lore): CreativeItemStackHelperSince1.8.4#
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 ​

setName(String name): CreativeItemStackHelperSince1.8.4#
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.
setName(TextHelper name): CreativeItemStackHelperSince1.8.4#
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 ​

setUnbreakable(boolean unbreakable): CreativeItemStackHelperSince1.8.4#
Sets or removes the unbreakable component on this stack.

Parameters:

  • unbreakable: whether the item should be unbreakable or not
Returns: self for chaining.