RA2 Builder
基本信息
| 属性 | 值 |
|---|---|
| 类 | gttweaker.mods.gregtech.RA2Builder |
| ZenClass | mods.gregtech.RA2(注意:不叫 RA2Builder) |
| ModOnly | @ModOnly("gregtech") |
| ZenMethod 数 | 15(全 mod 最多) |
| 动作类型 | RecipeAddAction implements IUndoableAction —— 可撤销 |
| RecipeMap 解析 | GTRecipeMap.getRecipeMap(String)(字符串运行时查表) |
| 注册时机 | FMLInitializationEvent(init) |
作用
GT5 的「RA2(Recipe Assembly v2)」链式配方构造器的 CraftTweaker 移植。这是本 mod 中唯一提供完整可撤销语义的「添加配方」路径 —— 55 个机器类走的 AddMultipleRecipeAction extends OneWayAction 全部不可撤销。
脚本用法:
mods.gregtech.RA2.builder()
.itemInputs([<ingotIron>])
.itemOutputs([<ingotSteel>])
.duration(100)
.eut(30)
.addTo("benderRecipes");
15 个 ZenMethod
| 方法 | 作用 | 备注 |
|---|---|---|
static RA2Builder builder() |
新建 builder(GTValues.RA.stdBuilder()) |
唯一静态方法 |
itemInputs(IIngredient[]) |
设置物品输入 | 经 GTTweaker.getItemStackOrNull + filter(nonNull) |
itemOutputs(IIngredient[]) |
设置物品输出 | 同上 |
fluidInputs(IIngredient[]) |
设置流体输入 | 经 GTTweaker.getFluidStackOrNull + filter(nonNull) |
fluidOutputs(IIngredient[]) |
设置流体输出 | 同上 |
duration(int) |
持续 tick | |
eut(int) |
每 tick EU | |
outputChances(int[]) |
输出概率 | 直传 |
specialValue(int) |
特殊值 | 直传 |
specialItem(IIngredient) |
特殊物品 | 单个,非数组 |
noItemInputs() |
空实现 | 见缺陷 |
noItemOutputs() |
空实现 | 见缺陷 |
noFluidInputs() |
空实现 | 见缺陷 |
noFluidOutputs() |
空实现 | 见缺陷 |
addTo(String recipeMap) |
构建并提交 | 见下 |
addTo 流程(RA2Builder.java:124-140)
GTRecipe recipe = recipeBuilder.build().orElse(null);
if (recipe == null) { MineTweakerAPI.logError("Could not build recipe!"); return; }
RecipeMap<?> map = GTRecipeMap.getRecipeMap(recipeMap);
if (map == null) { MineTweakerAPI.logError("Could not find recipe map named \"" + recipeMap + "\""); return; }
MineTweakerAPI.apply(new RecipeAddAction(recipe, map));
两处失败均为 logError + return,不抛异常。
RecipeAddAction:apply() → map.add(recipe);undo() → map.getBackend().removeRecipe(recipe);describe() = "RA2 - Adding recipe";describeUndo() = "RA2 - Removing recipe";getOverrideKey() 返回 null。
数值
| 数值 | 值 |
|---|---|
| ZenMethod 数 | 15 |
| 静态方法数 | 1(builder()) |
| 实例链式方法数 | 13 |
addTo 参数类型 |
String(RecipeMap 的 unlocalized 名) |
| 动作可撤销 | 是(IUndoableAction) |
describe() |
"RA2 - Adding recipe" |
describeUndo() |
"RA2 - Removing recipe" |
| 构建失败处理 | logError + return |
| map 未找到处理 | logError + return |
源码缺陷
- 4 个
noXxx()方法是纯空实现(:40-42、:54-56、:68-70、:82-84):方法体只有return this;,不做任何清空操作。脚本作者写.itemInputs([...]).noItemInputs()会得到两者都保留的结果 —— builder 内部仍带着之前的itemInputs。这 4 个方法的存在极具误导性,源码无注释。 - 两个
noXxx之间的差异只有目标字段(items vs fluids),但实现完全相同,是纯样板。 RA2Builder命名与 ZenClass 名不一致:@ZenClass("mods.gregtech.RA2")而类名是RA2Builder。脚本侧写mods.gregtech.RA2,Java 侧叫RA2Builder,检索源码时易漏。recipeBuilder字段可被null构造器绕过(:28):public RA2Builder() {}不设recipeBuilder。若该构造器被 ZenScript 反射实例化(虽然无@ZenMethod指向它),后续任一链式调用即 NPE。specialItem(IIngredient)用IIngredient而其余批量方法也用IIngredient:getItemStackOrNull遇String内部(矿辞典项)时取OreDictionary.getOres(...).get(0),即静默取第一个匹配项;矿辞典为空时返回null→ builder 收到nullspecial。源码无日志。RecipeAddAction的字段无final(:143-144):GTRecipe recipe/RecipeMap<?> map可变,虽无 setter 但风格上与RecipeRemoveAction一致。- 每次
addTo只提交 1 条配方:与AddMultipleRecipeAction的笛卡尔积展开不同,RA2 不支持一条脚本添加多条配方。
相关条目
- Recipe Map 查找 -
addTo(String)的 map 解析依赖 - AddMultipleRecipeAction - 对比:不可撤销的批量路径
- Recipe Remover - 与本条目共用
GTRecipeMap - 原料转换 -
IIngredient[]→ItemStack[]的转换实现