User Tools

Site Tools


zh_cn:tutorial:armor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
zh_cn:tutorial:armor [2021/08/17 12:11] solidblockzh_cn:tutorial:armor [2023/08/20 10:14] – [提供纹理] wjz_p
Line 3: Line 3:
 ==== 介绍 ==== ==== 介绍 ====
  
-盔甲是比一般的方块或者物品更复杂一点的实现,但是只要了解了,实现还是很简单的。如需添加盔甲,需要先做一个CustomArmorMaterial类,然后注册物品。无门还需要看看如何为盔甲提供纹理。There's a special chapter at the end of this document that explains how to add knockback to the armor, since the method is only accessible through a mixin (as of 1.16.3).+盔甲是比一般的方块或者物品更复杂一点的实现,但是只要了解了,实现还是很简单的。如需添加盔甲,需要先实现 CustomArmorMaterial 类,然后注册物品。我们还需要看看如何为盔甲提供纹理。本文最后有一个解释如何添加击退的特殊章节,因为此方法只能通过Mixin访问(对于 1.16.3)。
  
-本文档的一个例子可以在[[https://github.com/CumulusMC/Gilded-Netherite|本模组GitHub仓库]]找到。 +本文档的一个例子可以在[[https://github.com/gdude2002/Gilded-Netherite|本模组GitHub仓库]]找到。 
  
 ==== 创建盔甲材料类 ==== ==== 创建盔甲材料类 ====
  
-新的盔甲需要和一个新的名称(以及额外的一些内容,例如盔甲点和耐久度)一起设置,我们需要为我们的CustomArmorMaterial创建一个新的类。+新的盔甲需要和一个新的名称(以及额外的一些内容,例如盔甲点和耐久度)一起设置,我们需要为我们的 CustomArmorMaterial 创建一个新的类。
  
-本类实现ArmorMaterial,并以指定值为盔甲点(称为PROTECTION_VALUES)开始。所有这些参数都会充分利用 @Override。+本类实现 <yarn class_1741>,并以指定值为盔甲点(称为 PROTECTION_VALUES)开始。所有这些参数都会充分利用 @Override。
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
Line 18: Line 18:
  private static final int[] PROTECTION_VALUES = new int[] {A, B, C, D};   private static final int[] PROTECTION_VALUES = new int[] {A, B, C, D}; 
  
- // 其中A是头盔,B是胸甲,C是护腿,D是靴子。+ // 其中A是头盔,B是护腿,C是胸甲,D是靴子。
  // 例如,皮革使用{1, 2, 3, 1},钻石和下界合金使用{3, 6, 8, 3}  // 例如,皮革使用{1, 2, 3, 1},钻石和下界合金使用{3, 6, 8, 3}
 } }
Line 25: Line 25:
 接下来的变量如下定义(无需担心名称,下面你会看到如何实现): 接下来的变量如下定义(无需担心名称,下面你会看到如何实现):
  
-  - getDurability: how many hits can armor take before breaking. Uses the int we wrote on 'BASE_DURABILITY' to calculate. Leather uses 5, Diamond 33, Netherite 37. +  - <yarn method_7696>: how many hits can armor take before breaking. Uses the int we wrote on 'BASE_DURABILITY' to calculate. Leather uses 5, Diamond 33, Netherite 37.   
-  - getProtectionAmount: calls for the 'PROTECTION_VALUES' int we already wrote above. +**计算你的盔甲在损坏之前能承受多少次打击,利用的是你在'BASE_DURABILITY'里所写的int值。皮革是5,钻石33,下届合金的是37。**
-  - getEnchantability: This will be how likely the armor can get high level or multiple enchantments in an enchantment book. +
-  - SoundEvent getEquipSound: The standard used by vanilla armor is ''SoundEvents.ITEM_ARMOR_EQUIP_X'', X being the type of armor. +
-  - Ingredient getRepairIngredient: what item are we gonna be using to repair the armor on an anvil. It can be either a vanilla item or one of your own. +
-  - String getName: what the parent item of the armor is. In Diamond armor, it'd be "diamond"+
-  - getToughness: This is a second protection value where the armor is more durable against high value attacks. Value goes as 'X.0F'+
  
