User Tools

Site Tools


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
tutorial:armor [2022/04/13 09:39] – map2fabricyarn daomephstatutorial:armor [2023/08/20 10:19] (current) – [Texturing] wjz_p
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}; 
  
- // In which A is helmet, B chestplate, C leggings and D boots+ // In which A is boots, B leggings, C chestplate, and D helmet
  // For reference, Leather uses {1, 2, 3, 1}, and Diamond/Netherite {3, 6, 8, 3}  // For reference, Leather uses {1, 2, 3, 1}, and Diamond/Netherite {3, 6, 8, 3}
 } }
Line 92: Line 92:
 ==== Creating Armor Items ==== ==== Creating Armor Items ====
  
-We're gonna make a new class called RegisterItems to implement your new armor pieces. This will also be the place to, for example, register tools, if you're making a new item like an ingot (We'll refer to this as a "Custom_Material"). This setup will also put the items on a new Creative tab, but you're free to delete that part.  +We're gonna make a new class called RegisterItems to implement your new armor pieces. This will also be the place to, for example, register tools, if you're making a new item like an ingot (We'll refer to this as a "Custom_Material").
- +
-The syntax of groups is //.<yarn method_7892>(YourModName.YOUR_MOD_NAME_BUT_IN_CAPS_GROUP)//. I'll be referring to it as ExampleMod:+
  
 <yarncode java [enable_line_numbers="true"]> <yarncode java [enable_line_numbers="true"]>
Line 100: Line 98:
  
     public static final class_1741 CUSTOM_ARMOR_MATERIAL = new CustomArmorMaterial();     public static final class_1741 CUSTOM_ARMOR_MATERIAL = new CustomArmorMaterial();
-    public static final class_1792 CUSTOM_MATERIAL = new CustomMaterialItem(new class_1792.class_1793().method_7892(ExampleMod.EXAMPLE_MOD_GROUP));+    public static final class_1792 CUSTOM_MATERIAL = new CustomMaterialItem(new class_1792.class_1793());
     // If you made a new material, this is where you would note it.     // If you made a new material, this is where you would note it.
-    public static final class_1792 CUSTOM_MATERIAL_HELMET = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6169, new class_1792.class_1793().method_7892(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 class_1792 CUSTOM_MATERIAL_CHESTPLATE = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6174, new class_1792.class_1793().method_7892(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 class_1792 CUSTOM_MATERIAL_LEGGINGS = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6172, new class_1792.class_1793().method_7892(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 class_1792 CUSTOM_MATERIAL_BOOTS = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6166, new class_1792.class_1793().method_7892(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());
  
 } }
Line 116: Line 114:
 <yarncode java [enable_line_numbers="true"]> <yarncode java [enable_line_numbers="true"]>
 public static void register() { public static void register() {
-    class_2378.method_10230(class_2378.field_11142, new class_2960("examplemod", "custom_material"), CUSTOM_MATERIAL); +    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material"), CUSTOM_MATERIAL); 
-    class_2378.method_10230(class_2378.field_11142, new class_2960("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); 
-    class_2378.method_10230(class_2378.field_11142, new class_2960("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); 
-    class_2378.method_10230(class_2378.field_11142, new class_2960("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); 
-    class_2378.method_10230(class_2378.field_11142, new class_2960("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);
 } }
 </yarncode> </yarncode>
Line 128: Line 126:
 <yarncode java [enable_line_numbers="true"]> <yarncode java [enable_line_numbers="true"]>
 public static final class_1761 EXAMPLE_MOD_GROUP = FabricItemGroupBuilder.create( public static final class_1761 EXAMPLE_MOD_GROUP = FabricItemGroupBuilder.create(
-    new class_2960("examplemod", "example_mod_group"))+    new class_2960("tutorial", "example_mod_group"))
     .icon(() -> new class_1799(RegisterItems.CUSTOM_MATERIAL)) // This uses the model of the new material you created as an icon, but you can reference to whatever you like     .icon(() -> new class_1799(RegisterItems.CUSTOM_MATERIAL)) // This uses the model of the new material you created as an icon, but you can reference to whatever you like
     .build();     .build();
Line 154: Line 152:
 The following should be the same with all armor items, only changing which part are we using. We'll use helmet for our example. The following should be the same with all armor items, only changing which part are we using. We'll use helmet for our example.
  
-<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 165: Line 163:
 Repeat with all armor items. Repeat with all armor items.
  
-To give your on-body armor a texture, simply place X_layer_1.png and X_layer_2.png (where X is the <yarn method_7694> argument you chose in your armor material class) into 'resources/assets/minecraft/textures/models/armor'.+Generally, mod textures go under resources/assets/<modid>, however **armor textures go specifically in the minecraft directory**: 
 +To give your on-body armor a texture, place X_layer_1.png and X_layer_2.png (where X is the <yarn method_7694> argument you chose in your armor material class) into 'resources/assets/**minecraft**/textures/models/armor'.
  
  
  
 If you followed everything, you should now be able to have a full armor set! If you followed everything, you should now be able to have a full armor set!
- 
-====Adding Knockback Protection==== 
- 
-And here comes the so very cursed! 
- 
-Mojang decided that they were not only going to hardcode <yarn method_24355>, but they were also gonna make it immutable! Fun stuff. 
- 
-To get around this, we're gonna make a mixin that goes into <yarn class_1738>. 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: 
- 
-<yarncode java [enable_line_numbers:"true"]> 
-@Mixin (class_1738.class) 
-public abstract class ArmorItemMixin { 
- 
-} 
-</yarncode> 
- 
-Now we have to make a @Shadow to modify knockbackResistance, which is an <yarn class_1320> 
- 
-<yarncode java [enable_line_numbers:"true"]> 
-@Mixin (class_1738.class) 
-public abstract class ArmorItemMixin { 
- @Shadow @Final private static UUID[] MODIFIERS; 
- @Shadow @Final @Mutable private Multimap<class_1320, class_1322> attributeModifiers; 
- @Shadow @Final protected float knockbackResistance; 
-} 
-</yarncode> 
- 
-Next we @Inject our <yarn field_23718> into the <yarn class_1741> constructor. 
- 
-<yarncode java [enable_line_numbers:"true"]> 
-@Mixin (class_1738.class) 
-public abstract class ArmorItemMixin { 
- 
-    @Shadow @Final private static UUID[] MODIFIERS; 
-    @Shadow @Final @Mutable private Multimap<class_1320, class_1322> attributeModifiers; 
-    @Shadow @Final protected float knockbackResistance; 
- 
-    @Inject(method = "<init>", at = @At(value = "RETURN")) 
-    private void constructor(class_1741 material, class_1304 slot, class_1792.class_1793 settings, CallbackInfo ci) { 
-        UUID uUID = MODIFIERS[slot.method_5927()]; 
- 
-        if (material == RegisterItems.CUSTOM_ARMOR_MATERIAL) { 
-            ImmutableMultimap.Builder<class_1320, class_1322> builder = ImmutableMultimap.builder(); 
- 
-            this.attributeModifiers.forEach(builder::put); 
- 
-            builder.put( 
-                    class_5134.field_23718, 
-                    new class_1322(uUID, 
-                            "Armor knockback resistance", 
-                            this.knockbackResistance, 
-                            class_1322.class_1323.field_6328 
-                    ) 
-            ); 
- 
-            this.attributeModifiers = builder.build(); 
-        } 
-    } 
- 
-} 
-</yarncode> 
- 
-Now your armor has the knockback resistance value you assigned to it back on CustomArmorMaterial. 
tutorial/armor.1649842756.txt.gz · Last modified: 2022/04/13 09:39 by daomephsta