跳到主要内容

16自定义盔甲

定义盔甲枚举

定义盔甲枚举

public enum ModArmorMaterials implements ArmorMaterial {
RUBY("ruby", 25, new int[]{3, 6, 8, 3}, 19, SoundEvents.ITEM_ARMOR_EQUIP_NETHERITE,
2.0F, 0.1F, () -> Ingredient.ofItems(ModItems.RUBY)),
;

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 float knockbackResistance;
private final Supplier<Ingredient> repairIngredient;

private static final int[] BASE_DURABILITY = new int[]{11, 16, 15, 13};

ModArmorMaterials(String name, int durabilityMultiplier, int[] protectionAmounts, int enchantability, SoundEvent equipSound,
float toughness, float knockbackResistance, Supplier<Ingredient> repairIngredient) {
this.name = name;
this.durabilityMultiplier = durabilityMultiplier;
this.protectionAmounts = protectionAmounts;
this.enchantability = enchantability;
this.equipSound = equipSound;
this.toughness = toughness;
this.knockbackResistance = knockbackResistance;
this.repairIngredient = repairIngredient;
}

注册,头盔,胸甲,裤子,鞋子ModItems

public static final Item RUBY_HELMET = registerItem("ruby_helmet",
new ArmorItem(ModArmorMaterials.RUBY, ArmorItem.Type.HELMET, new FabricItemSettings()));
public static final Item RUBY_CHESTPLATE = registerItem("ruby_chestplate",
new ArmorItem(ModArmorMaterials.RUBY, ArmorItem.Type.CHESTPLATE, new FabricItemSettings()));
public static final Item RUBY_LEGGINGS = registerItem("ruby_leggings",
new ArmorItem(ModArmorMaterials.RUBY, ArmorItem.Type.LEGGINGS, new FabricItemSettings()));
public static final Item RUBY_BOOTS = registerItem("ruby_boots",
new ArmorItem(ModArmorMaterials.RUBY, ArmorItem.Type.BOOTS, new FabricItemSettings()));

添加到物品组

entries.add(ModItems.RUBY_HELMET);
entries.add(ModItems.RUBY_CHESTPLATE);
entries.add(ModItems.RUBY_LEGGINGS);
entries.add(ModItems.RUBY_BOOTS);

添加对应的json生成器:

ModItemTagProvider

@Override
protected void configure(RegistryWrapper.WrapperLookup arg) {
getOrCreateTagBuilder(ItemTags.TRIMMABLE_ARMOR)
.add(ModItems.RUBY_HELMET, ModItems.RUBY_CHESTPLATE, ModItems.RUBY_LEGGINGS, ModItems.RUBY_BOOTS);
}

ModModelProvider中:

itemModelGenerator.registerArmor(((ArmorItem) ModItems.RUBY_HELMET));
itemModelGenerator.registerArmor(((ArmorItem) ModItems.RUBY_CHESTPLATE));
itemModelGenerator.registerArmor(((ArmorItem) ModItems.RUBY_LEGGINGS));
itemModelGenerator.registerArmor(((ArmorItem) ModItems.RUBY_BOOTS));

效果

image-20240824213831989