-在1.16引入的新值 +  <yarn method_7697>calls for the 'PROTECTION_VALUES' int we already wrote above  
-  getKnockbackResistanceleave this value at 0. If you want to implement it, write '0.XF(in which X is how much knockback protection you want), and I'll teach you how to make it work later on.+**调用以获取我们之前定义的'PROTECTION_VALUES'.**
  
 +  - <yarn method_7699>: This will be how likely the armor can get high level or multiple enchantments in an enchantment book.
 +**获取关于这件盔甲能够在一本附魔书中被附魔到多高等级、多少种类的附魔**
 +
 +  - <yarn class_3414 method_7698>: The standard used by vanilla armor is ''<yarn class_3417>.ITEM_ARMOR_EQUIP_X'', X being the type of armor.
 +**在原版盔甲中,这个标准是''<yarn class_3417>.ITEM_ARMOR_EQUIP_X'',其中X是你的盔甲类型**
 +
 +  - <yarn class_1856 method_7695>: what item are we gonna be using to repair the armor on an anvil. It can be either a vanilla item or one of your own.
 +**获取我们应该在铁砧中用什么来修复这件盔甲,材料可以是原版的,也可以是你自己的模组中的物品**
 +
 +  - String <yarn method_7694>: what the parent item of the armor is. In Diamond armor, it'd be "diamond".
 +  - <yarn method_7700>: This is a second protection value where the armor is more durable against high value attacks. Value goes as 'X.0F'
 +**这是第二个保护数值,表示装甲在面对高伤害攻击时更耐用。数值为'X.0F'。**
 +在1.16引入的新值
 +  - <yarn method_24355>: leave this value at 0. If you want to implement it, write '0.XF' (in which X is how much knockback protection you want), and I'll teach you how to make it work later on.
 +**将这个值保留为0。如果你想实现它,写上'0.XF'(其中X代表你想要的击退保护量),我会稍后告诉你如何让它生效。**
  
 接下来所有的参数都会写成 X 或者 A、B、C、D。加上这些参数之后,效果应该如下: 接下来所有的参数都会写成 X 或者 A、B、C、D。加上这些参数之后,效果应该如下:
  
-<code java [enable_line_numbers="true"]> +<yarncode java [enable_line_numbers="true"]> 
-public class CustomArmorMaterial implements ArmorMaterial {+public class CustomArmorMaterial implements class_1741 {
  private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11};  private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11};
  private static final int[] PROTECTION_VALUES = new int[] {A, B, C, D};  private static final int[] PROTECTION_VALUES = new int[] {A, B, C, D};
  
  @Override  @Override
- public int getDurability(EquipmentSlot slot) { + public int method_7696(class_1304 slot) { 
- return BASE_DURABILITY[slot.getEntitySlotId()] * X;+ return BASE_DURABILITY[slot.method_5927()] * X;
  }  }
  
  @Override  @Override
- public int getProtectionAmount(EquipmentSlot slot) { + public int method_7697(class_1304 slot) { 
- return PROTECTION_VALUES[slot.getEntitySlotId()];+ return PROTECTION_VALUES[slot.method_5927()];
  }  }
  
  @Override  @Override
- public int getEnchantability() {+ public int method_7699() {
  return X;  return X;
  }  }
  
  @Override  @Override
- public SoundEvent getEquipSound() { + public class_3414 method_7698() { 
- return SoundEvents.ITEM_ARMOR_EQUIP_X;+ return class_3417.ITEM_ARMOR_EQUIP_X;
  }  }
  
  @Override  @Override
- public Ingredient getRepairIngredient() { + public class_1856 method_7695() { 
- return Ingredient.ofItems(RegisterItems.X);+ return class_1856.method_8091(RegisterItems.X);
  }  }
  
  @Override  @Override
- public String getName() {+ public String method_7694() { 
 + // Must be all lowercase
  return "name";  return "name";
  }  }
  
  @Override  @Override
- public float getToughness() {+ public float method_7700() {
  return X.0F;  return X.0F;
  }  }
  
  @Override  @Override
- public float getKnockbackResistance() {+ public float method_24355() {
  return 0.XF;  return 0.XF;
  }  }
 } }
-</code>+</yarncode>
  
- +注意你有盔甲材料类的基础了,所以在新的类中注册你的盔甲物品,即 RegisterItems。
-注意你有盔甲材料类的基础了,所以在新的类中注册你的盔甲物品,即RegisterItems。+
  
 ==== 创建盔甲物品 ==== ==== 创建盔甲物品 ====
  
-我们准备创建一个叫做RegisterItems的新的类以实现新的盔甲物件。这也会是注册工具的地方,如果你准备制作像锭这样的新物品(我们简单称为Custom_Material)。这一步同时还会将这些物品放在创造模式物品栏中,如果需要也可以删除这一部分+我们准备创建一个叫做 RegisterItems 的新的类以实现新的盔甲物件。这也会是注册工具的地方,如果你准备制作像锭这样的新物品(我们简单称为 Custom_Material)。
  
