if you're putting the code before the ..() then you have to make sure the mob is able to lay eggs, i.e: not dead.