Minecraft 1.16.5模组开发3D盔甲

Minecraft 1.12.2模组开发3D盔甲

我们本次在1.18.2的版本中实现具有动画效果的3D盔甲

1.首先,为了实现这些效果,我们需要首先使用到一个模组:geckolib(下载地址)

找到项目的build.gradle文件,在repositoriesdependencies中添加依赖。

repositories {//添加这个maven { url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/' }}
dependencies {minecraft 'net.minecraftforge:forge:1.18.2-40.1.0'//添加这个implementation fg.deobf('software.bernie.geckolib:geckolib-1.18-forge:3.0.18')}

之后我们重新构建gradle项目

构建好了项目后在项目的Main类中添加一句geckolib的初始化语句:

Main.java

 public Main() {IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();ItemInit.ITEMS.register(bus);//添加GeckoLib初始化函数GeckoLib.initialize();MinecraftForge.EVENT_BUS.register(this);}

2.之后,与之前的教程一样,我们需要在blockbench中制作一个模组中的3D盔甲:

进入软件后我们要找到一个插件按钮,然后再搜索栏中输入GeckoLib Animation Utils,并下载这个插件

将我们制作好的生物实体进行模型转换工作,找到Convert Project,之后选择Geckolib Animated Model

在这之后,你会发现你的生物实体栏多了一个Animate栏,点击进去:

具体动作制作的视频:Blockbench动画制作

注:我们的盔甲的要完全按照这种进行制作:

在制作好所有的动画后我们导出模型和动画json文件。

3.模型制作完成,接下来需要制作我们的盔甲类

在items包中新建armor包 -> armor包中新建我们的套装类HeisensuitArmorItem

HeisensuitArmorItem.java

package com.joy187.re8joymod.items.armor;import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;import com.google.common.collect.ImmutableMap;
import com.joy187.re8joymod.Main;
import com.joy187.re8joymod.init.EffectInit;
import com.joy187.re8joymod.init.ItemInit;
import com.joy187.re8joymod.util.CustomArmorMaterial;import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.PlayState;
import software.bernie.geckolib3.core.builder.AnimationBuilder;
import software.bernie.geckolib3.core.controller.AnimationController;
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
import software.bernie.geckolib3.core.manager.AnimationData;
import software.bernie.geckolib3.core.manager.AnimationFactory;
import software.bernie.geckolib3.item.GeoArmorItem;public class HeisensuitArmorItem extends GeoArmorItem implements IAnimatable{private AnimationFactory factory = new AnimationFactory(this);public HeisensuitArmorItem(ArmorMaterial materialIn, EquipmentSlot slot, Properties builder) {super(materialIn, slot, builder.tab(Main.TUTORIAL_TAB));}//动画状态机,判断每个时刻我们的盔甲的动画状态@SuppressWarnings("unused")private <P extends IAnimatable> PlayState predicate(AnimationEvent<P> event) {// This is all the extradata this event carries. The livingentity is the entity// that's wearing the armor. The itemstack and equipmentslottype are self// explanatory.List<EquipmentSlot> slotData = event.getExtraDataOfType(EquipmentSlot.class);List<ItemStack> stackData = event.getExtraDataOfType(ItemStack.class);LivingEntity livingEntity = event.getExtraDataOfType(LivingEntity.class).get(0);// Always loop the animation but later on in this method we'll decide whether or// not to actually play itevent.getController().setAnimation(new AnimationBuilder().addAnimation("animation.heisensuit.idle", true));// If the living entity is an armorstand just play the animation nonstopif (livingEntity instanceof ArmorStand) {return PlayState.CONTINUE;}// The entity is a player, so we want to only play if the player is wearing the// full set of armorelse if (livingEntity instanceof Player) {Player player = (Player) livingEntity;// Get all the equipment, aka the armor, currently held item, and offhand itemList<Item> equipmentList = new ArrayList<>();player.getAllSlots().forEach((x) -> equipmentList.add(x.getItem()));// 包含四个盔甲位置List<Item> armorList = equipmentList.subList(2, 6);//如果玩家穿上了所有的套装就会播放相应的动画// Make sure the player is wearing all the armor. If they are, continue playing// the animation, otherwise stop//ItemInit.HEISEN_BOOTS.get(), ItemInit.HEISEN_LEGGINGS.get(),ItemInit.HEISEN_CHEST.get(), ItemInit.HEISEN_HEAD.get()boolean isWearingAll = armorList.containsAll(Arrays.asList(ItemInit.HEISEN_BOOTS.get(), ItemInit.HEISEN_LEGG.get(),ItemInit.HEISEN_SUIT.get(), ItemInit.HEISEN_HEAD.get()));return isWearingAll ? PlayState.CONTINUE : PlayState.STOP;}return PlayState.STOP;}//将我们的待机动画进行注册@SuppressWarnings({ "unchecked", "rawtypes" })@Overridepublic void registerControllers(AnimationData data) {data.addAnimationController(new AnimationController(this, "controller", 20, this::predicate));}@Overridepublic AnimationFactory getFactory() {return this.factory;}private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP =(new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()).put(CustomArmorMaterial.ARMOR_MATERIAL_HEISENSUIT,new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 100, 1)).build();//穿上后给予效果@Overridepublic void onArmorTick(ItemStack stack, Level world, Player player) {if(!world.isClientSide()) {//穿上头盔就给予一个药水效果if(!player.getInventory().getArmor(3).isEmpty()) {MobEffectInstance mapStatusEffect1 = new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 100, 2);ArmorItem helmet = ((ArmorItem)player.getInventory().getArmor(3).getItem());if(helmet.getMaterial() == CustomArmorMaterial.ARMOR_MATERIAL_HEISENSUIT) {boolean hasPlayerEffect = player.hasEffect(mapStatusEffect1.getEffect());if(!hasPlayerEffect) {player.addEffect(new MobEffectInstance(mapStatusEffect1.getEffect(),mapStatusEffect1.getDuration(), mapStatusEffect1.getAmplifier()));}}}//穿上胸甲就给予一个药水效果if(!player.getInventory().getArmor(2).isEmpty()) {MobEffectInstance mapStatusEffect2 = new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 100, 1);ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmor(2).getItem());if(breastplate.getMaterial() == CustomArmorMaterial.ARMOR_MATERIAL_HEISENSUIT) {boolean hasPlayerEffect = player.hasEffect(mapStatusEffect2.getEffect());if(!hasPlayerEffect) {player.addEffect(new MobEffectInstance(mapStatusEffect2.getEffect(),mapStatusEffect2.getDuration(), mapStatusEffect2.getAmplifier()));}}}   //穿上护腿就给予一个药水效果if(!player.getInventory().getArmor(1).isEmpty()) {MobEffectInstance mapStatusEffect3 = new MobEffectInstance(MobEffects.SLOW_FALLING, 100, 1);ArmorItem leggings = ((ArmorItem)player.getInventory().getArmor(1).getItem());if(leggings.getMaterial() == CustomArmorMaterial.ARMOR_MATERIAL_HEISENSUIT) {boolean hasPlayerEffect = player.hasEffect(mapStatusEffect3.getEffect());if(!hasPlayerEffect) {player.addEffect(new MobEffectInstance(mapStatusEffect3.getEffect(),mapStatusEffect3.getDuration(), mapStatusEffect3.getAmplifier()));}}}//穿上靴子就给予一个药水效果if(!player.getInventory().getArmor(0).isEmpty()) {MobEffectInstance mapStatusEffect4 = new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 100, 0);ArmorItem boots = ((ArmorItem)player.getInventory().getArmor(0).getItem());if(boots.getMaterial() == CustomArmorMaterial.ARMOR_MATERIAL_HEISENSUIT) {boolean hasPlayerEffect = player.hasEffect(mapStatusEffect4.getEffect());if(!hasPlayerEffect) {player.addEffect(new MobEffectInstance(mapStatusEffect4.getEffect(),mapStatusEffect4.getDuration(), mapStatusEffect4.getAmplifier()));}}}}}}

之后我们需要在armor包中新建model包->model包中新建我们的盔甲的模型类ModelHeisensuit

ModelHeisensuit.java

package com.joy187.re8joymod.items.armor.model;import com.joy187.re8joymod.Main;
import com.joy187.re8joymod.items.armor.HeisensuitArmorItem;import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib3.model.AnimatedGeoModel;public class ModelHeisensuit extends AnimatedGeoModel<HeisensuitArmorItem> {//盔甲模型文件地址@Overridepublic ResourceLocation getModelLocation(HeisensuitArmorItem object) {return new ResourceLocation(Main.MOD_ID, "geo/heisensuit.geo.json");}//盔甲材质文件地址@Overridepublic ResourceLocation getTextureLocation(HeisensuitArmorItem object) {return new ResourceLocation(Main.MOD_ID, "textures/models/armor/heisensuit_layer_1.png");}//盔甲动画文件地址@Overridepublic ResourceLocation getAnimationFileLocation(HeisensuitArmorItem animatable) {return new ResourceLocation(Main.MOD_ID, "animations/heisensuit.animation.json");}
}

之后我们需要在armor包中新建render包->render包中新建我们的盔甲的渲染类ModelHeisensuit

RenderHeisensuit.java

package com.joy187.re8joymod.items.armor.render;import com.joy187.re8joymod.items.armor.HeisensuitArmorItem;
import com.joy187.re8joymod.items.armor.model.ModelHeisensuit;import software.bernie.geckolib3.renderers.geo.GeoArmorRenderer;public class RenderHeisensuit extends GeoArmorRenderer<HeisensuitArmorItem> {//渲染盔甲穿在身上的每一个部位的效果public RenderHeisensuit() {super(new ModelHeisensuit());//这里要和第二步你blockbench中建模的名称一一对应this.headBone = "Head";this.bodyBone = "chestplate";this.rightArmBone = "rightArm";this.leftArmBone = "leftArm";this.rightLegBone = "rightLeg";this.leftLegBone = "leftLeg";this.rightBootBone = "rightBoot";this.leftBootBone = "leftBoot";}
}

4.在ClientModEventSubscriber类中将我们的盔甲渲染类进行注册:

ClientModEventSubscriber.java

@Mod.EventBusSubscriber(modid = Main.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ClientModEventSubscriber extends ModEventSubscriber{@OnlyIn(Dist.CLIENT)@SubscribeEventpublic static void registerRenderers(final EntityRenderersEvent.AddLayers event) {//渲染类进行注册GeoArmorRenderer.registerArmorRenderer(HeisensuitArmorItem.class, new RenderHeisensuit());}
}

5.在ItemInit类中将我们的盔甲进行声明,盔甲属性请参考之前的教程1.18.2 盔甲套装:

ItemInit.java

    //头盔public static final RegistryObject<HeisensuitArmorItem> HEISEN_HEAD = ITEMS.register("heisenhead",() -> new HeisensuitArmorItem(CustomArmorMaterial.ARMOR_MATERIAL_HEISENSUIT, EquipmentSlot.HEAD, new Item.Properties()));//胸甲public static final RegistryObject<HeisensuitArmorItem> HEISEN_SUIT = ITEMS.register("heisensuit",() -> new HeisensuitArmorItem(CustomArmorMaterial.ARMOR_MATERIAL_HEISENSUIT, EquipmentSlot.CHEST, new Item.Properties()));//护腿public static final RegistryObject<HeisensuitArmorItem> HEISEN_LEGG = ITEMS.register("heisenlegg",() -> new HeisensuitArmorItem(CustomArmorMaterial.ARMOR_MATERIAL_HEISENSUIT, EquipmentSlot.LEGS, new Item.Properties()));//靴子public static final RegistryObject<HeisensuitArmorItem> HEISEN_BOOTS = ITEMS.register("heisenboots",() -> new HeisensuitArmorItem(CustomArmorMaterial.ARMOR_MATERIAL_HEISENSUIT, EquipmentSlot.FEET, new Item.Properties()));

6.代码部分结束,之后来到材质包制作环节:

resources\assets\你的modid中的lang包中的en_us.json添加盔甲的英文名称:

  "item.re8joymod.heisenhead":"H","item.re8joymod.heisensuit":"H","item.re8joymod.heisenlegg":"Hei","item.re8joymod.heisenboots":"Heis",

models\item包中添加所有盔甲的模型文件:

头盔

heisenhead.json

{"parent": "item/generated","textures": {"layer0": "re8joymod:item/heisenhead"}
}

胸甲

heisensuit.json

{"parent": "item/generated","textures": {"layer0": "re8joymod:item/heisensuit"}
}

护腿

heisenlegg.json

{"parent": "item/generated","textures": {"layer0": "re8joymod:item/heisenlegg"}
}

靴子

heisenboots.json

{"parent": "item/generated","textures": {"layer0": "re8joymod:item/heisenboots"}
}

textures\item中添加盔甲的手持贴图:

textures\models\armor中添加盔甲的穿戴后贴图:

assets\minecraft\textures\models\armor中同样添加我们的穿戴后贴图:

新建一个geo包和animation包,把第二步中的模型和动画文件分别放进去

8.保存所有文件 -> 进行测试:

穿上盔甲,如果可以正常显示,就说明我们成功了!

Minecraft 1.18.1、1.18.2模组开发 23.3D动画盔甲制作相关推荐

  1. Minecraft 1.19.2 Forge模组开发 10.3D动画盔甲

    Minecraft 1.16.5模组开发3D盔甲 Minecraft 1.12.2模组开发3D盔甲 Minecraft 1.18.2模组开发3D动画盔甲 我们本次在1.19.2的版本中实现具有动画效果 ...

  2. Minecraft 1.16.5模组开发(四十七) 动画生物实体

    1.18.2动画生物实体教程 今天我们尝试在1.16.5中添加一个能够做各种动作的生物实体,由于使用的是geckolib进行开发,所以代码方面和1.18.2没有太大差别. 1.首先,为了实现这些效果, ...

  3. Minecraft 1.18.1、1.18.2模组开发 02.方块和物品

    今天我们在1.18.1版本下制作属于自己的方块和物品 1.新建init文件夹 -> init包中新建BlockInit.java和ItemInit.java BlockInit.java pac ...

  4. Minecraft 1.18.1、1.18.2模组开发 05.发射器+投掷物

    1.12.2的霰弹枪教程:Minecraft 1.12.2模组开发(二十三) 霰弹枪! 1.16.5版本的投掷物教程:Minecraft 1.16.5模组开发(三十二) 自定义投掷物品实体 本期我们来 ...

  5. Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)

    Minecraft 1.18.1.1.18.2模组开发 05.发射器+投掷物 我们今天在模组中实现一把狙击枪. 1.与第5期教程类似,我们需要首先制作枪械的模型和子弹的模型: 不过我们本次希望狙击枪在 ...

  6. Minecraft 1.18.1、1.18.2模组开发 16.种植作物(crop)

    一年前的今天我们制作了1.12.2的作物教程:Minecraft 1.12.2模组开发(十五) 种植作物 我们本次在1.18.2中实现一个农作物. 1.在blocks包中新建一个我们的作物类Block ...

  7. Minecraft 1.18.1、1.18.2模组开发 01.eclipse 开发包构建教程

    1.18.2的离线开发包附文末 我们本次来进行Minecraft 1.18.1 模组开发教程的介绍,首先我们需要下载eclipse和openJDK eclipse下载 eclipse官网下载最新版 o ...

  8. Minecraft 1.16.5模组开发(三十八) 3D盔甲(新)

    Minecraft升级到1.16.5后,3D盔甲的制作方法也跟之前版本稍有不同(主要在第二步.第四步),建议先复习一下往期教程: Minecraft 1.12.2模组开发(三十七) 3D盔甲 1.在b ...

  9. Minecraft模组开发——环境搭建

    考虑到部分读者可能对环境搭建流程不熟,所以本章教程简单地过一遍环境搭建,并在项目中整合Mixin. 下载MDK 打开https://files.minecraftforge.net/net/minec ...

最新文章

  1. 《OpenCV3编程入门》学习笔记10 角点检测(一)Harris角点检测
  2. 如何为 Drupal 添加简单的 SEO META 标签(title keywords des...
  3. 背压加载文件– RxJava常见问题解答
  4. dcdc芯片效率不高的原因_半导体厂商如何做芯片的出厂测试?
  5. IE 浏览器各个版本 JavaScript 支持情况一览表
  6. jdbc工具类 配置版本 20210412_222527.mp4
  7. java mongodb开发_Java Tutorial:Java操作MongoDB入门
  8. 【LeetCode】【HOT】142. 环形链表 II(快慢指针)
  9. 不得不会的10点Java基础知识
  10. 使用R语言中的spgwr包进行GWR模型的相关运算
  11. 计算机二级栈,计算机二级国考office的高科技玩法之:堆栈的续集
  12. 计算机组成原理学习笔记——数据通路
  13. 每日作业-品优购详情页
  14. 中国余数定理解题步骤
  15. Ivanti的垃圾软件landesk
  16. OpenCV-Python根据鼠标点击位置截取ROI
  17. matlab rtdemo怎么生成,simulink——RTW自动代码生成简介
  18. 线性二次型调节器LQR/LQC算法解析及求解器代码(matlab)
  19. PowerDesigner导出ER图和表结构方法
  20. amos调节变量怎么画_amos怎么把变量颜色

热门文章

  1. 计算机桌面怎么锁,电脑怎么上锁,详细教您怎么给电脑屏幕上锁
  2. 计算机一级表格分类汇总怎么弄,多张word表格分类汇总 word表格分类汇总
  3. 如何在火车票退票免手续费
  4. EditText设置只允许输入文字、拼音、数字
  5. 基金投资入门教程-----基金入门
  6. 美团点评面试题目(2019)
  7. 怎样用360查看计算机使用记录,电脑360浏览器历史记录怎么查看
  8. Flappy Bird背后的故事
  9. 拆除联想一体机M7131z无线网卡
  10. 35岁以前要百万年薪