-物品分组的语法为 //.group(你的模组名称.你的分组的大写名称)//。这里将其称为ExampleMod: +<yarncode java [enable_line_numbers="true"]>
- +
-<code java [enable_line_numbers="true"]>+
 public class RegisterItems { public class RegisterItems {
  
-    public static final ArmorMaterial CUSTOM_ARMOR_MATERIAL = new CustomArmorMaterial(); +    public static final class_1741 CUSTOM_ARMOR_MATERIAL = new CustomArmorMaterial(); 
-    public static final Item CUSTOM_MATERIAL = new CustomMaterialItem(new Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP));+    public static final class_1792 CUSTOM_MATERIAL = new CustomMaterialItem(new class_1792.class_1793());
     // 如果创建了新的材料,则你需要注意这里。     // 如果创建了新的材料,则你需要注意这里。
-    public static final Item CUSTOM_MATERIAL_HELMET = new ArmorItem(CUSTOM_ARMOR_MATERIAL, EquipmentSlot.HEAD, new Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP)); +    public static final class_1792 CUSTOM_MATERIAL_HELMET = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6169, new class_1792.class_1793()); 
-    public static final Item CUSTOM_MATERIAL_CHESTPLATE = new ArmorItem(CUSTOM_ARMOR_MATERIAL, EquipmentSlot.CHEST, new Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP)); +    public static final class_1792 CUSTOM_MATERIAL_CHESTPLATE = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6174, new class_1792.class_1793()); 
-    public static final Item CUSTOM_MATERIAL_LEGGINGS = new ArmorItem(CUSTOM_ARMOR_MATERIAL, EquipmentSlot.LEGS, new Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP)); +    public static final class_1792 CUSTOM_MATERIAL_LEGGINGS = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6172, new class_1792.class_1793()); 
-    public static final Item CUSTOM_MATERIAL_BOOTS = new ArmorItem(CUSTOM_ARMOR_MATERIAL, EquipmentSlot.FEET, new Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP));+    public static final class_1792 CUSTOM_MATERIAL_BOOTS = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6166, new class_1792.class_1793());
  
 } }
-</code>+</yarncode>
  
-现在物品创建好了,将其注册并给予适当的名称,你的第一个参数是名字空间,也就是你的模组ID,第二个是你需要给予你的物品的名称。+现在物品创建好了,将其注册并给予适当的名称,你的第一个参数是名字空间,也就是你的模组 ID,第二个是你需要给予你的物品的名称。
  
 我们会在最后一个ArmorItem的下面写这些。 我们会在最后一个ArmorItem的下面写这些。
  
-<code java [enable_line_numbers="true"]>+<yarncode java [enable_line_numbers="true"]>
 public static void register() { public static void register() {
- Registry.register(Registry.ITEM, new Identifier("examplemod", "custom_material"), CUSTOM_MATERIAL); +    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material"), CUSTOM_MATERIAL); 
- Registry.register(Registry.ITEM, new Identifier("examplemod", "custom_material_helmet"), CUSTOM_MATERIAL_HELMET); +    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_helmet"), CUSTOM_MATERIAL_HELMET); 
- Registry.register(Registry.ITEM, new Identifier("examplemod", "custom_material_chestplate"), CUSTOM_MATERIAL_CHESTPLATE); +    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_chestplate"), CUSTOM_MATERIAL_CHESTPLATE); 
- Registry.register(Registry.ITEM, new Identifier("examplemod", "custom_material_leggings"), CUSTOM_MATERIAL_LEGGINGS); +    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_leggings"), CUSTOM_MATERIAL_LEGGINGS); 
- Registry.register(Registry.ITEM, new Identifier("examplemod", "custom_material_boots"), CUSTOM_MATERIAL_BOOTS);+    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_boots"), CUSTOM_MATERIAL_BOOTS);
 } }
-</code>+</yarncode>
  
-你的盔甲物品已完成。现在我们在主类中调用Registry。+你的盔甲物品已完成。现在我们在主类中调用 Registry。
  
-<code java [enable_line_numbers="true"]>+<yarncode java [enable_line_numbers="true"]>
 public static final ItemGroup EXAMPLE_MOD_GROUP = FabricItemGroupBuilder.create( public static final ItemGroup EXAMPLE_MOD_GROUP = FabricItemGroupBuilder.create(
             new Identifier("examplemod", "example_mod_group"))             new Identifier("examplemod", "example_mod_group"))
Line 135: Line 143:
         RegisterItems.register();         RegisterItems.register();
     }     }
-</code>+</yarncode>
  
-好了!你的盔甲现在应该存在于游戏中,虽然还没有纹理,但是已经可以通过/give来获得了。+好了!你的盔甲现在应该存在于游戏中,虽然还没有纹理,但是已经可以通过 /give 来获得了。
  
 现在分配纹理。 现在分配纹理。
- 
  
  
Line 153: Line 160:
 下列过程对于所有盔甲物品都是一样的,只需要修改我们使用的部分。这里以头盔为例。 下列过程对于所有盔甲物品都是一样的,只需要修改我们使用的部分。这里以头盔为例。
  
-<code JSON resources/assets/examplemod/models/item/custom_material_helmet.json>+<code JSON resources/assets/tutorial/models/item/custom_material_helmet.json>
 { {
  "parent": "item/generated",  "parent": "item/generated",
  "textures": {  "textures": {
- "layer0": "examplemod:item/custom_material_helmet"+ "layer0": "tutorial:item/custom_material_helmet"
  }  }
 } }
Line 164: Line 171:
 重复上述过程,完成其他物品。 重复上述过程,完成其他物品。
  
-要给予穿着的盔甲的纹理,只需要将X_layer_1.png和X_layer_2.png(其中X是你在你的盔甲材料类中选择参数)放到'resources/assets/minecraft/textures/models/armor'+要给予穿着的盔甲的纹理,只需要将X_layer_1.png和X_layer_2.png(其中X是你在你的盔甲材料类中重载getName方法的返回值)放到 'resources/assets/minecraft/textures/models/armor'
  
  
Line 170: Line 177:
 做完上述步骤,你应该会有一套完整的盔甲! 做完上述步骤,你应该会有一套完整的盔甲!
  
-==== 添加击退保护 ==== 
- 
-And here comes the so very cursed! 
- 
-Mojang decided that they were not only going to hardcode getKnockbackResistance, but they were also gonna make it immutable! Fun stuff. 
- 
-To get around this, we're gonna make a mixin that goes into ArmorItem. If this is your first time, [[tutorial:mixin_registration|here's how to register mixins on your fabric.mod.json]] 
- 
-We'll make a class called ArmorItemMixin, and write: 
- 
-<code java [enable_line_numbers:"true"]> 
-@Mixin (ArmorItem.class) 
-public abstract class ArmorItemMixin { 
- 
-} 
-</code> 
- 
-Now we have to make a @Shadow to modify knockbackResistance, which is an EntityAttribute 
- 
-<code java [enable_line_numbers:"true"]> 
-@Mixin (ArmorItem.class) 
-public abstract class ArmorItemMixin { 
- @Shadow @Final private static UUID[] MODIFIERS; 
- @Shadow @Final @Mutable private Multimap<EntityAttribute, EntityAttributeModifier> attributeModifiers; 
- @Shadow @Final protected float knockbackResistance; 
-} 
-</code> 
- 
-Next we @Inject our GENERIC_KNOCKBACK_RESISTANCE into the ArmorMaterial constructor. 
- 
-<code java [enable_line_numbers:"true"]> 
-@Mixin (ArmorItem.class) 
-public abstract class ArmorItemMixin { 
- 
-    @Shadow @Final private static UUID[] MODIFIERS; 
-    @Shadow @Final @Mutable private Multimap<EntityAttribute, EntityAttributeModifier> attributeModifiers; 
-    @Shadow @Final protected float knockbackResistance; 
-     
-    @Inject(method = "<init>", at = @At(value = "RETURN")) 
-    private void constructor(ArmorMaterial material, EquipmentSlot slot, Item.Settings settings, CallbackInfo ci) { 
-        UUID uUID = MODIFIERS[slot.getEntitySlotId()]; 
- 
-        if (material == RegisterItems.customArmorMaterial) { 
-            ImmutableMultimap.Builder<EntityAttribute, EntityAttributeModifier> builder = ImmutableMultimap.builder(); 
- 
-            this.attributeModifiers.forEach(builder::put); 
- 
-            builder.put( 
-                    EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, 
-                    new EntityAttributeModifier(uUID, 
-                            "Armor knockback resistance", 
-                            this.knockbackResistance, 
-                            EntityAttributeModifier.Operation.ADDITION 
-                    ) 
-            ); 
- 
-            this.attributeModifiers = builder.build(); 
-        } 
-    } 
-     
-} 
-</code> 
- 
-Now your armor has the knockback resistance value you assigned to it back on CustomArmorMaterial. 
zh_cn/tutorial/armor.txt · Last modified: 2023/08/20 10:19 by wjz_p