Crafting Recipe API
基本信息
| 属性 | 值 |
|---|---|
| 包路径 | net.mcft.betterstorage.api.crafting |
| 类数量 | 12 |
| 核心接口 | IStationRecipe、IRecipeInput、ICraftingSource |
| 注册入口 | BetterStorageCrafting.addStationRecipe(...) |
| gradle apiPackage | 未配置(gradle.properties 中 apiPackage = 为空) |
来源:src/main/java/net/mcft/betterstorage/api/crafting/;gradle.properties。
功能
这是本 mod 面向第三方模组的主要扩展点:让其它模组把自己的配方接入 合成台,而不是只能放在工作台里。
核心接口
IStationRecipe
合成台配方的契约。实现类分两种基类:
| 基类 | 类型 |
|---|---|
ShapedStationRecipe |
有序 |
ShapelessStationRecipe |
无序 |
IRecipeInput
配方输入的匹配抽象。本 mod 提供 4 种实现:
| 实现类 | 匹配方式 |
|---|---|
RecipeInputBase |
抽象基类 |
RecipeInputItemStack |
精确匹配物品栈 |
RecipeInputOreDict |
走物品字典 |
RecipeInputList |
多选一 |
RecipeBounds 用于约束配方在 3×3 网格中的位置。
ICraftingSource
描述配方的合成来源。CraftingSourceTileEntity 是基于 TileEntity 的实现。
ContainerInfo 提供容器元信息。
匹配流程
StationCrafting(src/main/java/net/mcft/betterstorage/api/crafting/StationCrafting.java)是匹配引擎,负责遍历已注册配方并用 IRecipeInput 体系比对合成栏内容。
RecipeInputBase 与 RecipeInputItemStack / RecipeInputOreDict / RecipeInputList 的组合使第三方模组可以表达「任意铜锭」「任意原木」这类宽松输入,无需自己实现物品匹配逻辑。
类清单
| 类 | 类型 |
|---|---|
BetterStorageCrafting |
注册入口 |
StationCrafting |
匹配引擎 |
IStationRecipe |
配方接口 |
ShapedStationRecipe |
有序配方基类 |
ShapelessStationRecipe |
无序配方基类 |
IRecipeInput |
输入匹配接口 |
RecipeInputBase |
输入抽象基类 |
RecipeInputItemStack |
物品栈匹配 |
RecipeInputOreDict |
物品字典匹配 |
RecipeInputList |
多选一匹配 |
RecipeBounds |
位置约束 |
ICraftingSource |
合成来源接口 |
CraftingSourceTileEntity |
TileEntity 来源实现 |
ContainerInfo |
容器元信息 |
共 14 个文件(目录 src/main/java/net/mcft/betterstorage/api/crafting/)。
使用示例(本 mod 自身)
src/main/java/net/mcft/betterstorage/misc/Recipes.java 中的 3 处调用:
BetterStorageCrafting.addStationRecipe(new PresentRemoveNametagRecipe()); // :168
BetterStorageCrafting.addStationRecipe(new CardboardEnchantmentRecipe()); // :323
BetterStorageCrafting.addStationRecipe(new CardboardRepairRecipe()); // :326
注意
gradle.properties 中 apiPackage = 为空值(未配置),意味着该包未被 build 脚本特殊标记为 API 包。第三方模组引用本 mod 的类时需自行处理依赖。