====== 添加盾牌====== [最高支持到1.19版本,对于1.14及以下版本,请参考英文原版wiki:https://fabricmc.net/wiki/tutorial:shield] 恭喜!在上一个教程中我们学会了如何创建自定义工具!想象一下,如果想要防御一把十分强大自定义的剑,常规的盾牌是不大起作用的。因此,我们将在这里尝试创建自定义的盾牌。 幸运的,CrimsonDawn45 已经为此制作了一个库来辅助创建自定义盾牌,如果没有他创建的库,我们甚至可能需要在这个教程中待上一个小时,感谢 CrimsonDawn45! 库的源码存储在 https://github.com/CrimsonDawn45/Fabric-Shield-Lib ===== 为项目添加依赖 ===== 将以下的代码添加到对应的文件中:\\ \\ **gradle.properties**\\ fabric_shield_lib_version=1.6.0-1.19 \\ **build.gradle** (在 dependencies {} 下)\\ modImplementation "com.github.CrimsonDawn45:Fabric-Shield-Lib:v${project.fabric_shield_lib_version}" \\ 在编写本文时,最新 project.fabric_shield_lib_version 应为1.3.7,最新 project.minecraft_version 应为1.17.1。每当出现新的版本时,此页面都会更新。\\ \\ **build.gradle** (在 repositories {} 下)\\ maven { url = 'https://jitpack.io' } \\ **__如果你的mod用于1.17或更高的游戏版本、或者你正在使用FabricShieldLib version 1.5.0 或以上,记得同时也要添加下面的东西:__** **gradle.properties**\\ fabric_asm_version=2.3 cloth_version=8.1.77 mod_menu_version=4.0.6 crowdlin_version=1.4+1.19 \\ **(These versions will be updated in this wiki alongside the mod version)** **build.gradle** (under dependencies)\\ modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}") { exclude(group: "net.fabricmc.fabric-api") } include("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}") modCompileOnly modRuntimeOnly ("com.terraformersmc:modmenu:${project.mod_menu_version}"), { exclude(group: "net.fabricmc.fabric-api") } modImplementation("com.github.Chocohead:Fabric-ASM:v${project.fabric_asm_version}") { exclude (group: "net.fabricmc.fabric-api") } include("com.github.Chocohead:Fabric-ASM:v${project.fabric_asm_version}") \\ **build.gradle** (under repositories, the one above dependencies)\\ maven { url "https://maven.shedaniel.me/" } maven { url "https://maven.terraformersmc.com/releases/" } \\ ===== 添加一块自定义的盾牌 ===== 现在我们正式开始!\\ \\ 请确保正确遵循了上一步并且刷新了项目依赖以添加库到项目中\\ 第一步,创建一个物品实例 public static final Item NETHERITE_SHIELD = new FabricShield(new FabricItemSettings().group(ItemGroup.COMBAT), 10, 2500, 13, Items.NETHERITE_INGOT); // FabricShield(settings, cooldownTicks, durability, enchantability, repairItem) \\ 然后,注册这个物品\\ Registry.register(Registries.ITEM, new Identifier("moreshields", "netherite_shield"), NETHERITE_SHIELD) \\ 我们已经创建了自定义盾牌的物品\\ 现在,我们需要为自定义盾牌添加纹理和模型\\ 对于纹理,可以使用任意的资源,如果不知道需要怎么样绘制,可以参考游戏原版的盾牌图案,然后在原版盾牌图案的基础上进行修改。绘制完成后放置到 resources/textures/item/.png\\ 对于模型, 需要编写一些 .json 文件\\ 指定物品模型 \\ { "parent":"fabricshieldlib:item/template_shield", "textures":{ "shield":"moreshields:item/netherite_shield" }, "overrides": [ { "predicate": { "blocking": 1 }, "model": "moreshields:item/netherite_shield_blocking" } ] } \\ 把它放到 resources/models/item/netherite_shield.json\\ 然后是方块模型 \\ { "parent":"fabricshieldlib:item/template_shield_blocking", "textures":{ "shield":"moreshields:item/netherite_shield" } } \\ 放到 resources/models/item/netherite_shield_blocking.json\\ \\ 最后,不要忘记添加本地化语言文件 **en_us.json**\\ { "item.moreshields.netherite_shield": "Netherite Shield" } \\ 到这里,一块自定义盾牌已经完成啦!