In this tutorial we will show you how you can make your own custom mob and make it spawn in the game. This tutorial does not explain how to make mob models. We simply use the vanilla zombie model but with another texture:

The first thing you need is an actual entity. The entity we use here is an adaptation of the vanilla zombie entity. It has a special property (ARMS_RAISED) which is used while attacking:

publicclassEntityWeirdZombieextendsEntityMob{// We reuse the zombie model which has arms that need to be raised when the zombie is attacking:privatestaticfinalDataParameter<Boolean>ARMS_RAISED=EntityDataManager.createKey(EntityWeirdZombie.class,DataSerializers.BOOLEAN);publicstaticfinalResourceLocationLOOT=newResourceLocation(ModTut.MODID,"entities/weird_zombie");publicEntityWeirdZombie(WorldworldIn){super(worldIn);setSize(0.6F,1.95F);}@OverrideprotectedvoidentityInit(){super.entityInit();this.getDataManager().register(ARMS_RAISED,Boolean.valueOf(false));}@OverrideprotectedvoidapplyEntityAttributes(){super.applyEntityAttributes();// Here we set various attributes for our mob. Like maximum health, armor, speed, ...this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(35.0D);this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.13D);this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(3.0D);this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(2.0D);}publicvoidsetArmsRaised(booleanarmsRaised){this.getDataManager().set(ARMS_RAISED,Boolean.valueOf(armsRaised));}@SideOnly(Side.CLIENT)publicbooleanisArmsRaised(){returnthis.getDataManager().get(ARMS_RAISED).booleanValue();}@OverrideprotectedvoidinitEntityAI(){this.tasks.addTask(0,newEntityAISwimming(this));this.tasks.addTask(2,newEntityAIWeirdZombieAttack(this,1.0D,false));this.tasks.addTask(5,newEntityAIMoveTowardsRestriction(this,1.0D));this.tasks.addTask(7,newEntityAIWander(this,1.0D));this.tasks.addTask(8,newEntityAIWatchClosest(this,EntityPlayer.class,8.0F));this.tasks.addTask(8,newEntityAILookIdle(this));this.applyEntityAI();}privatevoidapplyEntityAI(){this.tasks.addTask(6,newEntityAIMoveThroughVillage(this,1.0D,false));this.targetTasks.addTask(1,newEntityAIHurtByTarget(this,true,newClass[]{EntityPigZombie.class}));this.targetTasks.addTask(2,newEntityAINearestAttackableTarget(this,EntityPlayer.class,true));this.targetTasks.addTask(3,newEntityAINearestAttackableTarget(this,EntityVillager.class,false));this.targetTasks.addTask(3,newEntityAINearestAttackableTarget(this,EntityIronGolem.class,true));}@OverridepublicbooleanattackEntityAsMob(EntityentityIn){if(super.attackEntityAsMob(entityIn)){if(entityIninstanceofEntityLivingBase){// This zombie gives health boost and regeneration when it attacks((EntityLivingBase)entityIn).addPotionEffect(newPotionEffect(MobEffects.HEALTH_BOOST,200));((EntityLivingBase)entityIn).addPotionEffect(newPotionEffect(MobEffects.REGENERATION,200));}returntrue;}else{returnfalse;}}@Override@NullableprotectedResourceLocationgetLootTable(){returnLOOT;}@OverrideprotectedbooleanisValidLightLevel(){returntrue;}@OverridepublicintgetMaxSpawnedInChunk(){return5;}}

We also need a custom Mele Attack AI task because we need to support the raising of arms while attacking. This is again a copy of vanilla code but adapted to our entity:

We also need a rendering object. In this class we reuse the ModelZombie from vanilla but we do supply our own texture:

publicclassRenderWeirdZombieextendsRenderLiving<EntityWeirdZombie>{privateResourceLocationmobTexture=newResourceLocation("modtut:textures/entity/weirdzombie.png");publicstaticfinalFactoryFACTORY=newFactory();publicRenderWeirdZombie(RenderManagerrendermanagerIn){// We use the vanilla zombie model here and we simply// retexture it. Of course you can make your own modelsuper(rendermanagerIn,newModelZombie(),0.5F);}@Override@NonnullprotectedResourceLocationgetEntityTexture(@NonnullEntityWeirdZombieentity){returnmobTexture;}publicstaticclassFactoryimplementsIRenderFactory<EntityWeirdZombie>{@OverridepublicRender<?superEntityWeirdZombie>createRenderFor(RenderManagermanager){returnnewRenderWeirdZombie(manager);}}}

Finally we need to register all this to the system. We make a new ModEntities class like this. Note that registerModEntity also makes us a spawn egg which is handy for testing our mob:

publicclassModEntities{publicstaticvoidinit(){// Every entity in our mod has an ID (local to this mod)intid=1;EntityRegistry.registerModEntity(EntityWeirdZombie.class,"WeirdZombie",id++,ModTut.instance,64,3,true,0x996600,0x00ff00);// We want our mob to spawn in Plains and ice plains biomes. If you don't add this then it will not spawn automatically// but you can of course still make it spawn manuallyEntityRegistry.addSpawn(EntityWeirdZombie.class,100,3,5,EnumCreatureType.MONSTER,Biomes.PLAINS,Biomes.ICE_PLAINS);// This is the loot table for our mobLootTableList.register(EntityWeirdZombie.LOOT);}@SideOnly(Side.CLIENT)publicstaticvoidinitModels(){RenderingRegistry.registerEntityRenderingHandler(EntityWeirdZombie.class,RenderWeirdZombie.FACTORY);}}

Then we change CommonProxy and ClientProxy to call the new init methods: