Minecraft Fabric 教程 #9 添加盔甲

首发于Enaium的个人博客


创建一个盔甲类

public class EndArmorMaterials implements ArmorMaterial {
    [...]
}

复制一下内容

    private static final int[] BASE_DURABILITY = {13, 15, 16, 11};
    private final String name;
    private final int durabilityMultiplier;
    private final int[] protectionAmounts;
    private final int enchantability;
    private final SoundEvent equipSound;
    private final float toughness;
    private final Lazy<Ingredient> repairIngredientSupplier;

    public EndArmorMaterials(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairIngredient) {
        this.name = name;
        this.durabilityMultiplier = durabilityMultiplier;
        this.protectionAmounts = armorValueArr;
        this.enchantability = enchantability;
        this.equipSound = soundEvent;
        this.toughness = toughness;
        this.repairIngredientSupplier = new Lazy(repairIngredient);
    }

    public int getDurability(EquipmentSlot equipmentSlot_1) {
        return BASE_DURABILITY[equipmentSlot_1.getEntitySlotId()] * this.durabilityMultiplier;
    }

    public int getProtectionAmount(EquipmentSlot equipmentSlot_1) {
        return this.protectionAmounts[equipmentSlot_1.getEntitySlotId()];
    }

    public int getEnchantability() {
        return this.enchantability;
    }

    public SoundEvent getEquipSound() {
        return this.equipSound;
    }

    public Ingredient getRepairIngredient() {
        return this.repairIngredientSupplier.get();
    }

    @Environment(EnvType.CLIENT)
    public String getName() {
        return this.name;
    }

    public float getToughness() {
        return this.toughness;
    }

然后把class 改成 enum

制作盔甲材料

public enum EndArmorMaterials implements ArmorMaterial {



    END("end_heart" , 15 , new int[]{1,3,2,1}, 15, SoundEvents.BLOCK_WOOL_PLACE,0.0F, () -> {
        return Ingredient.ofItems(Items.WHITE_WOOL);
    });

    [...]
}

参数一 材料名字 参数二 耐久倍数 参数三 盔甲数也就是穿上盔甲加的盔甲值 参数四 使用的时候发出的声音 参数五 耐性

创建盔甲物品

    public static final Item END_HELMET = new ArmorItem(EndArmorMaterials.END, EquipmentSlot.HEAD, (new Item.Settings().group(ItemGroup.COMBAT)));
    public static final Item END_CHESTPLATE = new ArmorItem(EndArmorMaterials.END, EquipmentSlot.CHEST, (new Item.Settings().group(ItemGroup.COMBAT)));
    public static final Item END_LEGGINGS = new ArmorItem(EndArmorMaterials.END, EquipmentSlot.LEGS, (new Item.Settings().group(ItemGroup.COMBAT)));
    public static final Item END_BOOTS = new ArmorItem(EndArmorMaterials.END, EquipmentSlot.FEET, (new Item.Settings().group(ItemGroup.COMBAT)));

注册盔甲物品

    Registry.register(Registry.ITEM,new Identifier("endarmor","end_helmet"), END_HELMET);
    Registry.register(Registry.ITEM,new Identifier("endarmor","end_chestplate"), END_CHESTPLATE);
    Registry.register(Registry.ITEM,new Identifier("endarmor","end_leggings"), END_LEGGINGS);
    Registry.register(Registry.ITEM,new Identifier("endarmor","end_boots"), END_BOOTS);

添加纹理

先添加物品纹理

end_helmet.png

end_chestplate.png

end_leggings.png

end_boots.png

发现只有物品纹理穿上后没有模型纹理然后添加模型

位置 srcmainresourcesassetsminecrafttexturesmodelsarmor

一共有两层end_heart_layer_1.png 和 end_heart_layer_2.png

end_heart_layer_1.png

end_heart_layer_2.png

最终效果

9-1.jpg

9 声望
0 粉丝
0 条评论
推荐阅读
Jimmer VS MyBatisPlus查询自关联表
对象抓取器是 jimmer-sql 一个非常强大的特征,具备可媲美 GraphQL 的能力。即使用户不采用任何 GraphQL 相关的技术栈,也能在 SQL 查询层面得到和 GraphQL 相似的对象图查询能力。

Enaium

Java8的新特性
Java语言特性系列Java5的新特性Java6的新特性Java7的新特性Java8的新特性Java9的新特性Java10的新特性Java11的新特性Java12的新特性Java13的新特性Java14的新特性Java15的新特性Java16的新特性Java17的新特性Java...

codecraft32阅读 27.4k评论 1

一文彻底搞懂加密、数字签名和数字证书!
微信搜索🔍「编程指北」,关注这个写干货的程序员,回复「资源」,即可获取后台开发学习路线和书籍来源:个人CS学习网站:[链接]前言这本是 2020 年一个平平无奇的周末,小北在家里刷着 B 站,看着喜欢的 up 主视...

编程指北71阅读 33.4k评论 20

Java11的新特性
Java语言特性系列Java5的新特性Java6的新特性Java7的新特性Java8的新特性Java9的新特性Java10的新特性Java11的新特性Java12的新特性Java13的新特性Java14的新特性Java15的新特性Java16的新特性Java17的新特性Java...

codecraft28阅读 19.2k评论 3

Java5的新特性
Java语言特性系列Java5的新特性Java6的新特性Java7的新特性Java8的新特性Java9的新特性Java10的新特性Java11的新特性Java12的新特性Java13的新特性Java14的新特性Java15的新特性Java16的新特性Java17的新特性Java...

codecraft13阅读 21.7k

Java9的新特性
Java语言特性系列Java5的新特性Java6的新特性Java7的新特性Java8的新特性Java9的新特性Java10的新特性Java11的新特性Java12的新特性Java13的新特性Java14的新特性Java15的新特性Java16的新特性Java17的新特性Java...

codecraft20阅读 15.2k

Java13的新特性
Java语言特性系列Java5的新特性Java6的新特性Java7的新特性Java8的新特性Java9的新特性Java10的新特性Java11的新特性Java12的新特性Java13的新特性Java14的新特性Java15的新特性Java16的新特性Java17的新特性Java...

codecraft17阅读 11.1k

9 声望
0 粉丝
宣传栏