有小伙伴询问如何在模组中制作3D的盔甲并实装,那么我们今天就来做一件3D的盔甲
首先建议回顾一下之前关于盔甲的教程Minecraft 1.12.2模组开发(八) 盔甲套装
1.首先我们需要制作一套盔甲和盔甲穿在身上的贴图,可以使用blockbench进行制作:
相关教程
我们的模型要设定为实体类,同时导出类型为1.7~1.13
模型做好后导出模型为Java文件:
将导出的文件放入我们开发包中的armor文件夹
注意,我们要对导出的文件添加一些语句,让它继承ModelBiped(骨骼)类,同时在我们模型的最后一句添加 this.bipedBody.addChild(bone);
,表示让我们的盔甲随着身体模型一起运动,最后添加render和setRotationAngle两个函数。
记住我们模型的根目录,下面要用到
mirandaSuit.java
// Made with Blockbench 3.8.4
// Exported for Minecraft version 1.7 - 1.12
// Paste this class into your mod and generate all required imports
package com.joy187.rejoymod.item.armor;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelBox;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
//继承ModelBiped类
public class MirandaSuit extends ModelBiped {
//这个总的模型根目录类型为public,名称为bone
public final ModelRenderer bone;
private final ModelRenderer Body;
private final ModelRenderer Body_r1;
private final ModelRenderer Body_r2;
private final ModelRenderer Body_r3;
private final ModelRenderer Body_r4;
private final ModelRenderer swi2;
private final ModelRenderer Body_r5;
private final ModelRenderer Body_r6;
private final ModelRenderer swi;
private final ModelRenderer Body_r7;
private final ModelRenderer Body_r8;
private final ModelRenderer cir;
//...
private final ModelRenderer Body_r9;
private final ModelRenderer Body_r10;
private final ModelRenderer Body_r11;
private final ModelRenderer Body_r12;
private final ModelRenderer Body_r13;
private final ModelRenderer Body_r14;
private final ModelRenderer Body_r15;
private final ModelRenderer Body_r16;
private final ModelRenderer Body_r17;
private final ModelRenderer Body_r18;
public MirandaSuit() {
textureWidth = 128;
textureHeight = 128;
bone = new ModelRenderer(this);
bone.setRotationPoint(0.0F, 46.0F, 0.0F);
Body = new ModelRenderer(this);
Body.setRotationPoint(0.0F, -24.0F, 0.0F);
bone.addChild(Body);
Body.cubeList.add(new ModelBox(Body, 44, 7, -6.0F, -19.0F, -6.0F, 12, 12, 11, 0.0F, false));
Body.cubeList.add(new ModelBox(Body, 44, 7, -5.0F, -20.0F, -5.0F, 10, 1, 10, 0.0F, false));
Body.cubeList.add(new ModelBox(Body, 86, 109, -6.0F, -19.0F, 5.0F, 12, 18, 2, 0.0F, false));
Body.cubeList.add(new ModelBox(Body, 46, 65, -6.0F, -7.0F, -6.0F, 11, 8, 9, 0.0F, false));
Body_r1 = new ModelRenderer(this);
Body_r1.setRotationPoint(0.5F, -13.0F, -3.5F);
Body.addChild(Body_r1);
setRotationAngle(Body_r1, -0.6109F, 0.0F, 0.0F);
Body_r1.cubeList.add(new ModelBox(Body_r1, 44, 7, -5.0F, -4.0F, -3.5F, 9, 6, 5, 0.0F, false));
Body_r2 = new ModelRenderer(this);
Body_r2.setRotationPoint(-0.5F, -19.5F, 5.0F);
Body.addChild(Body_r2);
setRotationAngle(Body_r2, 0.3927F, 0.0F, 0.0F);
Body_r2.cubeList.add(new ModelBox(Body_r2, 86, 109, -2.5F, -0.5F, -1.0F, 5, 3, 2, 0.0F, false));
Body_r3 = new ModelRenderer(this);
Body_r3.setRotationPoint(9.5F, -19.0F, -2.0F);
Body.addChild(Body_r3);
setRotationAngle(Body_r3, 0.0F, 0.0F, -0.1745F);
Body_r3.cubeList.add(new ModelBox(Body_r3, 38, 38, -3.5F, -1.0F, -3.0F, 5, 2, 6, 0.0F, true));
// ...
Leftfrontlib = new ModelRenderer(this);
Leftfrontlib.setRotationPoint(0.0F, 1.0F, -2.0F);
Leftlib.addChild(Leftfrontlib);
//让身体的骨骼添加我们的模型
this.bipedBody.addChild(bone);
}
//添加这两个函数
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
super.render(entity, f, f1, f2, f3, f4, f5);
}
public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
modelRenderer.rotateAngleX = x;
modelRenderer.rotateAngleY = y;
modelRenderer.rotateAngleZ = z;
}
}
2.模型文件放好后就是对模型与我们的角色产生关联:
先写一个接口类: IHasModel.java
package com.joy187.rejoymod.util;
public interface IHasModel {
public void registerModels();
}
然后新建一个文件ArmorMirandaSuit.java:
ArmorMirandaSuit.java
package com.joy187.rejoymod.item.armor;
import com.joy187.rejoymod.IdlFramework;
import com.joy187.rejoymod.item.ModItems;
import com.joy187.rejoymod.util.IHasModel;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
//类继承ItemArmor 使用 IhasModel接口
public class ArmorMirandaSuit extends ItemArmor implements IHasModel {
public ArmorMirandaSuit(String name, CreativeTabs tab, ItemArmor.ArmorMaterial materialIn, EntityEquipmentSlot equipmentSlotIn) {
super(materialIn, 1, equipmentSlotIn);
setUnlocalizedName(name);
setRegistryName(name);
setCreativeTab(tab);
setMaxStackSize(1);
ModItems.ITEMS.add(this) ;
}
@Override
public void registerModels() {
IdlFramework.proxy.registerItemRenderer(this, 0, "inventory");
}
@Override
public ModelBiped getArmorModel(EntityLivingBase entity, ItemStack itemStack, EntityEquipmentSlot armorSlot, ModelBiped _default) {
if(!itemStack.isEmpty())
{
if(itemStack.getItem() instanceof ItemArmor)
{
//使用我们刚刚的模型
MirandaSuit model = new MirandaSuit();
//模型应用在胸甲上armorSlot.CHEST,其他的分别是HEAD(头盔),LEGS(护腿),FEET(靴子)
model.bone.showModel = armorSlot == armorSlot.CHEST;
model.leftArmPose = _default.leftArmPose;
model.rightArmPose = _default.rightArmPose;
model.isChild = _default.isChild;
model.isRiding= _default.isRiding;
model.isSneak = _default.isSneak;
return model;
}
}
return null;
//.applyEntityStats(defaultArmor).applySlot(EquipmentSlotType.HEAD);
}
//可以设置穿上盔甲后新增什么效果,我这里是穿上就拥有急迫Ⅳ和生命恢复Ⅳ
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack){
if(player.inventory.armorItemInSlot(2).getItem() == ModItems.MIRANDASUIT &&
player.inventory.armorItemInSlot(2)!=null) {
effectPlayer(player, MobEffects.HASTE, 0, 3);
effectPlayer(player, MobEffects.REGENERATION, 0, 3);
}
super.onArmorTick(world, player, itemStack);
}
//盔甲效果函数
private void effectPlayer(EntityPlayer player, Potion effect, int duration, int amplifier) {
if(player.getActivePotionEffect(effect)==null || player.getActivePotionEffect(effect).getDuration() <=1) {
player.addPotionEffect(new PotionEffect(effect, duration, amplifier, false, true));
}
}
}
3.找到ModItems.java(声明所有物品(item)的文件),在这里新建一个我们的盔甲的属性,同时声明我们的盔甲:
//盔甲属性声明,注意这个miranda1suit字符串,下面要用到,其他参数的意思参照第八期盔甲教程
public static final ItemArmor.ArmorMaterial ARMOR_MATERIAL_MIRANDA1SUIT = EnumHelper.addArmorMaterial("armor_material_miranda1suit", Reference.Mod_ID + ":miranda1suit", 150, new int[]{20, 40, 50, 22}, 105, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 15.0F);
//我们的盔甲物品 参数:套装名称, 放在哪个物品栏,盔甲属性,是什么部位的盔甲
public static final Item MIRANDASUIT = new ArmorMirandaSuit("mirandasuit", IdlFramework.ITEM_TAB, ARMOR_MATERIAL_MIRANDA1SUIT, EntityEquipmentSlot.CHEST);
4.找到resources包中的lang文件添加我们游戏中的物品名称
en_us.lang
item.mirandasuit.name=Miranda's Suit
进入models包中的item包,新建一个物品模型.json文件
mirandasuit.java
{
"parent": "item/generated",
"textures": {
"layer0": "rejoymod:items/mirandasuit"
}
}
进入textures包中的items包,添加我们的物品贴图.png文件(拿在手上的贴图,名称和.json文件中的一致)
进入textures包中的models\armor包中,添加我们的盔甲贴图.png文件(穿在身上的贴图,名称和第三步中的盔甲属性中的保持一致)
5.刷新项目,启动MC
手持时的贴图正常显示
建议把mc展示成果放到最前面
好的,谢谢。