I'm adding a new enemy to the game. But when I spawn it, it doesn't attack the player, even though I added the corresponding target selector. I borrowoed most of it from the ZombieEntity class.
Here is the class:
public class AngrySubEntity extends MonsterEntity {
public AngrySubEntity(EntityType<? extends AngrySubEntity> type, World worldIn)
{
super(type, worldIn);
this.goalSelector.addGoal(8, new LookAtGoal(this, PlayerEntity.class, 8.0F));
this.goalSelector.addGoal(8, new LookRandomlyGoal(this));
this.goalSelector.addGoal(7, new WaterAvoidingRandomWalkingGoal(this, 1.0D));
this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, true));
}
public static AttributeModifierMap.MutableAttribute createAttributes()
{
return MonsterEntity.func_234295_eP_()
.createMutableAttribute(Attributes.FOLLOW_RANGE, 35.0D)
.createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.23F)
.createMutableAttribute(Attributes.ATTACK_DAMAGE, 3.0D)
.createMutableAttribute(Attributes.ARMOR, 2.0D);
}
protected int getExperiencePoints(PlayerEntity player)
{
return 0;
}
public boolean attackEntityFrom(DamageSource source, float amount)
{
if (!super.attackEntityFrom(source, amount))
{
return false;
}
else return this.world instanceof ServerWorld;
}
protected SoundEvent getHurtSound(DamageSource damageSourceIn)
{
return SoundEvents.ENTITY_ZOMBIE_HURT;
}
protected SoundEvent getStepSound()
{
return SoundEvents.ENTITY_ZOMBIE_STEP;
}
protected void playStepSound(BlockPos pos, BlockState blockIn)
{
this.playSound(this.getStepSound(), 0.15F, 1.0F);
}
}