====== 标签 ====== 标签是一组有类似属性的方块、物品或者流体,可以用在配方中,使得不同物品可以在配方中等价。关于标签的更多表述,可参考[[https://minecraft.fandom.com/zh/wiki/标签|中文Minecraft Wiki]]。标签也可以用来分组不同模组的相同物品,以使得这些物品互相兼容。这些称为“常用标签”。 ===== 标签示例 ===== 文件位置:''src/main/resources/data/tutorial/tags/blocks/example_ores.json'' { "replace": false, "values": [ "tutorial:example_ore" ] } ''"replace"'' 标签决定了模组是否要从标签中移除该文件中未提及的其他物品。不建议设为true,且破坏和其他模组的兼容性。文件路径的 ''blocks'' 也可以是 ''items'' 或者 ''fluids'',用于表示不同的类型。多个词语用下划线隔开,且标签名称使用复数形式(不可数名词除外)。 如需注册标签并在代码中使用,你需要这样使用: === 1.19.3 及以上 === public class ModBlockTags { public static final TagKey EXAMPLE_ORES = class_6862.method_40092(class_7924.field_41254, new class_2960("tutorial", "example_ores")); } === 1.19.2 及以下 === public class ModBlockTags { public static final TagKey EXAMPLE_ORES = class_6862.method_40092(class_2378.BLOCK_KEY, new class_2960("tutorial", "example_ores")); } === 1.18.1 及以下(需要 Fabric API) === public class ModBlockTags { public static final Tag EXAMPLE_ORES = TagFactory.BLOCK.create(new class_2960("tutorial", "example_ores")); } === 1.17 及以下,不含 1.17.1(需要 Fabric API) === public class ModBlockTags { public static final Tag EXAMPLE_ORES = TagRegistry.block(new class_2960("tutorial", "example_ores")); } 注意 ''TagRegistry'' 自从 Fabric API 0.46.0 已经弃用,此时已有 ''TagFactory'',但不支持 1.17。 ===== 常见标签和模组标签 ===== 如果你的标签仅仅适用于你的模组,其他的模组不太可能有类似物品,或者你尤其只需要将你的模组的物品包含到标签中,则使用 ''你的模组id:你的标签'',即上面的这个例子。如果你的模组添加其他模组也会添加的物品,你可以: ======= 创建新的常用标签 ======= 常用标签使用 ''c:你的标签'' 这样的语法,其中 ''c'' 代表了“常用”。创建文件时,使用文件路径 ''src/main/resources/data/c/tags/'' 中的 ''blocks''、''items'' 或者 ''fluids''。多个词语用下划线隔开,且标签名称使用复数形式(不可数名词除外)。 ======= 已存在的常用标签 ======= 常用标签的列表请参考[[tutorial:tags#Existing Common Tags|英文页面]],其内容[[https://github.com/fabric-community/fabric-convention-tags|由脚本自动生成]]。如果你的物品适用于这些标签中的一个,则应该将其添加到这个标签而非定义你自己的。如果你的模组的配方与其他模组兼容,则在配方中将物品替换为 ''#c:标签名称''。