> For the complete documentation index, see [llms.txt](https://youyi580.gitbook.io/cog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://youyi580.gitbook.io/cog/advance/item-transform.md).

# 物品转换器

想在配方当中使用工具又不想吞工具？你就需要使用物品转换器了！物品条件和物品转换器也可以同时使用！

注意：1.16 的物品转换器只适用于不可堆叠的物品，对可堆叠物品使用会产生刷物品 Bug！

## 创建

使用 IIngredient 的 `transformCustom` 方法。这个方法有两个参数：

* uid as `string`：物品转换器的 ID，ID 要相互独立。建议如果要用多次带有物品转换器的物品，先把他存进变量里。
* function as `Function<IItemStack, IItemStack>`：一个以 IItemStack 为参数（具体的物品），返回值为 IItemStack （作为转换后的物品）的 lambda 表达式。用于确定物品转换器的具体逻辑。

```javascript
// 参与合成后，钻石镐变成铁镐
<item:minecraft:diamond_pickaxe>.transformCustom("level_down", (stack) => <item:minecraft:iron_pickaxe>);
```

## 复用

我们可以复用已经创建的物品转换器。

```javascript
val a = <item:minecraft:diamond_pickaxe>.transformCustom("level_down", (stack) => <item:minecraft:iron_pickaxe>);

// 现在这个金镐参与合成后也会变成铁镐了
<item:minecraft:golden_pickaxe>.transform(a.transformer);
```

## 内置物品转换器

以下是 CrT 内置的物品转换器。

* `reuse()`：不会消耗
* `transformDamage(amount as int)`：合成后掉几点耐久
* `transformReplace(replaceWith as IItemStack)`：合成后会变成什么物品

```javascript
<item:minecraft:diamond_axe>.reuse();
<item:minecraft:diamond_axe>.transformDamage(5);
<item:minecraft:diamond_pickaxe>.transformReplace(<item:minecraft:iron_pickaxe>);

// 我想你使用耗耐久的合成，肯定也要任何耐久的工具都能用于合成
<item:minecraft:diamond_axe>.anyDamage().transformDamage(5);
```


---

# 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://youyi580.gitbook.io/cog/advance/item-transform.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.
