Recipe Remover
基本信息
| 属性 | 值 |
|---|---|
| 类 | gttweaker.mods.gregtech.RecipeRemover |
| ZenClass | mods.gregtech.RecipeRemover |
| ModOnly | @ModOnly("gregtech") |
| ZenMethod 数 | 1(remove) |
| 动作类型 | RecipeRemoveAction implements IUndoableAction —— 可撤销 |
| 匹配方式 | RecipeMap.findRecipeQuery().items(...).fluids(...).dontCheckStackSizes(true).find() |
| map 解析 | GTRecipeMap.getRecipeMap(String) |
| 注册时机 | FMLInitializationEvent(init) |
作用
按 RecipeMap 名 + 物品输入 + 流体输入从 GregTech 5 中删除一条配方,是本 mod 提供的唯一删除能力(55 个机器类只能添加)。
脚本用法:
mods.gregtech.RecipeRemover.remove("centrifugeRecipes", [<bucket>], [<water:1000>]);
remove 流程(RecipeRemover.java:24-49)
RecipeMap<?> recipeMap = GTRecipeMap.getRecipeMap(map);
if (recipeMap == null) { logError("Could not find recipe map named \"" + map + "\""); return; }
GTRecipe recipe = recipeMap.findRecipeQuery()
.items(Arrays.stream(inputs).map(GTTweaker::getItemStackOrNull)
.filter(Objects::nonNull).toArray(ItemStack[]::new))
.fluids(Arrays.stream(fluidInputs).map(GTTweaker::getFluidStackOrNull)
.filter(Objects::nonNull).toArray(FluidStack[]::new))
.dontCheckStackSizes(true)
.find();
if (recipe == null) { logWarning("Could not find recipe to remove!"); return; }
MineTweakerAPI.apply(new RecipeRemoveAction(recipe, recipeMap));
RecipeRemoveAction:apply() → map.getBackend().removeRecipe(recipe);undo() → map.add(recipe);describe() = "Remove recipe from GT Machine";getOverrideKey() 返回 null。
数值
| 数值 | 值 |
|---|---|
| ZenMethod 数 | 1 |
| 参数个数 | 3(String map, IIngredient[] inputs, IIngredient[] fluidInputs) |
| 每次删除配方数 | 恰好 1(find() 返回单条) |
| stack size 检查 | dontCheckStackSizes(true) —— 关闭 |
null 元素处理 |
filter(Objects::nonNull) —— 静默丢弃无法转换的原料 |
| map 未找到 | logError + return |
| 配方未找到 | logWarning + return(注意级别不同) |
describe() |
"Remove recipe from GT Machine" |
| 可撤销 | 是 |
源码缺陷
logError与logWarning混用(:28vs:45):map 找不到是logError,配方找不到是logWarning。两者都是「脚本写错了」,严重程度却不同 —— 在 CraftTweaker 的/ct errors中只有logError会高亮,脚本作者可能完全看不到配方没找到的警告,误以为删除成功。find()静默丢弃无法转换的原料:map(GTTweaker::getItemStackOrNull).filter(Objects::nonNull)—— 若脚本写了<ore:doesNotExist>(矿辞典为空 →getItemStackOrNull返回null),该原料被直接从查询中移除,导致用更少条件去匹配(见 原料转换)。可能匹配到与预期完全不同的配方并将其删除。- 只删一条,不删全部匹配:
find()返回单条GTRecipe。若某 map 中有多条配方物品输入相同,脚本必须重复调用;源码无批量删除入口。 dontCheckStackSizes(true)放宽匹配:数量不参与匹配,因此<ingotIron:1>与<ingotIron:64>会匹配到同一条配方。对删除操作而言这是合理的(避免数量导致的误失配),但源码无注释说明。RecipeRemoveAction的字段无final(:53-54),与RA2Builder.RecipeAddAction风格一致(同仓库同问题)。describe()未含 RecipeMap 名与配方内容("Remove recipe from GT Machine"):MineTweaker 的 undo 列表里多条删除记录无法区分,只能靠顺序。对比RA2Builder的"RA2 - Adding recipe"同样不区分。- 无
@SuppressWarnings之外的现代写法:全类无泛型菱形(List<Class>在GTTweakerRegistry中),风格偏旧。 RecipeMap泛型<?>而非<? extends RecipeMap<?>>:map.getBackend()返回原始类型,调用removeRecipe(recipe)时有 unchecked 警告。
相关条目
- Recipe Map 查找 -
getRecipeMap(String)的实现与缓存 - RA2 Builder - 另一个
IUndoableAction实现,可作对比 - 原料转换 -
getItemStackOrNull/getFluidStackOrNull的失败模式 - 注册时序 - 本类的注册阶段