1.12.2盔甲教程:Minecraft 1.12.2模组开发(八) 盔甲套装
今天我们准备在模组中实现自己的一套盔甲装备
1.在Java包中新建一个util包,里面新建我们的盔甲属性枚举类CustomArmorMaterial
CustomArmorMaterial.java
package com.joy187.re8joymod.util;
import java.util.function.Supplier;
import com.joy187.re8joymod.init.ItemInit;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.LazyLoadedValue;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
public enum CustomArmorMaterial implements ArmorMaterial{
//在这里添加我们的盔甲属性 new int[] 四个位置分别为头、护腿、胸甲、鞋子
ARMOR_MATERIAL_FRANKSUIT("franksuit", 80, new int[]{8, 13, 20, 12}, 35, SoundEvents.ARMOR_EQUIP_IRON, 7.0F, 0.8F, () -> {
return Ingredient.of(ItemInit.BLACKFEATHER.get());
}),
ARMOR_MATERIAL_HUMUSSUIT("humussuit", 80, new int[]{4, 6, 8, 4}, 25, SoundEvents.SLIME_BLOCK_PLACE, 1.5F, 0.2F, () -> {
return Ingredient.of(ItemInit.BLACKFEATHER.get());
});
private static final int[] baseDurability = { 13, 15, 16, 11 };
private final String name;
private final int durabilityMultiplier;
private final int[] armorVal;
private final int enchantability;
private final SoundEvent equipSound;
private final float toughness;
private final float knockbackResistance;
private final LazyLoadedValue<Ingredient> repairIngredient;
private CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorVal, int enchantability, SoundEvent equipSound,
float toughness, float knockbackResistance, Supplier<Ingredient> repairIngredient) {
//盔甲属性名称
this.name = name;
//耐久度
this.durabilityMultiplier = durabilityMultiplier;
//四个位置的护甲值
this.armorVal = armorVal;
//附魔能力(越大附魔结果越好)
this.enchantability = enchantability;
//穿上盔甲的音效
this.equipSound = equipSound;
//盔甲韧性
this.toughness = toughness;
//抗击退效果
this.knockbackResistance = knockbackResistance;
//维修盔甲的材料
this.repairIngredient = new LazyLoadedValue<>(repairIngredient);
}
@Override
public int getDurabilityForSlot(EquipmentSlot slot) {
return baseDurability[slot.getIndex()] * durabilityMultiplier;
}
@Override
public int getDefenseForSlot(EquipmentSlot slot) {
return this.armorVal[slot.getIndex()];
}
@Override
public int getEnchantmentValue() {
return this.enchantability;
}
@Override
public SoundEvent getEquipSound() {
return this.equipSound;
}
public Ingredient getRepairIngredient() {
return this.repairIngredient.get();
}
@Override
public String getName() {
return this.name;
}
@Override
public float getToughness() {
return this.toughness;
}
@Override
public float getKnockbackResistance() {
return this.knockbackResistance;
}
}
2.在ItemInit中添加我们的自定义套装
ItemInit.java
//头盔
public static final RegistryObject<Item> HUMUS_HELMET = ITEMS.register("humus_helmet",
() -> new ArmorItem(CustomArmorMaterial.ARMOR_MATERIAL_HUMUSSUIT,EquipmentSlot.HEAD,(new Item.Properties()).tab(Main.TUTORIAL_TAB)));
//胸甲
public static final RegistryObject<Item> HUMUS_CHESTPLATE = ITEMS.register("humus_chest",
() -> new ArmorItem(CustomArmorMaterial.ARMOR_MATERIAL_HUMUSSUIT,EquipmentSlot.CHEST,(new Item.Properties()).tab(Main.TUTORIAL_TAB)));
//护腿
public static final RegistryObject<Item> HUMUS_LEGGINGS = ITEMS.register("humus_leggings",
() -> new ArmorItem(CustomArmorMaterial.ARMOR_MATERIAL_HUMUSSUIT,EquipmentSlot.LEGS,(new Item.Properties()).tab(Main.TUTORIAL_TAB)));
//靴子
public static final RegistryObject<Item> HUMUS_BOOTS = ITEMS.register("humus_boots",
() -> new ArmorItem(CustomArmorMaterial.ARMOR_MATERIAL_HUMUSSUIT,EquipmentSlot.FEET,(new Item.Properties()).tab(Main.TUTORIAL_TAB)));
3.代码部分结束,来到资源包制作环节
在resources\assets\你的modid
中en_us.json
中添加我们盔甲的英文名称
"item.re8joymod.humus_helmet":"E Humus Helmet",
"item.re8joymod.humus_chest":"E Humus Chestplate",
"item.re8joymod.humus_leggings":"E Humus Leggings",
"item.re8joymod.humus_boots":"E Humus Boots",
在zh_cn.json
中添加中文名称:
"item.re8joymod.humus_helmet":"头盔名",
"item.re8joymod.humus_chest":"胸甲名",
"item.re8joymod.humus_leggings":"护腿名",
"item.re8joymod.humus_boots":"靴子名",
在models\items
包中添加四个盔甲部件的模型文件。
1.头盔
humus_helmet.json
{
"parent": "item/generated",
"textures": {
"layer0": "re8joymod:item/humus_helmet"
}
}
2.胸甲
humus_chest.json
{
"parent": "item/generated",
"textures": {
"layer0": "re8joymod:item/humus_chest"
}
}
3.护腿
humus_leggings.json
{
"parent": "item/generated",
"textures": {
"layer0": "re8joymod:item/humus_leggings"
}
}
4.靴子
humus_boots.json
{
"parent": "item/generated",
"textures": {
"layer0": "re8joymod:item/humus_boots"
}
}
在textures\item
中添加我们手持盔甲的贴图
在textures\models\armor
中添加我们穿上后的贴图