# ItemHelper

`com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper`

**Since:** 1.8.4

Describes an item type, independently of any particular stack; use [ItemStackHelper](ItemStackHelper.md) for
stack-specific state. Obtain an item from
[RegistryHelper.getItem(String)](../../classes/RegistryHelper.md#com.jsmacrosce.jsmacros.client.api.classes.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 {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_constructor-Item-}

```js
new ItemHelper(Item base)
```

Wraps the supplied raw item type.

**Parameters:**
- `base`: raw item type to wrap

## Methods

### canBeNested {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_canBeNested-}

```js
canBeNested(): boolean
```

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.

**Since:** 1.8.4

### canBeRepairedWith {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_canBeRepairedWith-ItemStackHelper-}

```js
canBeRepairedWith(ItemStackHelper stack): boolean
```

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`.  
```js
// 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.

**Since:** 1.8.4

### getBlock {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getBlock-}

```js
getBlock(): BlockHelper
```

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.

**Since:** 1.8.4

### getCreativeTab {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getCreativeTab-}

```js
getCreativeTab(): List<TextHelper>
```

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.

**Since:** 1.8.4

### getDefaultStack {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getDefaultStack-}

```js
getDefaultStack(): ItemStackHelper
```

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`.

**Since:** 1.8.4

### getEnchantability {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getEnchantability-}

```js
getEnchantability(): int
```

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.

**Since:** 1.8.4

### getFood {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getFood-}

```js
getFood(): FoodComponentHelper
```

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.

**Since:** 1.8.4

### getGroupIcon {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getGroupIcon-}

```js
getGroupIcon(): List<ItemStackHelper>
```

Returns the icon stacks for creative tabs containing this item, in the same order as
[getCreativeTab()](#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getCreativeTab-).

**Returns:** the icon stacks for the tabs this item is in, or `null`.

**Since:** 1.8.4

### getId {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getId-}

```js
getId(): String
```

Returns this item's full registry identifier.

**Returns:** the identifier of this item.

**Since:** 1.8.4

### getMaxCount {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getMaxCount-}

```js
getMaxCount(): int
```

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.

**Since:** 1.8.4

### getMaxDurability {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getMaxDurability-}

```js
getMaxDurability(): int
```

Returns this item's maximum damage value, or `0` if no maximum is configured.

**Returns:** the maximum damage value.

**Since:** 1.8.4

### getMiningSpeedMultiplier {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getMiningSpeedMultiplier-BlockStateHelper-}

```js
getMiningSpeedMultiplier(BlockStateHelper state): float
```

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.

**Since:** 1.8.4

### getName {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getName-}

```js
getName(): String
```

Returns this item's name as a string in the current language. For a stack's custom name, see
[ItemStackHelper.getName()](ItemStackHelper.md#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemStackHelper_getName-).

**Returns:** the name of this item, translated to the current language.

**Since:** 1.8.4

### getRecipeRemainder {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getRecipeRemainder-}

```js
getRecipeRemainder(): ItemStackHelper
```

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.

**Since:** 1.8.4

### getStackWithNbt {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getStackWithNbt-String-}

```js
getStackWithNbt(String nbt): ItemStackHelper
```

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. To read components from an existing stack
instead of building one, use [ItemStackHelper.getComponents()](ItemStackHelper.md#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemStackHelper_getComponents-).  
```js
// 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.

**Since:** 1.8.4

### hasRecipeRemainder {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_hasRecipeRemainder-}

```js
hasRecipeRemainder(): boolean
```

Whether this item has a crafting remainder.

**Returns:** `true` if this item has a crafting remainder; `false` otherwise.

**Since:** 1.8.4

### isBlockItem {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_isBlockItem-}

```js
isBlockItem(): boolean
```

Whether this item is a block item; see [getBlock()](#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_getBlock-) for its associated block.

**Returns:** `true` if the item has a block representation, `false` otherwise.

**Since:** 1.8.4

### isDamageable {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_isDamageable-}

```js
isDamageable(): boolean
```

Whether this item's default stack is damageable.

**Returns:** `true` if the item has durability, `false` otherwise.

**Since:** 1.8.4

### isFireproof {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_isFireproof-}

```js
isFireproof(): boolean
```

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.

**Since:** 1.8.4

### isFood {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_isFood-}

```js
isFood(): boolean
```

Whether this item has a food component.

**Returns:** `true` if this item is food, `false` otherwise.

**Since:** 1.8.4

### isSuitableFor {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_isSuitableFor-BlockHelper-}

```js
isSuitableFor(BlockHelper block): boolean
```

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.

**Since:** 1.8.4

### isSuitableFor {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_isSuitableFor-BlockStateHelper-}

```js
isSuitableFor(BlockStateHelper block): boolean
```

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.

**Since:** 1.8.4

### isTool {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_isTool-}

```js
isTool(): boolean
```

Whether this item has a tool component.

**Returns:** `true` if this item is a tool, `false` otherwise.

**Since:** 1.8.4

### isWearable {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_isWearable-}

```js
isWearable(): boolean
```

Whether this item has an equippable component.

**Returns:** `true` if this item has an equippable component; `false` otherwise.

**Since:** 1.8.4

### toString {#com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemHelper_toString-}

```js
toString(): String
```

Returns a diagnostic representation containing the wrapped item's identifier.

**Returns:** diagnostic representation of the wrapped item type
