Files
2025-03-18 14:46:12 +08:00

352 lines
13 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
sidebarDepth: 1
---
# 配方
## AddBrewingRecipes
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.recipeCompServer.RecipeCompServer
- 描述
添加酿造台配方的接口
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| brewType | str | recipe_brewing_mix或者recipe_brewing_containerrecipe_brewing_mix代表混合酿造配方recipe_brewing_container代表换容酿造配方 |
| inputName | str | 该配方接受的物品 |
| reagentName | str | 酿造所需要的额外物品 |
| outputName | str | 该配方输出的物品 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 输出的物品无法和原来的物品堆叠一起
- 对于已有的配方会返回False
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRecipe(serverApi.GetLevelId())
print(comp.AddBrewingRecipes("recipe_brewing_container", "minecraft:potion", "minecraft:gunpowder", "minecraft:splash_potion"))
```
## AddRecipe
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.recipeCompServer.RecipeCompServer
- 描述
动态注册配方,支持配方类型详见<a href="../../../../mcguide/20-玩法开发/15-自定义游戏内容/5-自定义配方.html#配方类型说明">[配方类型说明]</a>
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| rcp | str或dict | 配方json数据或者配方字典 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否成功 |
- 备注
- 注意按照基岩版1.20的酿造台特性,每个药水槽内一次只能放进一个物品,无法一次放入两个及以上的数量的物品。目前该接口无法在联机大厅生效,后续会修复
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRecipe(serverApi.GetLevelId())
dictData = {
"minecraft:recipe_brewing_container": {
"description": {
"identifier": "netease:splash_to_normal"
},
"tags": ["brewing_stand"],
"input": "minecraft:splash_potion",
"reagent": "minecraft:apple",
"output": "minecraft:potion"
}
}
jsonData = '{
"minecraft:recipe_furnace": {
"description": {
"identifier": "netease:diamond_to_apple"
},
"tags": ["furnace"],
"input": {
"item": "minecraft:diamond",
"count": 1
},
"output": {
"item": "minecraft:apple"
}
}
}'
print "dictionary data:", comp.AddRecipe(dictData)
print "json str data:", comp.AddRecipe(jsonData)
```
## GetRecipeResult
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.recipeCompServer.RecipeCompServer
- 描述
根据配方id获取配方结果。仅支持合成配方
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| recipeId | str | 配方id,对应配方json文件中的identifier字段 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| list(dict) | list的元素resultDict字典见备注 |
- 备注
- resultDict字典内容如下
| 关键字 | 数据类型 | 说明 |
| ----------| --------------------- | ---------|
| fullItemName | str | 物品的identifier |
|auxValue| int | 物品附加值 |
|num| int | 物品数目 |
- 在基岩版1.20更新后,配方里的部分物品不再是对应单一物品,而是对应某种类型的物品。即'item字段所对应的物品有可能是列表类型(list),也可能为字符串类型(str)。如果是字符串类型则为这个物品的identifier如果为列表类型则包含了符合同种类型的所有物品的identifier。例如木板类型的物品item'则会返回包含'minecraft:mangrove_planks', 'minecraft:planks', 'minecraft:warped_planks'等木板在内的列表。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRecipe(serverApi.GetLevelId())
comp.GetRecipeResult("minecraft:boat")
```
## GetRecipesByInput
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.recipeCompServer.RecipeCompServer
- 描述
通过输入物品查询配方
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| inputIdentifier | str | 输入物品的标识符 |
| tag | str | 对应配方json中的tags字段里面的值 |
| aux | int | 输入物品的附加值, 不传参的话默认为0 |
| maxResultNum | int | 最大输出条目数若大于等于0时结果超过maxResultNum则只返回maxResultNum条。默认-1表示返回全部 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| list(dict) | 返回符合条件的配方列表 |
- 备注
- 获取熔炉配方时若输出物品数量为1时output使用字符串表示物品identifier及附加值若输出物品数量大于1时output为一个dict
- 在获取酿造台配方时不匹配tag标签与aux值药水的identifier需要输入全称例如minecraft:potion_type:long_turtle_master否则无法获取正确的配方。
- 需要遍历较多数据,不建议频繁调用
- 在基岩版1.20更新后,配方里的部分物品不再是对应单一物品,而是对应某种类型的物品。即'item字段所对应的物品有可能是列表类型(list),也可能为字符串类型(str)。如果是字符串类型则为这个物品的identifier如果为列表类型则包含了符合同种类型的所有物品的identifier。例如木板类型的物品item'则会返回包含'minecraft:mangrove_planks', 'minecraft:planks', 'minecraft:warped_planks'等木板在内的列表。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRecipe(serverApi.GetLevelId())
print(comp.GetRecipesByInput("minecraft:log", "crafting_table", 0, -1))
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.recipeCompClient.RecipeCompClient
- 描述
通过输入物品查询配方
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| inputIdentifier | str | 输入物品的标识符 |
| tag | str | 对应配方json中的tags字段里面的值 |
| aux | int | 输出物品的附加值, 不传参的话默认为0 |
| maxResultNum | int | 最大输出条目数若大于等于0时结果超过maxResultNum则只返回maxResultNum条。默认-1表示返回全部 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| list(dict) | 返回符合条件的配方列表 |
- 备注
- 获取熔炉配方时若输出物品数量为1时output使用字符串表示物品identifier及附加值若输出物品数量大于1时output为一个dict
- 在获取酿造台配方时不匹配tag标签与aux值药水的identifier需要输入全称例如minecraft:potion_type:long_turtle_master否则无法获取正确的配方。
- 需要遍历较多数据,不建议频繁调用
- 在基岩版1.20更新后,配方里的部分物品不再是对应单一物品,而是对应某种类型的物品。即'item字段所对应的物品有可能是列表类型(list),也可能为字符串类型(str)。如果是字符串类型则为这个物品的identifier如果为列表类型则包含了符合同种类型的所有物品的identifier。例如木板类型的物品item'则会返回包含'minecraft:mangrove_planks', 'minecraft:planks', 'minecraft:warped_planks'等木板在内的列表。
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateRecipe(clientApi.GetLevelId())
print(comp.GetRecipesByInput("minecraft:log", "crafting_table", 0, -1))
```
## GetRecipesByResult
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.recipeCompServer.RecipeCompServer
- 描述
通过输出物品查询配方所需要的输入材料
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| resultIdentifier | str | 输出物品的标识符 |
| tag | str | 对应配方json中的tags字段里面的值 |
| aux | int | 输出物品的附加值, 不传参的话默认为0 |
| maxResultNum | int | 最大输出条目数若大于等于0时结果超过maxResultNum则只返回maxResultNum条。默认-1表示返回全部 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| list(dict) | 返回符合条件的配方列表 |
- 备注
- 获取熔炉配方时若输出物品数量为1时output使用字符串表示物品identifier及附加值若输出物品数量大于1时output为一个dict
- 在获取酿造台配方时不匹配tag标签与aux值药水的identifier需要输入全称例如minecraft:potion_type:long_turtle_master否则无法获取正确的配方。
- 在基岩版1.20更新后,配方里的部分物品不再是对应单一物品,而是对应某种类型的物品。即'item字段所对应的物品有可能是列表类型(list),也可能为字符串类型(str)。如果是字符串类型则为这个物品的identifier如果为列表类型则包含了符合同种类型的所有物品的identifier。例如木板类型的物品item'则会返回包含'minecraft:mangrove_planks', 'minecraft:planks', 'minecraft:warped_planks'等木板在内的列表。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRecipe(serverApi.GetLevelId())
print(comp.GetRecipesByResult("minecraft:boat", "crafting_table", 4, -1))
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.recipeCompClient.RecipeCompClient
- 描述
通过输出物品查询配方所需要的输入材料
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| resultIdentifier | str | 输出物品的标识符 |
| tag | str | 对应配方json中的tags字段里面的值 |
| aux | int | 输出物品的附加值, 不传参的话默认为0 |
| maxResultNum | int | 最大输出条目数若大于等于0时结果超过maxResultNum则只返回maxResultNum条。默认-1表示返回全部 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| list(dict) | 返回符合条件的配方列表 |
- 备注
- 获取熔炉配方时若输出物品数量为1时output使用字符串表示物品identifier及附加值若输出物品数量大于1时output为一个dict
- 在获取酿造台配方时不匹配tag标签与aux值药水的identifier需要输入全称例如minecraft:potion_type:long_turtle_master否则无法获取正确的配方。
- 在基岩版1.20更新后,配方里的部分物品不再是对应单一物品,而是对应某种类型的物品。即'item字段所对应的物品有可能是列表类型(list),也可能为字符串类型(str)。如果是字符串类型则为这个物品的identifier如果为列表类型则包含了符合同种类型的所有物品的identifier。例如木板类型的物品item'则会返回包含'minecraft:mangrove_planks', 'minecraft:planks', 'minecraft:warped_planks'等木板在内的列表。
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateRecipe(clientApi.GetLevelId())
print(comp.GetRecipesByResult("minecraft:boat", "crafting_table", 4, -1))
```
## RemoveRecipe
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.recipeCompServer.RecipeCompServer
- 描述
动态禁用配方
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| rcpIdentifier | str | 配方identifier |
| rcpTypeStr | str | 配方类型,省略前缀"minecraft"。详见<a href="../../../../mcguide/20-玩法开发/15-自定义游戏内容/5-自定义配方.html#配方类型说明">[配方类型说明]</a> |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否成功 |
- 备注
- 目前动态移除配方接口不支持移除原生配方
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRecipe(serverApi.GetLevelId())
comp.RemoveRecipe("netease:splash_to_normal", "recipe_brewing_container")
comp.RemoveRecipe("netease:diamond_to_apple", "recipe_furnace")
```