Help with mixin into ArmorMaterials interface #4888
-
DescriptionI wanted to change vanilla armor stats @Mixin(ArmorMaterials.class)
public interface MyMixin {
@Shadow
private static Map<EquipmentType, Integer> createDefenseMap(int bootsDefense, int leggingsDefense, int chestplateDefense, int helmetDefense, int bodyDefense) {
return Maps.newEnumMap(Map.of(EquipmentType.BOOTS, bootsDefense, EquipmentType.LEGGINGS, leggingsDefense, EquipmentType.CHESTPLATE, chestplateDefense, EquipmentType.HELMET, helmetDefense, EquipmentType.BODY, bodyDefense));
}
@Shadow
ArmorMaterial DIAMOND = new ArmorMaterial(
5, createDefenseMap(1, 1, 1, 1, 1), 15, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 0.0F, 0.0F, ItemTags.REPAIRS_DIAMOND_ARMOR, EquipmentAssetKeys.DIAMOND
);
} Nothing changes... I'm new to java, can someone please tell me what is wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The ideal solution depends on exactly what changes you want to make to diamond armour, but for a crude "I just want it to work, then I'll make it good" solution, look into This does silently clobber any changes made by other mods though, so it shouldn't be used for anything other than learning purposes. The ideal way to do this depends on exactly what changes you want to make. |
Beta Was this translation helpful? Give feedback.
-
Oh, I forgot that interface fields can only be final, so you can't write an interface mixin which assigns to an interface field because there's no way to make the code compile. Normally you'd have your shadow be
Initialise it to null. Shadow methods and fields are just "dummies" to make the code compile. |
Beta Was this translation helpful? Give feedback.
Oh, I forgot that interface fields can only be final, so you can't write an interface mixin which assigns to an interface field because there's no way to make the code compile. Normally you'd have your shadow be
@Final
instead offinal
, but the compiler addsfinal
, so that doesn't work for interface mixins.That makes this significantly more complicated. You'll need to use
@ModifyArgs
to change the arguments passed to the ArmorMaterial constructor call, using@ModifyArgs.slice
to restrict the scope of the@At
so it only targets the initialiser ofDIAMOND
.Initialise it to null. Shadow meth…