tutorial:armor
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
tutorial:armor [2022/03/17 15:17] – fix furnygo | tutorial:armor [2022/04/13 09:39] – map2fabricyarn daomephsta | ||
---|---|---|---|
Line 11: | Line 11: | ||
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), | ||
- | This class will implement | + | This class will implement |
- | <code java [enable_line_numbers=" | + | <yarncode |
- | public class CustomArmorMaterial implements | + | public class CustomArmorMaterial implements |
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}; | ||
Line 21: | Line 21: | ||
// For reference, Leather uses {1, 2, 3, 1}, and Diamond/ | // For reference, Leather uses {1, 2, 3, 1}, and Diamond/ | ||
} | } | ||
- | </code> | + | </yarncode> |
The next arguments are defined as follows (don't worry about the names, you'll see how we implement it below them): | The next arguments are defined as follows (don't worry about the names, you'll see how we implement it below them): | ||
- | - getDurability: how many hits can armor take before breaking. Uses the int we wrote on ' | + | - <yarn method_7696> |
- | - getProtectionAmount: calls for the ' | + | - <yarn method_7697> |
- | - getEnchantability: This will be how likely the armor can get high level or multiple enchantments in an enchantment book. | + | - <yarn method_7699> |
- | - SoundEvent getEquipSound: The standard used by vanilla armor is '' | + | - <yarn class_3414 method_7698> |
- | - 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. | + | - <yarn class_1856 method_7695> |
- | - String | + | - String |
- | - getToughness: This is a second protection value where the armor is more durable against high value attacks. Value goes as ' | + | - <yarn method_7700> |
And the new value introduced on 1.16 | And the new value introduced on 1.16 | ||
- | - getKnockbackResistance: leave this value at 0. If you want to implement it, write ' | + | - <yarn method_24355> |
I'll leave all variables written as X or A, B, C, D. With those arguments, it should now look something like this: | I'll leave all variables written as X or A, B, C, D. With those arguments, it should now look something like this: | ||
- | <code java [enable_line_numbers=" | + | <yarncode |
- | public class CustomArmorMaterial implements | + | public class CustomArmorMaterial implements |
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 | + | public int method_7696(class_1304 |
- | return BASE_DURABILITY[slot.getEntitySlotId()] * X; | + | return BASE_DURABILITY[slot.method_5927()] * X; |
} | } | ||
@Override | @Override | ||
- | public int getProtectionAmount(EquipmentSlot | + | public int method_7697(class_1304 |
- | 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 | + | public |
- | return | + | return |
} | } | ||
@Override | @Override | ||
- | public | + | public |
- | return | + | return |
} | } | ||
@Override | @Override | ||
- | public String | + | public String |
// Must be all lowercase | // Must be all lowercase | ||
return " | return " | ||
Line 76: | Line 76: | ||
@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> |
Line 94: | Line 94: | ||
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 " | 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 " | ||
- | The syntax of groups is //.group(YourModName.YOUR_MOD_NAME_BUT_IN_CAPS_GROUP)// | + | The syntax of groups is //.<yarn method_7892> |
- | <code java [enable_line_numbers=" | + | <yarncode |
public class RegisterItems { | public class RegisterItems { | ||
- | public static final ArmorMaterial | + | public static final class_1741 |
- | public static final Item CUSTOM_MATERIAL = new CustomMaterialItem(new | + | public static final class_1792 |
// 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 Item CUSTOM_MATERIAL_HELMET = new ArmorItem(CUSTOM_ARMOR_MATERIAL, | + | public static final class_1792 |
- | public static final Item CUSTOM_MATERIAL_CHESTPLATE = new ArmorItem(CUSTOM_ARMOR_MATERIAL, | + | public static final class_1792 |
- | public static final Item CUSTOM_MATERIAL_LEGGINGS = new ArmorItem(CUSTOM_ARMOR_MATERIAL, | + | public static final class_1792 |
- | public static final Item CUSTOM_MATERIAL_BOOTS = new ArmorItem(CUSTOM_ARMOR_MATERIAL, | + | public static final class_1792 |
} | } | ||
- | </code> | + | </yarncode> |
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. | 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. | ||
- | We'll be writing this right below your last ArmorItem. | + | We'll be writing this right below your last <yarn class_1738> |
- | <code java [enable_line_numbers=" | + | <yarncode |
public static void register() { | public static void register() { | ||
- | Registry.register(Registry.ITEM, new Identifier(" | + | class_2378.method_10230(class_2378.field_11142, new class_2960(" |
- | Registry.register(Registry.ITEM, new Identifier(" | + | |
- | Registry.register(Registry.ITEM, new Identifier(" | + | |
- | Registry.register(Registry.ITEM, new Identifier(" | + | |
- | Registry.register(Registry.ITEM, new Identifier(" | + | |
} | } | ||
- | </code> | + | </yarncode> |
Your armor items are done. Now we'll just call the Registry on our main class (and annotate the new group). | Your armor items are done. Now we'll just call the Registry on our main class (and annotate the new group). | ||
- | <code java [enable_line_numbers=" | + | <yarncode |
- | public static final ItemGroup | + | public static final class_1761 |
- | new Identifier(" | + | new class_2960(" |
- | .icon(() -> new ItemStack(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(); |
- | | + | @Override |
- | public void onInitialize() { | + | public void onInitialize() { |
- | RegisterItems.register(); | + | RegisterItems.register(); |
- | } | + | } |
- | </code> | + | </yarncode> |
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. | ||
Line 165: | Line 165: | ||
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 getName | + | 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> |
Line 175: | Line 175: | ||
And here comes the so very cursed! | And here comes the so very cursed! | ||
- | Mojang decided that they were not only going to hardcode | + | Mojang decided that they were not only going to hardcode |
- | To get around this, we're gonna make a mixin that goes into ArmorItem. If this is your first time, [[tutorial: | + | To get around this, we're gonna make a mixin that goes into <yarn class_1738> |
We'll make a class called ArmorItemMixin, | We'll make a class called ArmorItemMixin, | ||
- | <code java [enable_line_numbers:" | + | <yarncode |
- | @Mixin (ArmorItem.class) | + | @Mixin (class_1738.class) |
public abstract class ArmorItemMixin { | public abstract class ArmorItemMixin { | ||
} | } | ||
- | </code> | + | </yarncode> |
- | Now we have to make a @Shadow to modify knockbackResistance, | + | Now we have to make a @Shadow to modify knockbackResistance, |
- | <code java [enable_line_numbers:" | + | <yarncode |
- | @Mixin (ArmorItem.class) | + | @Mixin (class_1738.class) |
public abstract class ArmorItemMixin { | public abstract class ArmorItemMixin { | ||
@Shadow @Final private static UUID[] MODIFIERS; | @Shadow @Final private static UUID[] MODIFIERS; | ||
- | @Shadow @Final @Mutable private Multimap< | + | @Shadow @Final @Mutable private Multimap< |
@Shadow @Final protected float knockbackResistance; | @Shadow @Final protected float knockbackResistance; | ||
} | } | ||
- | </code> | + | </yarncode> |
- | Next we @Inject our GENERIC_KNOCKBACK_RESISTANCE | + | Next we @Inject our <yarn field_23718> |
- | <code java [enable_line_numbers:" | + | <yarncode |
- | @Mixin (ArmorItem.class) | + | @Mixin (class_1738.class) |
public abstract class ArmorItemMixin { | public abstract class ArmorItemMixin { | ||
@Shadow @Final private static UUID[] MODIFIERS; | @Shadow @Final private static UUID[] MODIFIERS; | ||
- | @Shadow @Final @Mutable private Multimap< | + | @Shadow @Final @Mutable private Multimap< |
@Shadow @Final protected float knockbackResistance; | @Shadow @Final protected float knockbackResistance; | ||
- | | + | |
@Inject(method = "< | @Inject(method = "< | ||
- | private void constructor(ArmorMaterial | + | private void constructor(class_1741 |
- | UUID uUID = MODIFIERS[slot.getEntitySlotId()]; | + | UUID uUID = MODIFIERS[slot.method_5927()]; |
- | if (material == RegisterItems.customArmorMaterial) { | + | if (material == RegisterItems.CUSTOM_ARMOR_MATERIAL) { |
- | ImmutableMultimap.Builder< | + | ImmutableMultimap.Builder< |
this.attributeModifiers.forEach(builder:: | this.attributeModifiers.forEach(builder:: | ||
builder.put( | builder.put( | ||
- | | + | |
- | new EntityAttributeModifier(uUID, | + | new class_1322(uUID, |
"Armor knockback resistance", | "Armor knockback resistance", | ||
this.knockbackResistance, | this.knockbackResistance, | ||
- | | + | |
) | ) | ||
); | ); | ||
Line 230: | Line 230: | ||
} | } | ||
} | } | ||
- | | + | |
} | } | ||
- | </code> | + | </yarncode> |
Now your armor has the knockback resistance value you assigned to it back on CustomArmorMaterial. | Now your armor has the knockback resistance value you assigned to it back on CustomArmorMaterial. |
tutorial/armor.txt · Last modified: 2023/08/20 10:19 by wjz_p