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 revisionBoth sides next revision
tutorial:armor [2022/06/12 08:38] – [Texturing] technici4ntutorial:armor [2022/06/24 07:17] – Remove [Adding Knockback Protection] as FAPI 0.55.1 obsoletes it daomephsta
Line 171: Line 171:
  
 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.txt · Last modified: 2023/08/20 10:19 by wjz_p