Minecraft升级到1.16.5后,3D盔甲的制作方法也跟之前版本稍有不同(主要在第二步、第四步),建议先复习一下往期教程:
Minecraft 1.12.2模组开发(三十七) 3D盔甲
1.在blockbench中制作我们的盔甲的模型和材质
注意修改版本为1.16(Mojmaps)
制作好后导出Java模型
将模型放入armor包中
2.对模型文件添加或修改几个函数
MirandaSuit.java
package com.joy187.re8joymod.common.items.armor;
// Made with Blockbench 3.9.3
// Exported for Minecraft version 1.15 - 1.16 with Mojang mappings
// Paste this class into your mod and generate all required imports
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.renderer.entity.model.BipedModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.inventory.EquipmentSlotType;
public class MirandaSuit extends BipedModel {
//和上期一样,bone是模型根目录
private final ModelRenderer bone;
private final ModelRenderer Body;
private final ModelRenderer Body_r1;
...(模型机密)
private final ModelRenderer Leftfrontlib;
public MirandaSuit() {
super(1F);
texWidth = 128;
texHeight = 128;
bone = new ModelRenderer(this);
bone.setPos(0.0F, 44.0F, 0.0F);
Body = new ModelRenderer(this);
Body.setPos(0.0F, -24.0F, 0.0F);
bone.addChild(Body);
Body.texOffs(44, 7).addBox(-6.0F, -19.0F, -6.0F, 12.0F, 12.0F, 11.0F, 0.0F, false);
Body.texOffs(44, 7).addBox(-5.0F, -20.0F, -5.0F, 10.0F, 1.0F, 10.0F, 0.0F, false);
Body.texOffs(86, 109).addBox(-6.0F, -19.0F, 5.0F, 12.0F, 18.0F, 2.0F, 0.0F, false);
Body.texOffs(46, 65).addBox(-6.0F, -7.0F, -6.0F, 11.0F, 8.0F, 9.0F, 0.0F, false);
Body_r1 = new ModelRenderer(this);
...
Leftfrontlib = new ModelRenderer(this);
Leftfrontlib.setPos(0.0F, 1.0F, -2.0F);
Leftlib.addChild(Leftfrontlib);
//添加这句话,说明是胸甲(头盔head,护腿、靴子leftLeg,rightLeg)
this.body.addChild(bone);
}
//这个函数很关键,直接整个复制
public final MirandaSuit applyEntityStats(BipedModel defaultArmor){
this.leftArmPose = defaultArmor.leftArmPose;
this.rightArmPose = defaultArmor.rightArmPose;
this.crouching = defaultArmor.crouching;
this.head.copyFrom(defaultArmor.head);
this.hat.copyFrom(defaultArmor.hat);
this.body.copyFrom(defaultArmor.body);
this.rightArm.copyFrom(defaultArmor.rightArm);
this.leftArm.copyFrom(defaultArmor.leftArm);
this.rightLeg.copyFrom(defaultArmor.rightLeg);
this.leftLeg.copyFrom(defaultArmor.leftLeg);
return this;
}
//这个函数也很关键,直接整个复制
@Override
public void copyPropertiesTo(BipedModel p_217148_1_) {
super.copyPropertiesTo(p_217148_1_);
p_217148_1_.leftArmPose = this.leftArmPose;
p_217148_1_.rightArmPose = this.rightArmPose;
p_217148_1_.crouching = this.crouching;
p_217148_1_.head.copyFrom(this.head);
p_217148_1_.hat.copyFrom(this.hat);
p_217148_1_.body.copyFrom(this.body);
p_217148_1_.rightArm.copyFrom(this.rightArm);
p_217148_1_.leftArm.copyFrom(this.leftArm);
p_217148_1_.rightLeg.copyFrom(this.rightLeg);
p_217148_1_.leftLeg.copyFrom(this.leftLeg);
}
//这个函数决定盔甲部位,
public BipedModel applySlot(EquipmentSlotType slot){
bone.visible = false;
switch(slot){
//这里的CHEST说明我们的盔甲是胸甲,头盔HEAD,护腿LEGS,靴子FEET
case CHEST:
bone.visible = true;
break;
default:
break;
}
return this;
}
//这个函数也很关键,直接整个复制
@Override
public void renderToBuffer(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){
bone.render(matrixStack, buffer, packedLight, packedOverlay);
}
//这个函数也很关键,直接整个复制
public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
modelRenderer.xRot = x;
modelRenderer.yRot = y;
modelRenderer.zRot = z;
}
//这个函数也很关键,直接整个复制
private final void copyModelAngles(ModelRenderer in, ModelRenderer out){
out.xRot = in.xRot;
out.yRot = in.yRot;
out.zRot = in.zRot;
}
}
3.在armor包中新建一个盔甲物品定义类ArmorMirandaSuit
ArmorMirandaSuit.java
package com.joy187.re8joymod.common.items.armor;
import com.joy187.re8joymod.common.init.ModItems;
import net.minecraft.client.renderer.entity.model.BipedModel;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.world.World;
public class ArmorMirandaSuit extends ArmorItem {
//定义一个我们第二步中的盔甲类
private MirandaSuit mirandaSuitModel;
//仿照这样写
public ArmorMirandaSuit(IArmorMaterial material, EquipmentSlotType equipmentSlot, Item.Properties properties, MirandaSuit armorModel) {
super(material, equipmentSlot, properties);
this.mirandaSuitModel = armorModel;
}
@Override
public final BipedModel getArmorModel(LivingEntity entity, ItemStack itemStack, EquipmentSlotType armorSlot, BipedModel defaultArmor) {
this.mirandaSuitModel.copyPropertiesTo(defaultArmor);
//最后EquipmentSlotType是我们穿戴的部位:胸甲CHEST,头盔HEAD,护腿LEGS,靴子FEET
return mirandaSuitModel.applyEntityStats(defaultArmor).applySlot(EquipmentSlotType.CHEST);
}
//定义穿上盔甲的效果
@OnlyIn(Dist.CLIENT)
@Override
public void onArmorTick(ItemStack stack, World world, PlayerEntity player) {
if(player.getItemBySlot(EquipmentSlotType.CHEST).getItem() == ModItems.MIRANDA_SUIT.get())
{
player.addEffect(new EffectInstance(Effects.DIG_SPEED,10,3,false,false));
player.addEffect(new EffectInstance(Effects.REGENERATION,10,3,true,true));
}
super.onArmorTick(stack,world, player);
}
}
4.新建一个盔甲属性类用于存放所有模组的盔甲属性:
CustomArmorMaterial.java
public enum CustomArmorMaterial implements IArmorMaterial {
ARMOR_MATERIAL_FRANKSUIT("franksuit", 80, new int[] {8, 13, 20, 12}, 35, SoundEvents.ARMOR_EQUIP_IRON, 7.0F, 0.8F, () -> Ingredient.of(ModItems.MACHINEHEARTS.get())),
ARMOR_MATERIAL_MIRANDASUIT("mirandasuit", 150, new int[] {20, 40, 48, 28}, 95, SoundEvents.ARMOR_EQUIP_NETHERITE, 10.0F, 0.8F, () -> Ingredient.of(ModItems.BLACKFEATHER.get())),
ARMOR_MATERIAL_MIRANDA1SUIT("miranda1suit", 160, new int[] {20, 49, 40, 28}, 125, SoundEvents.ARMOR_EQUIP_NETHERITE, 15.0F, 0.9F, () -> Ingredient.of(ModItems.BLACKFEATHER.get())),
//可以添加续写
ARMOR_MATERIAL_DIMI1SUIT("dimi1suit", 120, new int[] {15, 35, 25, 20}, 75, SoundEvents.ARMOR_EQUIP_NETHERITE, 10.0F, 0.6F, () -> Ingredient.of(ModItems.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 Ingredient repairIngredient;
/**
* Constructor that adds the armormaterial
* @param name Armor name
* @param durabilityMultiplier Armor durability multiplier
* @param armorVal Armor values per body part
* @param enchantability Armor enchantability
* @param equipSound Armor equipping sound
* @param toughness Armor toughness points
* @param knockbackResistance Armor knockback resistance
* @param repairIngredient Armor repair item
*/
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 = repairIngredient.get();
}
/**
* Gets the durability for a certain slot
* @param slot Armor slot
* @return Base durability times multiplier for that slot
*/
@Override
public int getDurabilityForSlot(EquipmentSlotType slot) {
return baseDurability[slot.getIndex()] * durabilityMultiplier;
}
/**
* Gets the defense for a certain slot
* @param slot Armor slot
* @return Armor value for that slot
*/
@Override
public int getDefenseForSlot(EquipmentSlotType slot) {
return this.armorVal[slot.getIndex()];
}
/**
* Gets the enchantability for a certain armor
* @return Enchantability value
*/
@Override
public int getEnchantmentValue() {
return this.enchantability;
}
/**
* Gets the equip sound for a certain armor
* @return Equip sound
*/
@Override
public SoundEvent getEquipSound() {
return this.equipSound;
}
/**
* Gets the repair item for a certain armor
* @return Repair item
*/
@Override
public Ingredient getRepairIngredient() {
return this.repairIngredient;
}
/**
* Gets the name for a certain armor
* @return Name
*/
@Override
public String getName() {
return this.name;
}
/**
* Gets the toughness value for a certain armor
* @return Toughness value
*/
@Override
public float getToughness() {
return this.toughness;
}
/**
* Gets the knockback resistance for a certain armor
* @return Knockback resistance value
*/
@Override
public float getKnockbackResistance() {
return this.knockbackResistance;
}
}
5.在ModItems.java中声明我们的盔甲
//盔甲声明 参数:盔甲名称字符串,盔甲属性(上一步中定义,在这里引用),盔甲穿戴部位,盔甲放在哪个物品栏,盔甲类(第二步中的)
public static final RegistryObject<Item> MIRANDA_SUIT = ITEMS.register("mirandasuit",
() -> new ArmorMirandaSuit(CustomArmorMaterial.ARMOR_MATERIAL_MIRANDA1SUIT,EquipmentSlotType.CHEST,(new Item.Properties()).tab(RegistryEvents.RE8GROUP),new MirandaSuit()) );
6.找到resources包中assets包
1.assets\minecraft\textures\models\armor中添加盔甲穿戴后贴图
2.assets\你的模组名称文件夹下:
en_us.json中添加物品游戏内英文名称
"item.re8joymod.mirandasuit":"Miranda's Suit",
在models/item中新建一个模型文件mirandasuit.json
{
"parent": "item/generated",
"textures": {
"layer0": "re8joymod:items/mirandasuit"
}
}
textures/models/armor包中添加盔甲贴图,textures/items中添加物品手持贴图
6.保存所有文件,刷新项目 -> 启动MC