ItemHelper
com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper
Describes an item type, independently of any particular stack; use ItemStackHelper for stack-specific state. Obtain an item from RegistryHelper.getItem(String).
js
const item = Client.getRegistryManager().getItem("minecraft:diamond_sword");
const stack = item.getDefaultStack();
Chat.log(`${item.getId()}: max stack ${item.getMaxCount()}, current count ${stack.getCount()}`);js
const item = Client.getRegistryManager().getItem("minecraft:diamond_sword");
Chat.log(`${item.getId()} is called ${item.getName()}`);
Chat.log(`stack of ${item.getMaxCount()}, a tool: ${item.isTool()}, a block item: ${item.isBlockItem()}`);
// what it is made of, and what it repairs with
Chat.log(`enchantability ${item.getEnchantability()}, max durability ${item.getMaxDurability()}`);
Chat.log(`repairs with cobblestone: ${item.canBeRepairedWith(
Client.getRegistryManager().getItemStack("minecraft:cobblestone"))}`);
// and a stack of one to work with
const stack = item.getDefaultStack();
Chat.log(`${stack.getCount()} of ${stack.getItemId()}`);Constructors
new ItemHelper
Methods
canBeNested
Whether this item is allowed inside container items such as bundles.
Returns:
true if this item can be nested, i.e. put into a bundle or shulker box, false otherwise.canBeRepairedWith
Whether the given stack can be used to repair stacks of this item at an anvil. The item's own data is the list of materials the game accepts, and the question is whether this stack is one of them. An item with no repairable component returns
false. // what a tool can be repaired with
const reg = Client.getRegistryManager();
const sword = reg.getItem("minecraft:diamond_sword");
for (const id of ["minecraft:cobblestone", "minecraft:iron_ingot", "minecraft:diamond", "minecraft:dirt"]) {
Chat.log(`${id}: ${sword.canBeRepairedWith(reg.getItemStack(id))}`);
}Parameters:
stack: the possible repair material
Returns:
true if the given item stack can be used to repair item stacks of this item, false otherwise.getBlock
Returns the block associated with this block item, or
null if this item is not a block item.Returns: the block representation of this item or
null if this item has no corresponding block.getCreativeTab
Returns the display names of creative tabs containing this item, or an empty list if none.
Returns: the display names of the creative tabs this item is in, empty if it is in none.
getDefaultStack
Returns a fresh default stack of this item, with a count of one.
Returns: the default item stack of this item with a stack size of
1.getEnchantability
Returns this item's enchantability component value, or
0 if it has no such component.Returns: this item's enchantability value, or
0 if absent.getFood
Returns this item's food component, or
null if it has none.Returns: the food component of this item or
null if this item is not food.getGroupIcon
Returns the icon stacks for creative tabs containing this item, in the same order as getCreativeTab().
Returns: the icon stacks for the tabs this item is in, or
null.getId
getMaxCount
Returns this item's default maximum stack size; items without a configured size default to
1.Returns: the maximum amount of items in a stack of this item.
getMaxDurability
Returns this item's maximum damage value, or
0 if no maximum is configured.Returns: the maximum damage value.
getMiningSpeedMultiplier
Returns this item's mining-speed multiplier for the given block state. Without tool data, the multiplier is
1.Parameters:
state: the block state to check
Returns: the mining-speed multiplier;
1 when this item has no tool data.getName
Returns this item's name as a string in the current language. For a stack's custom name, see ItemStackHelper.getName().
Returns: the name of this item, translated to the current language.
getRecipeRemainder
Returns this item's crafting remainder, or
null if it has none.Returns: the remainder as a one-count item stack, or
null if none exists.getStackWithNbt
Parses
nbt as the component syntax appended to this item's ID and returns a stack with those components. The stack count is always one. // a named and damaged tool
const sword = Client.getRegistryManager().getItem("minecraft:diamond_sword");
const named = sword.getStackWithNbt('[custom_name='"Excalibur"', damage=10]');
Chat.log(`${named.getName()} with ${named.getDurability()} durability left`);
// an enchanted one
const enchanted = sword.getStackWithNbt('[{id:"minecraft:sharpness",lvl:5}]');
const found = enchanted.getEnchantment("minecraft:sharpness");
Chat.log(found === null ? "no sharpness" : found.getRomanLevelName());
// a text that will not parse is an error rather than an empty stack
try {
sword.getStackWithNbt("[not_a_component]");
} catch (e) {
Chat.log("that component list did not parse");
}Parameters:
nbt: the component syntax to append to this item's ID.
Returns: a stack with the parsed components and a count of one.
hasRecipeRemainder
Whether this item has a crafting remainder.
Returns:
true if this item has a crafting remainder; false otherwise.isBlockItem
Whether this item is a block item; see getBlock() for its associated block.
Returns:
true if the item has a block representation, false otherwise.isDamageable
Whether this item's default stack is damageable.
Returns:
true if the item has durability, false otherwise.isFireproof
Whether this item's damage-resistance component targets the fire damage-type tag. Items with no damage-resistance component return
false.Returns:
true if fire damage is resisted according to the component; false otherwise.isFood
Whether this item has a food component.
Returns:
true if this item is food, false otherwise.isSuitableFor
Checks whether this item is a correct tool for drops against the block's default state.
Parameters:
block: the block to check
Returns:
true if this item is a correct tool for drops for the default state; false otherwise.Checks whether this item is a correct tool for drops against this specific block state.
Parameters:
block: the block to check
Returns:
true if this item is a correct tool for drops for this state; false otherwise.isTool
Whether this item has a tool component.
Returns:
true if this item is a tool, false otherwise.isWearable
Whether this item has an equippable component.
Returns:
true if this item has an equippable component; false otherwise.