Legacy Fabric-Api

Legacy Fabric-Api

70.5k Downloads

[1.7.10] Armor Registering and Rendering

Starexify opened this issue ยท 0 comments

commented

LFAPI Version: 1.11.1+1.7.10

When registering armor items it's a bit difficult so I made this process:
Registering the item using the basic item registration and for instancing it an set example would be:

public static Item MATERIAL_HELMET = registerItem("material_helmet", () -> new ArmorItem(ArmorMaterial.valueOf("MATERIAL"), <materialId>, 0));
public static Item MATERIAL_CHESTPLATE = registerItem("material_chestplate", () -> new ArmorItem(ArmorMaterial.valueOf("MATERIAL"), <materialId>, 1));
public static Item MATERIAL_LEGGINGS = registerItem("material_leggings", () -> new ArmorItem(ArmorMaterial.valueOf("MATERIAL"), <materialId>, 2));
public static Item MATERIAL_BOOTS = registerItem("material_boots", () -> new ArmorItem(ArmorMaterial.valueOf("MATERIAL"), <materialId>, 3));

the material ID is limted to the lenght of the String Array in BipedEntityRenderer so I had to mixin aswell and add my new name aswell in the Array with this Mixin:

@Mixin(BipedEntityRenderer.class)
public class BipedEntityRendererMixin {
    @Shadow @Final private static String[] field_5195;

    static {
        List<String> armorModelList = new ArrayList<>(Arrays.asList(field_5195));
        armorModelList.add("<material>");
        field_5195 = armorModelList.toArray(new String[0]);
    }
}

With this the materialId length will be +1 from the basic private static final String[] field_5195 = new String[]{"leather", "chainmail", "iron", "diamond", "gold"}; which is 5, so 5 -> 6.

Then I also had to add my material id with the modid into the method method_5759 from BipedEntityRenderer for rendering the armor layers from my namespace so inside the BipedEntityRendererMixin I added this:

@ModifyArg(method = "method_5759", at = @At(value = "INVOKE", target = "Ljava/lang/String;format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;"), index = 0)
private static String modifyArmorLayerLocation(String format, @Local(argsOnly = true) ArmorItem armorItem) {
    if (armorItem.materialId == <materialId>) return MODID + ":textures/models/armor/%s_layer_%d%s.png";
    return format;
}

Now the armor renders the textures from my namespace, the armor should show on the player aswell.
Last I mixin into ArmorMaterial to set repair item for the Armor:

@Mixin(ArmorMaterial.class)
public abstract class ArmorMaterialMixin {
    @ModifyReturnValue(method = "method_6339", at = @At("RETURN"))
    private Item modifyRepairItem(Item original) {
        if ((Object) this == ArmorMaterial.valueOf("MATERIAL")) return <Items.ITEM>;
        return original;
    }
}