tutorial:armor
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:armor [2022/04/13 09:39] – map2fabricyarn daomephsta | tutorial:armor [2024/07/04 16:32] (current) – mineblock11 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~REDIRECT> | ||
+ | |||
====== Adding Armor ====== | ====== Adding Armor ====== | ||
- | ==== Introduction ==== | + | ===== Introduction |
While armor is a bit more complicated to implement than a normal block or item, once you understand it, it becomes simple to implement. To add armor, we'll first make a CustomArmorMaterial class, then register the items. We'll also take a look at how to texture them. There' | While armor is a bit more complicated to implement than a normal block or item, once you understand it, it becomes simple to implement. To add armor, we'll first make a CustomArmorMaterial class, then register the items. We'll also take a look at how to texture them. There' | ||
Line 7: | Line 9: | ||
An example for this document can be found in [[https:// | An example for this document can be found in [[https:// | ||
- | ==== Creating an Armor Material class ==== | + | ===== Creating an Armor Material class ===== |
Since new armor needs to be set with a new name (as well as extra things like armor points and durability), | Since new armor needs to be set with a new name (as well as extra things like armor points and durability), | ||
Line 18: | Line 20: | ||
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 | + | // In which A is boots, B leggings, C chestplate, |
// For reference, Leather uses {1, 2, 3, 1}, and Diamond/ | // For reference, Leather uses {1, 2, 3, 1}, and Diamond/ | ||
} | } | ||
Line 90: | Line 92: | ||
Now that you have the basics of the armor material class, let's register your armor items in a new class we'll simply call RegisterItems. | Now that you have the basics of the armor material class, let's register your armor items in a new class we'll simply call RegisterItems. | ||
- | ==== 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 | + | In the [[item]] tutorial, we've created |
- | + | ||
- | The syntax of groups is //.<yarn method_7892> | + | |
< | < | ||
- | public class RegisterItems | + | public |
+ | // [...] | ||
+ | | ||
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 = register(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, | + | public static final class_1792 CUSTOM_MATERIAL_HELMET = register(new class_1738(CUSTOM_ARMOR_MATERIAL, |
- | public static final class_1792 CUSTOM_MATERIAL_CHESTPLATE = new class_1738(CUSTOM_ARMOR_MATERIAL, | + | public static final class_1792 CUSTOM_MATERIAL_CHESTPLATE = register(new class_1738(CUSTOM_ARMOR_MATERIAL, |
- | public static final class_1792 CUSTOM_MATERIAL_LEGGINGS = new class_1738(CUSTOM_ARMOR_MATERIAL, | + | public static final class_1792 CUSTOM_MATERIAL_LEGGINGS = register(new class_1738(CUSTOM_ARMOR_MATERIAL, |
- | public static final class_1792 CUSTOM_MATERIAL_BOOTS = new class_1738(CUSTOM_ARMOR_MATERIAL, | + | public static final class_1792 CUSTOM_MATERIAL_BOOTS = register(new class_1738(CUSTOM_ARMOR_MATERIAL, |
} | } | ||
</ | </ | ||
- | Now that your items are properly created, let's register them and give them proper names. Your first parameter is going to be your namespace, which is your mod ID, and then next one the name you want to give to your item. | + | Your armor items are done. Now we' |
- | + | ||
- | We' | + | |
< | < | ||
- | public | + | public |
- | | + | |
- | | + | |
- | | + | .displayName(Text.translatable("itemGroup.tutorial.test_group")) |
- | | + | .entries((context, entries) -> { |
- | | + | |
+ | | ||
+ | .add(CUSTOM_MATERIAL_CHESTPLATE) | ||
+ | .add(CUSTOM_MATERIAL_LEGGINGS) | ||
+ | | ||
+ | }) | ||
+ | .build(); | ||
+ | | ||
+ | | ||
+ | // Since 1.21: | ||
+ | Registry.register(Registries.ITEM_GROUP, Identifier.of("tutorial", "test_group" | ||
+ | } | ||
} | } | ||
</ | </ | ||
- | Your armor items are done. Now we'll just call the Registry on our main class (and annotate | + | If you did those above in the separate classes, remember to statically initialize |
- | + | <code java> | |
- | <yarncode | + | public |
- | public | + | |
- | new class_2960(" | + | |
- | .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 | + | @Override |
- | | + | public void onInitialize() { |
- | + | | |
- | @Override | + | TUtorialItemGroups.initialize(); |
- | public void onInitialize() { | + | } |
- | | + | |
} | } | ||
- | </yarncode> | + | </code> |
That's it! Your armor should now exist in game, untextured still, but present and able to be given with /give. | That's it! Your armor should now exist in game, untextured still, but present and able to be given with /give. | ||
Now we'll be assigning the textures to each piece. | Now we'll be assigning the textures to each piece. | ||
- | |||
- | |||
==== Texturing ==== | ==== Texturing ==== | ||
We're going to assume you | We're going to assume you | ||
- | * Have the textures for each armor item (x_helmet.png, | + | * Have the textures for each armor item ('' |
- | * Have the textures for the armor in body (x_layer_1.png and x_layer_2.png) | + | * Have the textures for the armor in body ('' |
And assign them to each armor item. | And assign them to each armor item. | ||
Line 154: | Line 160: | ||
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. | ||
- | < | + | < |
{ | { | ||
" | " | ||
" | " | ||
- | " | + | " |
} | } | ||
} | } | ||
Line 165: | Line 171: | ||
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> | + | Generally, mod textures go under resources/ |
+ | To give your on-body armor a texture, place '' | ||
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>, | ||
- | |||
- | To get around this, we're gonna make a mixin that goes into <yarn class_1738> | ||
- | |||
- | We'll make a class called ArmorItemMixin, | ||
- | |||
- | < | ||
- | @Mixin (class_1738.class) | ||
- | public abstract class ArmorItemMixin { | ||
- | |||
- | } | ||
- | </ | ||
- | |||
- | Now we have to make a @Shadow to modify knockbackResistance, | ||
- | |||
- | < | ||
- | @Mixin (class_1738.class) | ||
- | public abstract class ArmorItemMixin { | ||
- | @Shadow @Final private static UUID[] MODIFIERS; | ||
- | @Shadow @Final @Mutable private Multimap< | ||
- | @Shadow @Final protected float knockbackResistance; | ||
- | } | ||
- | </ | ||
- | |||
- | Next we @Inject our <yarn field_23718> | ||
- | |||
- | < | ||
- | @Mixin (class_1738.class) | ||
- | public abstract class ArmorItemMixin { | ||
- | |||
- | @Shadow @Final private static UUID[] MODIFIERS; | ||
- | @Shadow @Final @Mutable private Multimap< | ||
- | @Shadow @Final protected float knockbackResistance; | ||
- | |||
- | @Inject(method = "< | ||
- | 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< | ||
- | |||
- | this.attributeModifiers.forEach(builder:: | ||
- | |||
- | 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(); | ||
- | } | ||
- | } | ||
- | |||
- | } | ||
- | </ | ||
- | |||
- | 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