本篇教程参考为的NeoForge1.20.4Mod开发的视频,这篇教程是我边学边总结的,与其说是教程更像我的学习笔记,如有不清楚的地方,大家可以在评论区提问。在我力所能及的范围内,我都会解答的。
设计新护甲材料
创建ModArmorMaterial类
public enum ModArmorMaterial implements ArmorMaterial {
RUBY("ruby",33,Util.make(new EnumMap<>(ArmorItem.Type.class),typeIntegerEnumMap ->{
typeIntegerEnumMap.put(ArmorItem.Type.BOOTS,3);
typeIntegerEnumMap.put(ArmorItem.Type.LEGGINGS,6);
typeIntegerEnumMap.put(ArmorItem.Type.CHESTPLATE,8);
typeIntegerEnumMap.put(ArmorItem.Type.HELMET,3);
}),10, SoundEvents.ARMOR_EQUIP_DIAMOND,2,0,()->Ingredient.of(ModItems.RUBY.get()));
private static final EnumMap<ArmorItem.Type,Integer> HEALTH_FUNCTION_FOR_TYPE= Util.make(new EnumMap<>(ArmorItem.Type.class),typeIntegerEnumMap -> {
typeIntegerEnumMap.put(ArmorItem.Type.BOOTS,13);//数字为耐久度
typeIntegerEnumMap.put(ArmorItem.Type.CHESTPLATE,16);
typeIntegerEnumMap.put(ArmorItem.Type.HELMET,11);
typeIntegerEnumMap.put(ArmorItem.Type.LEGGINGS,15);
});
private final String name;//铠甲材质的名称
private final int durabilityMultiplier;//耐久度乘数
private final EnumMap<ArmorItem.Type,Integer> protectionFunctionForType;//护甲值
private final int enchantmentValue;//附魔值
private final SoundEvent sound;//装备时的声音
private final float toughness;//韧性
private final float knockbackResistance;//击退抗性
private final LazyLoadedValue<Ingredient> repairIngredient;//修复材料
private ModArmorMaterial(String name,
int durabilityMultiplier,
EnumMap<ArmorItem.Type,Integer> protectionFunctionForType,
int enchantmentValue,
SoundEvent sound,
float toughness,
float knockbackResistance,
Supplier<Ingredient> repairIngredient)
{
this.name=name;
this.durabilityMultiplier=durabilityMultiplier;
this.protectionFunctionForType=protectionFunctionForType;
this.enchantmentValue=enchantmentValue;
this.sound=sound;
this.toughness=toughness;
this.knockbackResistance=knockbackResistance;
this.repairIngredient=new LazyLoadedValue<>(repairIngredient);
}
@Override
public int getDurabilityForType(ArmorItem.@NotNull Type type) {//计算并返回耐久值
return HEALTH_FUNCTION_FOR_TYPE.get(type)*this.durabilityMultiplier;
}
@Override
public int getDefenseForType(ArmorItem.@NotNull Type type) {//返回护甲值
return this.protectionFunctionForType.get(type);
}
@Override
public int getEnchantmentValue() {//返回附魔值
return this.enchantmentValue;
}
@Override
public @NotNull SoundEvent getEquipSound() {//返回装备时的声音
return this.sound;
}
@Override
public @NotNull Ingredient getRepairIngredient() {//返回修复材料
return this.repairIngredient.get();
}
@Override
public @NotNull String getName() {//返回名称
return this.name;
}
@Override
public float getToughness() {//返回韧性
return this.toughness;
}
@Override
public float getKnockbackResistance() {//返回击退抗性
return this.knockbackResistance;
}
}
创建盔甲
在ModItems类中
public static final Supplier<Item> RUBY_HELMET = ITEMS.register("ruby_helmet", () -> new ArmorItem(ModArmorMaterial.RUBY, ArmorItem.Type.HELMET, (new Item.Properties())));
public static final Supplier<Item> RUBY_CHESTPLATE = ITEMS.register("ruby_chestplate", () -> new ArmorItem(ModArmorMaterial.RUBY, ArmorItem.Type.CHESTPLATE, (new Item.Properties())));
public static final Supplier<Item> RUBY_LEGGINGS =ITEMS.register("ruby_leggings", () -> new ArmorItem(ModArmorMaterial.RUBY, ArmorItem.Type.LEGGINGS, (new Item.Properties())));
public static final Supplier<Item> RUBY_BOOTS =ITEMS.register("ruby_boots", () -> new ArmorItem(ModArmorMaterial.RUBY, ArmorItem.Type.BOOTS, (new Item.Properties())));
添加材质和模型
模型的数据生成
this.basicItem(ModItems.RUBY_BOOTS.get());
this.basicItem(ModItems.RUBY_HELMET.get());
this.basicItem(ModItems.RUBY_LEGGINGS.get());
this.basicItem(ModItems.RUBY_PICKAXE.get());
材质需要新建minecraft目录,不能用自己的命名空间。物品材质图片需要放在自己的命名空间

这里的layer是盔甲在身上显示的贴图,不知道画法的可以用解压软件打开原版的jar文件,在相同的路径可以找到
命名规则:材料名称_layer_1/2
类介绍
ArmorItem类
实例变量:
-
type:表示铠甲的类型(头盔、胸甲、裤子、靴子)。这个字段由枚举ArmorItem.Type定义 -
defense:该铠甲的防御值(由ArmorMaterial提供) -
toughness:铠甲的耐性值(由ArmorMaterial提供),用于减少受到伤害时的效果 -
knockbackResistance:铠甲的击退抵抗力(由ArmorMaterial提供) -
material:该铠甲的材质(ArmorMaterial类型),决定了防御、耐性、附魔值等属性 -
defaultModifiers:默认的属性修改器(如防御、耐性、击退抵抗力),它通过Attribute和AttributeModifier来为铠甲定义加成
静态方法:
public static boolean dispenseArmor(BlockSource blockSource, ItemStack armorItem):该方法用于将铠甲物品投掷到地面并装备到最近的实体身上
实例方法:
-
getType:返回铠甲的类型(如头盔、胸甲等) -
getEnchantmentValue:返回铠甲的附魔值,用于控制附魔效果的强度 -
getMaterial:返回铠甲的材质(如ruby) -
isValidRepairItem:判断铠甲是否可以在铁砧中修复。如果铠甲的修复物品与传入的修复物品匹配,则返回true -
use:处理物品的右键使用行为,通常是将物品与玩家的装备槽进行交换 -
getDefaultAttributeModifiers:返回与装备相关的属性修改器(例如增加防御、耐性等) -
getDefense:返回该铠甲的防御值 -
getToughness:返回该铠甲的耐性值 -
getEquipmentSlot:返回该铠甲对应的装备槽位(头盔、胸甲、裤子、靴子) -
getEquipSound







暂无评论内容