> For the complete documentation index, see [llms.txt](https://thisistails.gitbook.io/tailslib/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thisistails.gitbook.io/tailslib/tailslib-rus/custom-items/item-methods.md).

# Item Methods

## String id() \[required]

ID of item.

## CustomItemBuilder createBuilder() \[required]

Item creation process.

### Example

```java
@Override
public CustomItemBuilder createBuilder() {
    return new CustomItemBuilder(Material.DIAMOND)
        .name("Test Item")
        .loreString(List.of("&7Some lore"));
}
```

## void improveItem(ItemStack)

To modify item meta and etc.

## void itemReady(CustomItemRuntime)

Event called when item is ready to use.

Called sometimes in-game to be sure that item will not break anything so don't put big logic in it. Also good event to put your NBTStates

### Example

```java
public final NBTState<Integer> randomNumberState = new NBTState<>(
    "randomNumber",
    PersistentDataType.INTEGER
);

@Override
public void itemReady(CustomItemRuntime runtime) {
    Random random = new Random();
    if (randomNumberState.get(runtime) == null)
        randomNumberState.set(runtime, random.nextInt(0, 1000));
}
```

## Left and right clicks

CustomItem clicks have built-in cooldown of 1 tick (or 50ms) to fix double clicks for main hand.

### Methods

Both left and right clicks can be handled with:

```java
// Right click
public void rightClick(CustomItemRuntime item, PlayerInteractEvent event)
// Left click
public default void leftClick(CustomItemRuntime item, PlayerInteractEvent event)

// Right click event
// Fired when player clicks on entity with CustomItem in main hand
public void rightClickOnEntity(CustomItemRuntime item, PlayerInteractEntityEvent event)
```

## Item owner dealt and taken damage

CustomItem allow you to handle when item owner dealing damage to entity and taking damager from entity.

### Methods

```java
// When this item dealing damage to another entity.
public void damageDealt(CustomItemRuntime item, EntityDamageByEntityEvent event)

// When owner of this item taking damage from entity
public void damageTaken(CustomItemRuntime item, EntityDamageByEntityEvent event)
```

## Item select and item switching hand event

CustomItem allow you handle when item is selected and deselected:

### Methods

```java
/**
* Called when the item is selected (switched to).
*/
public void itemSelected(CustomItemRuntime item, PlayerItemHeldEvent event)

/**
* Called when the item is deselected (switched from).
*/
public void itemDeselected(CustomItemRuntime item, PlayerItemHeldEvent event)
```

Also you can handle when player switching hand with only hotkey.

```java
public void handSwitched(CustomItemRuntime item, PlayerSwapHandItemsEvent event)
```

## Register

See [Item manager](/tailslib/tailslib-rus/custom-items/item-manager.md#register-the-item)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://thisistails.gitbook.io/tailslib/tailslib-rus/custom-items/item-methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
